# API key

## Get all API keys

> \## API key Resource Fields\
> \
> \| Field |\
> \| :--- |\
> \| \`id\` |\
> \| \`created\_at\` |\
> \| \`is\_of\_\_actor\` |\
> \| \`name\` |\
> \| \`description\` |\
> \
> \
> \---\
> \
> \`GET /v7/api\_key\`\
> \
> \
> \### Usage Variations\
> \
> \--- \
> \#### Get all API keys of a device by UUID\
> \`GET /v7/api\_key?$filter=is\_of\_\_actor/any(a:a/is\_of\_\_device/any(d:d/uuid eq '\<DEVICE\_UUID>'))\`\
> \
> \--- \
> \#### Get all API keys of an application by slug\
> \`GET /v7/api\_key?$filter=is\_of\_\_actor/any(a:a/is\_of\_\_application/any(ioa:ioa/slug eq '\<SLUG>'))\`\
> \
> \--- \
> \#### Get all user API keys for the authenticated user\
> \`GET /v7/api\_key?$filter=is\_of\_\_actor/any(a:a/is\_of\_\_user eq \<USER\_ID>))\`

```json
{"openapi":"3.0.0","info":{"title":"Balena API Spec","version":"7.0.0"},"servers":[{"url":"https://api.balena-cloud.com"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer"}}},"paths":{"/v7/api_key":{"get":{"tags":["API key"],"summary":"Get all API keys","description":"## API key Resource Fields\n\n| Field |\n| :--- |\n| `id` |\n| `created_at` |\n| `is_of__actor` |\n| `name` |\n| `description` |\n\n\n---\n\n`GET /v7/api_key`\n\n\n### Usage Variations\n\n--- \n#### Get all API keys of a device by UUID\n`GET /v7/api_key?$filter=is_of__actor/any(a:a/is_of__device/any(d:d/uuid eq '<DEVICE_UUID>'))`\n\n--- \n#### Get all API keys of an application by slug\n`GET /v7/api_key?$filter=is_of__actor/any(a:a/is_of__application/any(ioa:ioa/slug eq '<SLUG>'))`\n\n--- \n#### Get all user API keys for the authenticated user\n`GET /v7/api_key?$filter=is_of__actor/any(a:a/is_of__user eq <USER_ID>))`"}}}}
```

## Update the expiry date for an API Key

> \`PATCH /v7/api\_key(\<ID>)\`\
> \
> \*\*Request Body:\*\*\
> \`\`\`json\
> {\
> &#x20;   "expiry\_date": \<ISO\_8601\_DATE\_TIME>\
> }\
> \`\`\`\
> \
> Note: Select a date in the past to expire an API Key immediately.\
> \
> \
> \### Usage Variations\
> \
> \--- \
> \#### Clear the expiry date of an API Key\
> \`PATCH /v7/api\_key(\<ID>)\`\
> \
> \*\*Request Body:\*\*\
> \`\`\`json\
> {\
> &#x20;   "expiry\_date": null\
> }\
> \`\`\`

````json
{"openapi":"3.0.0","info":{"title":"Balena API Spec","version":"7.0.0"},"servers":[{"url":"https://api.balena-cloud.com"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer"}}},"paths":{"/v7/api_key({ID})":{"patch":{"tags":["API key"],"summary":"Update the expiry date for an API Key","description":"`PATCH /v7/api_key(<ID>)`\n\n**Request Body:**\n```json\n{\n    \"expiry_date\": <ISO_8601_DATE_TIME>\n}\n```\n\nNote: Select a date in the past to expire an API Key immediately.\n\n\n### Usage Variations\n\n--- \n#### Clear the expiry date of an API Key\n`PATCH /v7/api_key(<ID>)`\n\n**Request Body:**\n```json\n{\n    \"expiry_date\": null\n}\n```","parameters":[{"name":"ID","in":"path","required":true}],"requestBody":{"content":{"application/json":{"schema":{"type":"object"}}}}}}}}
````

## Create new API key

> \`POST /api-key/user/full\`\
> \
> \*\*Request Body:\*\*\
> \`\`\`json\
> {\
> &#x20;   "name": \<NAME>,\
> &#x20;   "description": \<DESCRIPTION>\
> }\
> \`\`\`

````json
{"openapi":"3.0.0","info":{"title":"Balena API Spec","version":"7.0.0"},"servers":[{"url":"https://api.balena-cloud.com"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer"}}},"paths":{"/api-key/user/full":{"post":{"tags":["API key"],"summary":"Create new API key","description":"`POST /api-key/user/full`\n\n**Request Body:**\n```json\n{\n    \"name\": <NAME>,\n    \"description\": <DESCRIPTION>\n}\n```","requestBody":{"content":{"application/json":{"schema":{"type":"object"}}}}}}}}
````
