Skip to main content
API keys provide a secure way to authenticate server-to-server requests without requiring a user session. This guide explains how to use API keys with the SnackBase JavaScript SDK.

What are API Keys?

API keys are long-lived credentials that allow your server to authenticate with SnackBase without requiring a user login flow. They’re ideal for:
  • Backend services and cron jobs
  • Webhook endpoints
  • Server-side data processing
  • Automated scripts
API keys should only be used on the server side. Never expose API keys in client-side code or public repositories.

Setting Up API Keys

Generate an API Key

  1. Log in to your SnackBase admin panel
  2. Navigate to API Keys
  3. Click + New API Key
  4. Enter a description (e.g., “Production API”)
  5. Copy the generated key
API keys are only shown once at creation. Store them securely in your environment variables.

Using API Keys

Basic Usage

Environment Variables

Store your API key in environment variables:

Different Keys for Different Environments

Use different API keys for different environments:

API Key vs User Authentication

Server-Side Operations

Express.js Example

Next.js Example

Background Jobs

Webhook Handling

Admin Operations

API keys have full access to account operations:

Error Handling

Security Best Practices

1. Environment Variables

Never hardcode API keys:

2. Use Different Keys for Different Services

Create separate API keys for different services:

3. Rotate API Keys Regularly

Periodically rotate your API keys:
  1. Create a new API key
  2. Update your environment variables
  3. Deploy the changes
  4. Delete the old API key

4. Use Key Prefixes

API keys include prefixes to identify their type:
  • sbak_live_ - Production keys
  • sbak_test_ - Test/development keys
Verify the key type in production:

5. Monitor Usage

Monitor your API key usage in the SnackBase admin panel to detect unauthorized access.

Rate Limits

API keys have higher rate limits than user authentication:
Actual rate limits depend on your SnackBase plan. Contact support for custom limits.

Testing

Use test API keys during development:

Next Steps