Api Reference
API keys allow you to authenticate API requests programmatically without using session cookies. API keys are tenant-scoped and support granular permissions via scopes.
/admin/api)Security: API keys are displayed only once at creation. If lost, you must create a new key. Store keys securely and never commit them to version control.
1curl -X POST "https://app.betterdata.co/api/admin/api-keys" \2 -H "Authorization: Bearer YOUR_SESSION_TOKEN" \3 -H "Content-Type: application/json" \4 -d '{5 "name": "Production API Key",6 "scopes": ["inventory:read", "forecast:read"]7 }'Response:
1{2 "apiKey": {3 "id": "key_123",4 "name": "Production API Key",5 "keyPrefix": "bdk_live_ABC123",6 "last4": "XYZ1",7 "scopes": ["inventory:read", "forecast:read"],8 "status": "ACTIVE",9 "createdAt": "2024-01-01T00:00:00Z"10 },11 "plaintextKey": "bdk_live_ABC123_<random>"12}Include the API key in the Authorization header as a Bearer token:
1curl -X GET "https://app.betterdata.co/api/inventory/channel-location?locationId=loc_123&page=1&limit=50" \2 -H "Authorization: Bearer bdk_live_ABC123_<your-key>" \3 -H "Content-Type: application/json"API keys support granular permissions via scopes:
inventory:read - Read inventory datainventory:write - Create/update inventoryforecast:read - Read forecastsforecast:write - Create/update forecastsplanning:read - Read planning dataplanning:write - Create/update plansprocurement:read - Read procurement dataprocurement:write - Create/update purchase ordersshipping:read - Read shipping datashipping:write - Create/update shipmentsreports:read - Read reportsadmin:read - Read admin dataadmin:write - Admin operations (tenant admin only)inventory:* - All inventory operations* - All operations (use with caution)1curl -X GET "https://app.betterdata.co/api/admin/api-keys" \2 -H "Authorization: Bearer YOUR_SESSION_TOKEN"1curl -X PATCH "https://app.betterdata.co/api/admin/api-keys/key_123" \2 -H "Authorization: Bearer YOUR_SESSION_TOKEN" \3 -H "Content-Type: application/json" \4 -d '{5 "name": "Updated Name",6 "scopes": ["inventory:read", "inventory:write"]7 }'1curl -X POST "https://app.betterdata.co/api/admin/api-keys/key_123/revoke" \2 -H "Authorization: Bearer YOUR_SESSION_TOKEN"Create a new key and optionally revoke the old one:
1curl -X POST "https://app.betterdata.co/api/admin/api-keys/key_123/rotate" \2 -H "Authorization: Bearer YOUR_SESSION_TOKEN" \3 -H "Content-Type: application/json" \4 -d '{5 "revokeOld": true6 }'| Code | Status | Description |
|------|--------|-------------|
| MISSING_AUTHORIZATION | 401 | Authorization header missing |
| INVALID_API_KEY | 401 | API key not found or invalid |
| REVOKED_API_KEY | 401 | API key has been revoked |
| EXPIRED_API_KEY | 401 | API key has expired |
| INACTIVE_ORGANIZATION | 403 | Organization is not active |
| IP_RESTRICTED | 403 | API key not authorized for this IP |
| INSUFFICIENT_SCOPE | 403 | Key lacks required scope |
1curl -X GET "https://app.betterdata.co/api/inventory/channel-location?locationId=loc_123&page=1&limit=50" \2 -H "Authorization: Bearer bdk_live_ABC123_<your-key>" \3 -H "Content-Type: application/json"This requires the inventory:read scope.
