# createApiKey

```graphql
mutation CreateApiKey($input: CreateApiKeyInput!) {
  createApiKey(input: $input) {
    id
    projectId
    userId
    accountId
    name
    key
    keyPrefix
    expiresAt
    createdAt
    scopes
    scope
  }
}
```

Create an API key and return its secret once.

## Arguments

| Name                     | Type               | Required | Description                                                                                                                                                                                              |
| ------------------------ | ------------------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `input`                  | CreateApiKeyInput! | Yes      |                                                                                                                                                                                                          |
| `input.projectReference` | String             |          | Project ID or slug. Creating a project-scoped key requires project.api\_keys.manage. Omit for a user-level key; a project-scoped API-key caller retains its enforced project when this field is omitted. |
| `input.name`             | String!            | Yes      |                                                                                                                                                                                                          |
| `input.scopes`           | \[String!]         |          |                                                                                                                                                                                                          |
| `input.expiresAt`        | String             |          |                                                                                                                                                                                                          |

## Variables

```json
{
  "input": {
    "name": "string"
  }
}
```

## Responses

| Status | Description                                    |
| ------ | ---------------------------------------------- |
| 200    | The CreateApiKeyPayload! in data.createApiKey. |

## Call it

```bash
curl -X POST "https://api.veryfront.com/graphql" \
  -H "Authorization: Bearer $VERYFRONT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "query": "mutation CreateApiKey($input: CreateApiKeyInput!) {\n  createApiKey(input: $input) {\n    id\n    projectId\n    userId\n    accountId\n    name\n    key\n    keyPrefix\n    expiresAt\n    createdAt\n    scopes\n    scope\n  }\n}",
  "variables": {
    "input": {
      "name": "string"
    }
  }
}'
```

## Example response

```json
{
  "data": {
    "createApiKey": {
      "id": "string",
      "projectId": "string",
      "userId": "string",
      "accountId": "string",
      "name": "string",
      "key": "string",
      "keyPrefix": "string",
      "expiresAt": "string",
      "createdAt": "string",
      "scopes": [
        "string"
      ],
      "scope": "string"
    }
  }
}
```
