Skip to content

Entity API Keys

Entity API Keys

Manage entity-scoped API keys (ek_* prefix) for userless access to entities.

The Entity API Key object

object

Attributes

idstring

Stable, non-secret handle for this key (akh_* prefix). Use this to address the key in GET/DELETE calls. It is NOT the bearer credential and cannot be used to authenticate.

namestringnullable

Friendly name for the API key

environmentstring

Environment the key is valid for

Possible values: "live", "sandbox"

Other attributes

Create entity API key

POST/entities/api-keys

Create a new entity-scoped API key (ek_* prefix). This key can only access this specific entity.

Header parameters

entity_idstringoptional

Entity ID on which the request is made. Auto-selected when only one entity exists, required when multiple entities exist.

Body parameters

namestringoptional

Friendly name for the API key

Other parameters
import SpaceInvoices from '@spaceinvoices/js-sdk/sdk';

const sdk = new SpaceInvoices('YOUR_API_KEY');

const response = await sdk.entityApiKeys.create({
  name: "Production Integration Key",
  ttl: 86400,
  purpose: "integration"
}, {
  entity_id: "YOUR_ENTITY_ID"
});

console.log(response);

Returns

idstring

Stable, non-secret handle for this key (akh_* prefix). Use this to address the key in GET/DELETE calls. It is NOT the bearer credential and cannot be used to authenticate.

namestringnullable

Friendly name for the API key

Other parameters
json
{
  "id": "akh_abc123def456789012345678abcd1234abc123def456789012345678abcd1234",
  "key": "ek_sandbox_abc123def456789012345678abcd1234",
  "entity_id": "ent_abc123def456",
  "name": "Dashboard Access",
  "environment": "sandbox",
  "purpose": null,
  "prefix_hint": "ek_sandbox_abc...234",
  "created_at": "2024-01-01T00:00:00.000Z",
  "expires_at": null
}

Revoke all integration keys

POST/entities/api-keys/revoke-integration

Delete every API key of the current entity that was created for the white-label API integration (purpose: integration), expired ones included, in a single operation. Ordinary keys are never touched. Returns how many keys were deleted; repeating the call returns 0. Not gated on the plan or on the white-label capability, so the integration can always be turned off.

Header parameters

entity_idstringoptional

Entity ID on which the request is made. Auto-selected when only one entity exists, required when multiple entities exist.

import SpaceInvoices from '@spaceinvoices/js-sdk/sdk';

const sdk = new SpaceInvoices('YOUR_API_KEY');

const response = await sdk.entityApiKeys.revokeEntityApiKeyIntegration({
  entity_id: "YOUR_ENTITY_ID"
});

console.log(response);

Returns

json
{
  "revoked": 2
}

List entity API keys

GET/entities/api-keys

Retrieve all API keys for the current entity. Keys are masked for security.

Header parameters

entity_idstringoptional

Entity ID on which the request is made. Auto-selected when only one entity exists, required when multiple entities exist.

import SpaceInvoices from '@spaceinvoices/js-sdk/sdk';

const sdk = new SpaceInvoices('YOUR_API_KEY');

const response = await sdk.entityApiKeys.listEntityApiKeys({
  entity_id: "YOUR_ENTITY_ID"
});

console.log(response);

Returns

dataarray of objects
json
{
  "data": [
    {
      "id": "akh_abc123def456789012345678abcd1234abc123def456789012345678abcd1234",
      "entity_id": "ent_abc123def456",
      "name": "Dashboard Access",
      "environment": "sandbox",
      "purpose": null,
      "prefix_hint": "ek_sandbox_abc...234",
      "created_at": "2024-01-01T00:00:00.000Z",
      "expires_at": null
    }
  ]
}

Delete entity API key

DELETE/entities/api-keys/{id}

Permanently delete an entity API key. This action cannot be undone.

Header parameters

entity_idstringoptional

Optional entity ID specifying which entity context to use for this operation.

Path parameters

idstringrequired

Entity API key handle (the id from list/create, not the bearer secret)

import SpaceInvoices from '@spaceinvoices/js-sdk/sdk';

const sdk = new SpaceInvoices('YOUR_API_KEY');

await sdk.entityApiKeys.delete("akh_abc123def456789012345678abcd1234abc123def456789012345678abcd1234", {
  entity_id: "YOUR_ENTITY_ID"
});

console.log('Deleted successfully');

Returns

messagestring
json
{
  "message": "API key deleted"
}