Skip to content

Authentication

All API requests must be authenticated using an API key. You can obtain your API key from the Caramel Dashboard.

Caramel supports two authentication methods:

Bearer Token

Recommended - Pass your API key in the Authorization header

Authorization: Bearer YOUR_API_KEY

API Key Header

Alternative method using a custom header

X-Caramel-API-Key: YOUR_API_KEY
  1. Get your API key

    Log in to your Caramel Dashboard and navigate to Settings → API Keys

  2. Choose your environment

    • Production: pk_live_... for real transactions
    • Test: pk_test_... for development and testing
  3. Make your first request

    Terminal window
    curl https://api.joincaramel.com/v1/gift-cards \
    -H "Authorization: Bearer pk_live_YOUR_API_KEY" \
    -H "Content-Type: application/json"
Key TypePrefixUsageCapabilities
Productionpk_live_Live transactionsFull access to all API endpoints
Testpk_test_Development & testingFull access, no real charges
Restrictedrk_live_Limited scopeCustom permissions per key
Publishablepub_live_Client-sideRead-only operations

Our official SDKs handle authentication automatically:

import { Caramel } from '@caramel/node';
const caramel = new Caramel({
apiKey: process.env.CARAMEL_API_KEY,
// Optional: defaults to production
environment: 'production'
});
// SDK handles authentication headers automatically
const giftCards = await caramel.giftCards.list();

OAuth 2.0 Coming Soon

Section titled “OAuth 2.0 ”

For partners and marketplace integrations, we support OAuth 2.0 authentication flow.

sequenceDiagram
participant User
participant YourApp
participant Caramel
User->>YourApp: Initiate connection
YourApp->>Caramel: Redirect to /oauth/authorize
Caramel->>User: Show consent screen
User->>Caramel: Approve access
Caramel->>YourApp: Redirect with auth code
YourApp->>Caramel: Exchange code for token
Caramel->>YourApp: Return access token
YourApp->>Caramel: Make API requests

Define the level of access your application needs:

  • read:gift_cards - View gift cards
  • write:gift_cards - Create and manage gift cards
  • read:customers - View customer data
  • write:customers - Manage customers
  • read:analytics - Access analytics data
  • admin - Full account access

Rotate Keys Regularly

Rotate your API keys every 90 days to maintain security

Use Environment Variables

Never hardcode API keys. Store them in environment variables

Implement Rate Limiting

Respect rate limits to avoid service interruption

Monitor Usage

Regularly review API usage logs for suspicious activity

API requests are rate limited to ensure fair usage:

PlanRequests per SecondRequests per Day
Free10 req/s10,000 req/day
Starter50 req/s100,000 req/day
Professional100 req/s1,000,000 req/day
EnterpriseCustomUnlimited

Rate limit information is included in response headers:

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1640995200

Authentication errors return appropriate HTTP status codes:

Status CodeError TypeDescription
401UnauthorizedMissing or invalid API key
403ForbiddenValid key but insufficient permissions
429Too Many RequestsRate limit exceeded

Example error response:

{
"error": {
"type": "authentication_error",
"message": "Invalid API key provided",
"code": "invalid_api_key",
"doc_url": "https://docs.joincaramel.com/errors/invalid_api_key"
}
}

Use our test endpoint to verify your authentication:

Terminal window
curl https://api.joincaramel.com/v1/auth/verify \
-H "Authorization: Bearer YOUR_API_KEY"

Success response:

{
"authenticated": true,
"key_type": "live",
"permissions": ["read", "write"],
"restaurant": {
"id": "rest_1234",
"name": "Your Restaurant"
}
}

For webhook endpoints, verify the signature to ensure requests come from Caramel:

const crypto = require('crypto');
function verifyWebhookSignature(payload, signature, secret) {
const expectedSignature = crypto
.createHmac('sha256', secret)
.update(payload)
.digest('hex');
return crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(expectedSignature)
);
}

Now that you’re authenticated, you can: