Skip to main content

API Key Authentication

🔐 API Key Authentication

ActiveCampaign uses API key authentication with account-specific base URLs. Each account has a unique API URL and API key that must be obtained from the ActiveCampaign dashboard.

🌐 Environment Variables

VariableDescriptionExample
ACTIVECAMPAIGN_API_VERSIONAPI version path/api/3

📋 API Endpoints

MethodEndpointDescriptionAuth Required
POST/v1/integrations/activecampaign/authSave API credentials✅ JWT
DELETE/v1/integrations/activecampaign/authDelete stored credentials✅ JWT

🔄 Authentication Flow

Step 1: Obtain API Credentials

From ActiveCampaign dashboard:

  1. Login to your ActiveCampaign account
  2. Navigate to Settings → Developer
  3. Copy API URL - Example: https://dashclicks83379.api-us1.com
  4. Copy API Key - Example: a0b219e049fb4f027fd927ade6a21d38abc123def456789

Step 2: Save Credentials

Endpoint: POST /auth

Request Body:

  • api_key (required) - ActiveCampaign API key
  • base_url (required) - Account-specific API base URL

Request:

POST /v1/integrations/activecampaign/auth
Authorization: Bearer {jwt_token}
Content-Type: application/json

{
"api_key": "a0b219e049fb4f027fd927ade6a21d38abc123def456789",
"base_url": "https://dashclicks83379.api-us1.com"
}

Process:

  1. Check for existing credentials (one per user/account)
  2. Validate base_url is provided
  3. Validate api_key is provided
  4. Test API key by making request to /api/3/contacts
  5. If valid, save credentials to MongoDB
  6. If invalid, return error

Success Response:

{
"success": true,
"message": "SUCCESS"
}

Error Responses:

// Credentials already exist
{
"success": false,
"errno": 400,
"message": "Record already exist!"
}

// Missing base URL
{
"success": false,
"errno": 400,
"message": "Base URL is required!"
}

// Missing API key
{
"success": false,
"errno": 400,
"message": "API Key is required!"
}

// Invalid credentials
{
"success": false,
"errno": 400,
"message": "Invalid base_url or api_key."
}

Step 3: Delete Credentials

Endpoint: DELETE /auth

Request:

DELETE /v1/integrations/activecampaign/auth
Authorization: Bearer {jwt_token}

Success Response:

{
"success": true,
"message": "SUCCESS"
}

Error Response:

{
"success": false,
"errno": 400,
"message": "Unauthorised Access."
}

🔑 Credential Storage

MongoDB Document Structure

{
_id: ObjectId("..."),
api_key: "a0b219e049fb4f027fd927ade6a21d38abc123def456789",
base_url: "https://dashclicks83379.api-us1.com",
account_id: "12345",
owner: "user_Lwh9EzeD8",
workspace_id: "1234567890"
}

Model Methods

find(account_id, owner)

keysModel.find(account_id, owner).then(result => {
// Returns credential document or null
});

save(req)

keysModel.save(req).then(result => {
// Saves credentials from request
});

delete(account_id, owner)

keysModel.delete(account_id, owner).then(result => {
// Deletes credentials
});

🌍 Base URL Structure

Each ActiveCampaign account has a unique base URL based on:

  1. Account Name/ID: Unique identifier
  2. Region: Geographic location

Format:

https://{account_identifier}.api-{region}.com

Common Regions:

  • us1 - United States (primary)
  • eu1 - European Union
  • ap1 - Asia Pacific

Examples:

  • https://dashclicks83379.api-us1.com
  • https://mycompany123.api-us1.com
  • https://acmecorp.api-eu1.com

🔒 API Key Validation

When credentials are saved, the integration validates them by making a test request:

Validation Request:

GET {base_url}/api/3/contacts?limit=1
Api-Token: {api_key}

Valid Response: 200 OK with contact data

Invalid Response: 401 Unauthorized or 403 Forbidden

This ensures:

  • API key is active
  • Base URL is correct
  • Account has necessary permissions

🎯 Authorization Middleware

All protected endpoints require JWT authentication:

JWT Token Structure:

req.auth = {
account_id: '12345', // DashClicks account ID
uid: 'user_Lwh9EzeD8', // DashClicks user ID
workspace_id: '1234567890', // DashClicks workspace ID
// ... other JWT claims
};

Required JWT Claims

ClaimDescriptionExample
account_idDashClicks account ID"12345"
uidDashClicks user ID"user_Lwh9EzeD8"
workspace_idDashClicks workspace ID"1234567890"

🔐 Security Features

Single Connection Per User

Only one set of credentials allowed per user/account combination:

  • Prevents credential duplication
  • Ensures data consistency
  • Simplifies management

To update credentials:

  1. Delete existing credentials
  2. Save new credentials

Credential Validation

All credentials validated before storage:

  • API Key Format: Checked for validity
  • Base URL Format: Validated as HTTPS URL
  • API Access: Test request confirms connectivity

Storage Security

  • Credentials stored in MongoDB
  • Should be encrypted at rest (deployment-specific)
  • Access controlled by DashClicks authentication

⚠️ Error Handling

ErrorCauseSolution
"Record already exist!"Credentials already savedDelete old credentials first
"Base URL is required!"Missing base_url parameterProvide base URL from ActiveCampaign
"API Key is required!"Missing api_key parameterProvide API key from ActiveCampaign
"Invalid base_url or api_key."Credentials don't workVerify credentials in ActiveCampaign dashboard
"Unauthorised Access."No credentials foundSave credentials first

📝 Important Notes

  • 🔑 No Expiration: API keys don't expire automatically
  • 🌍 Region-Specific: Base URL must match account region
  • 👤 One Connection: Single credential set per user/account
  • Validation: Credentials tested before storage
  • 🔒 Security: Store credentials securely
  • No Refresh: No token refresh needed (unlike OAuth)

🔗 API Request Format

After saving credentials, all API requests use:

Headers:

Api-Token: {api_key}
Content-Type: application/json

URL Format:

{base_url}/api/3/{endpoint}

Example:

GET https://dashclicks83379.api-us1.com/api/3/contacts
Api-Token: a0b219e049fb4f027fd927ade6a21d38abc123def456789

🎯 Best Practices

Credential Management

  1. Rotate Keys Periodically: Generate new API keys regularly
  2. Delete Unused Keys: Remove credentials when no longer needed
  3. Monitor Usage: Track API calls for unusual activity
  4. Secure Storage: Ensure MongoDB encryption is enabled

Integration Setup

  1. Test Credentials: Verify in ActiveCampaign before saving
  2. Document Base URL: Note the exact URL for troubleshooting
  3. Handle Errors: Implement retry logic for transient failures
  4. Log Actions: Track credential save/delete operations
💬

Documentation Assistant

Ask me anything about the docs

Hi! I'm your documentation assistant. Ask me anything about the docs!

I can help you with:
- Code examples
- Configuration details
- Troubleshooting
- Best practices

Try asking: How do I configure the API?
09:30 AM