Create API Key
POST
/users/{username}/api-keys
Generate a new API key for a user. The raw key is returned only once in the response.
Parameters
| Name | Type | Description |
|---|---|---|
| username required | string | The username to create the API key for |
| name optional | string | A descriptive name for the API key |
| scopes optional | array | List of permission scopes for the key |
| expiry_days optional | integer | Number of days until the key expires. Omit or set to null for no expiry. |
JSON
{"name": "CI Deploy Key", "scopes": [], "expiry_days": 90}
JSON
{"data": {"id": "abc123", "name": "CI Deploy Key", "api_key": "grav_...", "scopes": [], "created": 1710000000}}
Response Codes
201
API key created
401
Unauthorized
403
Forbidden
404
User not found