Create an API Key API
On this page
This API is used to create a new API Key. An API key with key manager permission set to true can create keys. An API key that is tenant scoped can create another key for the same tenant.
A key with key manager permissions cannot be created using this API. Only through the Admin UI or kickstart can you create such a key.
Request#
Create from Scratch#
OpenAPI Spec
OpenAPI Spec
Path Parameters#
apiKeyIdThe unique Id of the API Key to create. If not specified a secure random UUID will be generated.
Request Body#
apiKey.expirationInstant The expiration instant of this API key. Using an expired API key for API Authentication will result in a 401 response code.
apiKey.key API key string. When you create an API key the key is defaulted to a secure random value but the API key is simply a string, so you may call it super-secret-key if you'd like. However a long and random value makes a good API key in that it is unique and difficult to guess.
apiKey.ipAccessControlListId The Id of the IP Access Control List limiting access to this API key.
Enterprise plan To use , you'll need an Enterprise plan.
apiKey.metaData.attributes.description Description of the key.
apiKey.name The name of the API key. Must be unique.
If apiKey.retrievable is false then this field is required.
apiKey.permissions.endpoints Endpoint permissions for this key. Each key of the object is an endpoint, with the value being an array of the HTTP methods which can be used against the endpoint. An Empty permissions object mean that this is a super key that authorizes this key for all the endpoints.
apiKey.retrievable Indicates whether this key is retrievable. If this value is false, the key will not be returned in the API response.
This value is read-only once the key is created. If this value is set to false then the apiKey.name field is required.
apiKey.tenantId The unique Id of the Tenant. This value is required if the key is meant to be tenant scoped. Tenant scoped keys can only be used to access users and other tenant scoped objects for the specified tenant. This value is read-only once the key is created.
Tenant-scoped keys have read-only access to entities that are shared between tenants. You can further limit these API keys by specifying required endpoints, permissions, and a tenant.
Use care when scoping an API key to the Default tenant. These API keys can make changes to User Registrations for the FusionAuth Admin application via the User Registration API to broaden the effective scope of a key to other tenants.
{
"apiKey": {
"expirationInstant": 872812800000,
"key": "super-secret-key",
"ipAccessControlListId": "eae37b0e-950b-4e92-abcc-d0b310326f66",
"metaData": {
"attributes": {
"description": "my super secret key"
}
},
"name": "Awesome API Key",
"permissions": {
"endpoints": {
"/api/application": [
"DELETE",
"POST",
"GET",
"PUT",
"PATCH"
]
}
},
"retrievable": false,
"tenantId": "94f751c5-4883-4684-a817-6b106778edec"
}
}Copy Another API Key#
OpenAPI Spec
OpenAPI Spec
Path Parameters#
apiKeyIdThe unique Id of the API Key to create. If not specified a secure random UUID will be generated.
Request Body#
sourceKeyIdThe Id of an existing API Key from which a copy will be made. The resulting key will have the same permissions of this existing key.
Note that you cannot copy a key designated as a key manager.
apiKey.name The name of the API key. Must be unique.
If the retrievable value of the source key is false then this field is required.
{
"sourceKeyId": "de36ce0f-70db-4d73-b0b2-9f82c1572761",
"apiKey": {
"name": "Awesome API Key - copy"
}
}Response#
The response for this API contains the Key that was created.
Response Codes| Code | Description |
|---|---|
| 200 | The request was successful. The response will contain a JSON body. |
| 400 | The request was invalid and/or malformed. The response will contain an Errors JSON Object with the specific errors. This status will also be returned if a paid FusionAuth license is required and is not present. |
| 401 | You did not supply a valid Authorization header. The header was omitted or your API key was not valid. The response will be empty. See Authentication. |
| 500 | There was an internal error. A stack trace is provided and logged in the FusionAuth log files. The response will be empty. |
Response Body#
apiKey.expirationInstant The expiration instant of this API key. Using an expired API key for API Authentication will result in a 401 response code.
apiKey.id The Id of the API key.
apiKey.id The Id of the API key.
apiKey.insertInstant The instant when the API key was added to the FusionAuth database.
apiKey.ipAccessControlListId The Id of the IP Access Control List limiting access to this API key.
apiKey.key The API key value, this is the string value you will use in the Authorization header to authenticate API requests.
If the apiKey.retrievable value is false then this will be the only time the key is returned in the response.
apiKey.key The API key value. This is the string value you will use in the Authorization header to authenticate API requests.
If the apiKey.retrievable value is false then this field will not be returned in the response.
apiKey.keyManager Indicates whether this key is a key manager. Setting this flag to true allows this key to be used to call these APIs. An attempt to call these APIs with a non-manager key (keyManager set to false) will always return a HTTP response status code 401.
apiKey.lastUpdateInstant The instant when the API key was last updated in the FusionAuth database.
apiKey.metaData.attributes.description Description of the key.
apiKey.name The name of the API key.
apiKey.permissions.endpoints Endpoint permissions for this key. Each key of the object is an endpoint, with the value being an array of the HTTP methods which can be used against the endpoint. An empty permissions object mean that this is a super key that authorizes this key for all the endpoints.
apiKey.retrievable Indicates whether this key is retrievable.
If this value is false, the apiKey.key will not be returned in the API response.
apiKey.tenantId The unique Id of the Tenant. This value is read-only once the key is created.
{
"apiKey": {
"expirationInstant": 872812800000,
"id": "de36ce0f-70db-4d73-b0b2-9f82c1572761",
"insertInstant": 1619726194060,
"ipAccessControlListId": "eae37b0e-950b-4e92-abcc-d0b310326f66",
"key": "super-secret-key",
"keyManager": false,
"lastUpdateInstant": 1619726194060,
"metaData": {
"attributes": {
"description": "my super secret key"
}
},
"name": "Awesome API Key",
"permissions": {
"endpoints": {
"/api/application": [
"DELETE",
"POST",
"GET",
"PUT",
"PATCH"
]
}
},
"retrievable": false,
"tenantId": "94f751c5-4883-4684-a817-6b106778edec"
}
}Related
Learn about the APIs for creating, retrieving, updating and deleting API Keys.
API documentation for the FusionAuth Update an API Key API.
API documentation for the FusionAuth Delete an API Key API.
API documentation for the FusionAuth Retrieve an API Key API.