Skip to main content

Create Key

Generates a new API key for the specified user with the given visibility level.

:::tip Store the Key Immediately The full key string is only returned once at creation time. Store it securely (such as in a secrets manager or environment variable) before discarding the response — it cannot be retrieved in full afterward. :::

Endpoint

POST /v2/keys/create

Request Body

FieldTypeRequiredConstraintsDescription
userIdintYesMust be a valid user IDThe ID of the user for whom the key is being created
visibilitystringYesMust be a valid KeyVisibility valueDetermines the scope in which this key can be used
{
"userId": 12345,
"visibility": "Private"
}

Response

Returns the full key record, including the newly generated key string.

{
"success": true,
"data": {
"keyId": 9003,
"userId": 12345,
"key": "ek_live_newkey987zyxwvu...",
"visibility": "Private",
"created": "2026-05-07T08:45:00Z"
}
}

Response Fields

FieldTypeDescription
keyIdintUnique identifier for the new key record
userIdintThe user this key belongs to
keystringThe newly generated API key string — save this now
visibilitystringScope of the key — see KeyVisibility enum
createddatetimeUTC timestamp when the key was created

ENUMs

KeyVisibility

See KeyVisibility in the Appendix for the full list of values.

ValueDescription
PrivateKey is accessible only to the owning user
SharedKey is shared within the mailbox or network
PublicKey is publicly accessible
SessionKey is tied to a single session

Code Examples

curl -X POST "https://rest.ecgrid.io/v2/keys/create" \
-H "X-API-Key: $ECGRID_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "userId": 12345, "visibility": "Private" }'

See Also