Server-SideREST API
Authentication
How to authenticate with the Audiencelab REST API
All Audiencelab REST API requests require authentication using your API key.
API Key
Your API key is provided when you create an application in the Audiencelab dashboard. Each application has its own unique API key.
Keep your API key secure. Never expose it in client-side code or public repositories. The REST API is designed for server-to-server communication only.
Authentication Header
Include your API key in the geeklab-api-key header of every request:
geeklab-api-key: your_api_key_hereFull Request Example
curl -X POST https://analytics.geeklab.app/fetch-token \
-H "Content-Type: application/json" \
-H "geeklab-api-key: your_api_key_here" \
-d '{
"type": "device-metrics",
"created_at": "2024-10-10T10:15:00.000Z",
"data": {
"device_name": "MacBook Pro",
"device_model": "MacBookPro18,3",
"os_system": "macOS 14.5",
"timezone": "America/Los_Angeles"
}
}'Request Headers
Every API request must include these headers:
Prop
Type
Authentication Errors
401 Unauthorized
Returned when the API key is missing or invalid:
{
"success": false,
"error": "Invalid or missing API key"
}403 Forbidden
Returned when the API key doesn't have access to the requested resource:
{
"success": false,
"error": "Access denied for this resource"
}Obtaining Your API Key
- Log in to the Audiencelab Dashboard
- Navigate to Settings → Applications
- Select your application or create a new one
- Copy the API Key from the application details
Best Practices
- Store securely: Use environment variables or a secrets manager
- Never commit: Add your API key to
.gitignoreand never commit it to version control - Server-side only: Only use the API key from your backend servers
- Rotate if compromised: If you suspect your key has been exposed, regenerate it from the dashboard
Next Steps
Now that you understand authentication, learn about the available endpoints:
- Fetch Token - Get a token from device metrics
- Verify Token - Validate a token
- Check Data Collection Status - Confirm collection is enabled
- Webhook Events - Send retention and custom events