cURL Examples

Command Line

Complete cURL examples for testing and integrating with the Magnetite API from the command line

Environment Setup

Set environment variables to avoid repeating sensitive information:

# Set your API credentials as environment variables
export MAGNETITE_API_KEY="YOUR_API_KEY"
export MAGNETITE_CAMPAIGN_ID="YOUR_CAMPAIGN_ID"

# Verify they're set
echo "API Key: $MAGNETITE_API_KEY"
echo "Campaign ID: $MAGNETITE_CAMPAIGN_ID"

Basic Examples

Add Lead to Campaign
Add a new lead to your campaign for automated outreach
curl -X POST "https://magnetite.ai/api/campaigns/$MAGNETITE_CAMPAIGN_ID/leads" \
  -H "Authorization: Bearer $MAGNETITE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "companyName": "Acme Corp",
    "contactName": "John Smith",
    "email": "john@acme.com",
    "title": "VP of Sales"
  }'

Expected Response:

{
  "success": true,
  "prospectId": "abc123def456",
  "status": "queued",
  "message": "Lead added to campaign and queued for outreach"
}
Add Lead with All Optional Fields
Include additional information for better personalization
curl -X POST "https://magnetite.ai/api/campaigns/$MAGNETITE_CAMPAIGN_ID/leads" \
  -H "Authorization: Bearer $MAGNETITE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "companyName": "TechCorp Inc",
    "contactName": "Jane Doe",
    "email": "jane@techcorp.com",
    "title": "Marketing Director",
    "domain": "techcorp.com",
    "phone": "+1-555-123-4567",
    "linkedInUrl": "https://linkedin.com/in/janedoe",
    "companyLinkedInUrl": "https://linkedin.com/company/techcorp",
    "notes": "Met at SaaStr conference, interested in automation"
  }'
Add Lead with Enrichment Data
Pass pre-enriched company and contact data
curl -X POST "https://magnetite.ai/api/campaigns/$MAGNETITE_CAMPAIGN_ID/leads" \
  -H "Authorization: Bearer $MAGNETITE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "companyName": "BigCorp Industries",
    "contactName": "Michael Chen",
    "email": "michael@bigcorp.com",
    "title": "Sales Director",
    "company": {
      "industry": "Technology",
      "employeeCount": 500,
      "revenue": "$100M-500M",
      "fundingStage": "Series C",
      "technologies": ["Salesforce", "HubSpot", "Slack"]
    },
    "contact": {
      "seniority": "Director",
      "department": "Sales",
      "city": "New York",
      "country": "USA"
    },
    "extraContext": {
      "painPoints": ["Lead generation", "Sales automation"],
      "referredBy": "Partner program"
    }
  }'

Advanced Examples

Rate Limit Monitoring
View response headers including rate limit information
curl -X POST "https://magnetite.ai/api/campaigns/$MAGNETITE_CAMPAIGN_ID/leads" \
  -H "Authorization: Bearer $MAGNETITE_API_KEY" \
  -H "Content-Type: application/json" \
  -v \
  -d '{
    "companyName": "Test Company",
    "contactName": "Test User",
    "email": "test@example.com"
  }'

Look for these headers in the response:

X-RateLimit-Limit: 10
X-RateLimit-Remaining: 9
X-RateLimit-Reset: 1703123456
Bulk Import with Shell Script
Import multiple leads from a file
#!/bin/bash
# bulk_import.sh

# Read leads from a JSON file and add them to campaign
# leads.json should be an array: [{"companyName": "...", ...}, ...]

CAMPAIGN_ID="$MAGNETITE_CAMPAIGN_ID"
API_KEY="$MAGNETITE_API_KEY"

# Process each lead
cat leads.json | jq -c '.[]' | while read lead; do
  echo "Adding lead: $(echo $lead | jq -r '.email')"

  response=$(curl -s -X POST "https://magnetite.ai/api/campaigns/$CAMPAIGN_ID/leads" \
    -H "Authorization: Bearer $API_KEY" \
    -H "Content-Type: application/json" \
    -d "$lead")

  success=$(echo $response | jq -r '.success')

  if [ "$success" = "true" ]; then
    echo "  ✓ Added successfully"
  else
    error=$(echo $response | jq -r '.error')
    echo "  ✗ Failed: $error"
  fi

  # Respect rate limits - wait 1 second between requests
  sleep 1
done

echo "Import complete!"
Error Handling
Handle different types of API errors
# Example with invalid API key
curl -X POST "https://magnetite.ai/api/campaigns/$MAGNETITE_CAMPAIGN_ID/leads" \
  -H "Authorization: Bearer invalid_key" \
  -H "Content-Type: application/json" \
  -w "\nHTTP Status: %{http_code}\n" \
  -d '{
    "companyName": "Test",
    "contactName": "Test",
    "email": "test@example.com"
  }'

Error Response:

{
  "error": "Invalid or expired API key"
}
HTTP Status: 401

Common Error Codes:

400 - Bad Request (missing required fields)

401 - Unauthorized (invalid API key)

403 - Forbidden (no access to campaign)

404 - Not Found (campaign doesn't exist)

409 - Conflict (duplicate lead)

429 - Rate limit exceeded

Parse Response with jq
Extract specific fields from the response
# Add lead and extract prospect ID
PROSPECT_ID=$(curl -s -X POST "https://magnetite.ai/api/campaigns/$MAGNETITE_CAMPAIGN_ID/leads" \
  -H "Authorization: Bearer $MAGNETITE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "companyName": "Acme Corp",
    "contactName": "John Smith",
    "email": "john@acme.com"
  }' | jq -r '.prospectId')

echo "Created prospect: $PROSPECT_ID"

# Check if successful
curl -s -X POST "https://magnetite.ai/api/campaigns/$MAGNETITE_CAMPAIGN_ID/leads" \
  -H "Authorization: Bearer $MAGNETITE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "companyName": "Test Co",
    "contactName": "Test User",
    "email": "test@testco.com"
  }' | jq '{success: .success, id: .prospectId, status: .status}'

Tips for Using cURL

Use -v flag to see detailed request/response headers
Save responses to files with -o filename.json
Use jq to parse JSON responses: curl ... | jq '.prospectId'
Set environment variables to keep API keys secure in scripts