Authentication

How to authenticate your API requests

Overview

The SnapTrack API uses API tokens for authentication. All API requests must include a valid API token in the Authorization header.

Note: You must have an active subscription (Starter, Pro, or Business plan) to access the API. Free plan does not include API access.

Getting Your API Token

Step 1: Login to Dashboard

Visit https://snaptrack.dev/login and login with your credentials.

Step 2: Navigate to Settings

Go to Settings → API Keys from the admin dashboard.

Step 3: Generate Token

  1. Click "Generate API Token" button
  2. Copy the generated token immediately
  3. Store it securely (you won't be able to see it again)
Note: API tokens are SHA-256 hashed and stored securely. You can only view them when first generated.

Using Your API Token

Include your API token in the Authorization header of every API request:

Authorization: Bearer YOUR_API_TOKEN

Example Request

curl -X GET https://api.snaptrack.dev/websites \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -H "Content-Type: application/json"

Token Management

Regenerate Token

If your token is compromised or you need a new one:

  1. Go to Settings → API Keys
  2. Click "Revoke Token"
  3. Confirm revocation
  4. Click "Generate API Token" to create a new one
Warning: Revoking your token will immediately invalidate all API requests using the old token. Update your applications with the new token.

Testing Your Token

Test your API token with the test endpoint:

curl -X GET https://api.snaptrack.dev/test \ -H "Authorization: Bearer YOUR_API_TOKEN" Response: 200 OK { "success": true, "message": "API is working", "user": { "id": 1, "name": "John Doe", "email": "[email protected]", "subscription_tier": "pro" }, "rate_limit": { "limit": 20, "remaining": 19, "reset": 1706371200 } }

Token Security

Common Authentication Errors

401 Unauthorized

{ "success": false, "error": "Unauthorized" }

Causes:

Solution: Generate a new token and ensure the header format is correct.

403 API Access Denied

{ "success": false, "error": "API access is not available on your plan", "current_plan": "free" }

Causes:

Solution: Upgrade to Starter plan or higher.

Best Practices

Environment Variables

Store your token in a .env file:

SNAPTRACK_API_TOKEN=your_token_here SNAPTRACK_API_URL=https://api.snaptrack.dev

Access in your code:

// JavaScript (Node.js) const token = process.env.SNAPTRACK_API_TOKEN; const apiUrl = process.env.SNAPTRACK_API_URL; // Python import os token = os.getenv('SNAPTRACK_API_TOKEN') api_url = os.getenv('SNAPTRACK_API_URL') // PHP $token = getenv('SNAPTRACK_API_TOKEN'); $apiUrl = getenv('SNAPTRACK_API_URL');

Next: API Endpoints →