Authentication

Learn how to authenticate your API requests to Magnetite

API Key Authentication

Magnetite uses API keys to authenticate requests. You can create and manage API keys from your dashboard settings.

Getting Your API Key

  1. Log in to your Magnetite dashboard
  2. Navigate to Settings → API Keys
  3. Click Create API Key
  4. Give your key a descriptive name (e.g., "Production Integration")
  5. Copy your API key immediately

Using Your API Key

Include your API key in the Authorization header as a Bearer token:

curl -X POST "https://magnetite.ai/api/campaigns/YOUR_CAMPAIGN_ID/leads" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"companyName": "Acme Corp", "contactName": "John Smith", "email": "john@acme.com"}'

Examples in Different Languages

JavaScript (Axios)

const axios = require('axios');

const response = await axios.post(
  'https://magnetite.ai/api/campaigns/YOUR_CAMPAIGN_ID/leads',
  {
    companyName: 'Acme Corp',
    contactName: 'John Smith',
    email: 'john@acme.com'
  },
  {
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    }
  }
);

Python (Requests)

import requests

response = requests.post(
    'https://magnetite.ai/api/campaigns/YOUR_CAMPAIGN_ID/leads',
    json={
        'companyName': 'Acme Corp',
        'contactName': 'John Smith',
        'email': 'john@acme.com'
    },
    headers={
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json'
    }
)

PHP

<?php
$campaignId = 'YOUR_CAMPAIGN_ID';
$apiKey = 'YOUR_API_KEY';

$data = [
    'companyName' => 'Acme Corp',
    'contactName' => 'John Smith',
    'email' => 'john@acme.com'
];

$ch = curl_init("https://magnetite.ai/api/campaigns/$campaignId/leads");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Authorization: Bearer $apiKey",
    "Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
curl_close($ch);

Error Responses

If authentication fails, you'll receive one of these error responses:

401 - Missing API Key

{
  "error": "Authorization header is required"
}

401 - Invalid API Key

{
  "error": "Invalid or expired API key"
}

403 - No Access to Campaign

{
  "error": "You do not have access to this campaign"
}

Best Practices

  • Store API keys in environment variables, not in your code
  • Use different API keys for development and production
  • Rotate your API keys regularly
  • Never expose API keys in client-side code
  • Use HTTPS for all API requests
  • Monitor your API usage in the dashboard

Next Steps

Now that you understand authentication, learn how to add leads to your campaigns.

Add Lead to Campaign →