Skip to main content

Where API Keys Are Stored

API keys are stored in the PostgreSQL database in the users table with the following columns:
  • api_key - The actual API key (64 character hex string)
  • api_key_created_at - When the key was generated
  • api_key_last_used_at - When the key was last used for authentication

Methods to Find API Keys

If you already have an API key, retrieve it:
curl -X GET https://api.checkpoint.b-digital.uk/api/v1/api-keys/my-key \
  -H "X-API-Key: YOUR_EXISTING_API_KEY"
Response:
{
  "success": true,
  "data": {
    "user_id": "auth0|123456",
    "email": "[email protected]",
    "api_key": "5f36aee30fcd8e60a71ac2e8ff2a6243a36a3935845beae713cdd64e2eb3b032",
    "created_at": "2025-11-03T22:50:33.234Z",
    "last_used_at": "2025-11-03T23:15:12.456Z"
  }
}

Method 2: Query Database Directly

Connect to your PostgreSQL database and query:
-- Get all users with API keys
SELECT 
  id,
  email,
  api_key,
  api_key_created_at,
  api_key_last_used_at
FROM users
WHERE api_key IS NOT NULL
  AND deleted_at IS NULL
ORDER BY api_key_created_at DESC;

-- Get API key for specific user
SELECT 
  email,
  api_key,
  api_key_created_at
FROM users
WHERE email = '[email protected]'
  AND api_key IS NOT NULL;

Method 3: Via Railway Dashboard

  1. Go to your Railway PostgreSQL service
  2. Click on “Query” tab
  3. Run the SQL query above
  4. Copy the API keys from the results

Method 4: Check Bulk Generation Output

If you used the bulk generation script, check the output file:
# Look for files like:
api-keys-2025-11-03.json
These files contain all generated API keys in JSON format.

Method 5: Generate New API Key

If a user doesn’t have an API key, generate one:
# Via API
curl -X POST https://api.checkpoint.b-digital.uk/api/v1/api-keys/generate \
  -H "Content-Type: application/json" \
  -d '{"email": "[email protected]"}'

# Via script
cd functions/api-standalone
npm run generate-api-key -- [email protected]

Security Notes

⚠️ Important:
  • API keys are shown only once when generated
  • Store them securely immediately
  • Never commit API keys to version control
  • Use secure channels (password managers, encrypted email) to share keys
  • Delete bulk generation JSON files after distributing keys

Finding Keys for Multiple Users

Get All API Keys for a Tenant

SELECT 
  u.email,
  u.api_key,
  u.api_key_created_at,
  u.api_key_last_used_at,
  t.name as tenant_name
FROM users u
JOIN tenants t ON u.tenant_id = t.id
WHERE u.api_key IS NOT NULL
  AND u.deleted_at IS NULL
  AND t.name = 'KettleOrganisation'
ORDER BY u.email;

Export to CSV

-- Export to CSV format
COPY (
  SELECT 
    email,
    api_key,
    api_key_created_at::text,
    api_key_last_used_at::text
  FROM users
  WHERE api_key IS NOT NULL
    AND deleted_at IS NULL
) TO '/tmp/api-keys.csv' WITH CSV HEADER;

Troubleshooting

User has no API key

If the query returns no results or NULL:
  • Generate a new API key using Method 5 above
  • The key will be shown once in the response

Can’t access database

If you can’t access the database directly:
  • Use the API endpoint (Method 1) if you have an existing key
  • Contact your database administrator
  • Use Railway dashboard SQL editor

Forgot your API key

If you’ve lost your API key:
  1. Regenerate it (old key will stop working):
    curl -X POST https://api.checkpoint.b-digital.uk/api/v1/api-keys/regenerate \
      -H "X-API-Key: YOUR_OLD_KEY" \
      -H "Content-Type: application/json"
    
  2. Or query the database if you have access
  3. Or generate via script if you have database access