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_PROJECT_ID="YOUR_PROJECT_ID"

# Verify they're set
echo "API Key: $MAGNETITE_API_KEY"
echo "Project ID: $MAGNETITE_PROJECT_ID"

Basic Examples

Generate Lead Magnet
Create a new lead magnet for a prospect
curl -X POST "https://magnetite.ai/api/projects/$MAGNETITE_PROJECT_ID/generate" \
  -H "Authorization: Bearer $MAGNETITE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "john.smith@example.com",
    "fullName": "John Smith",
    "company": "Acme Corp",
    "domain": "acmecorp.com",
    "title": "VP of Sales",
    "industry": "SaaS"
  }'

Expected Response:

{
  "success": true,
  "leadId": "lead_abc123",
  "jobId": "job_xyz789",
  "leadMagnetUrl": "https://acme-corp.go.magnetite.ai/lead_abc123",
  "status": "queued",
  "message": "Lead magnet generation started successfully",
  "statusEndpoint": "/api/generation/job_xyz789/status",
  "inputData": {
    "email": "john.smith@example.com",
    "fullName": "John Smith",
    "company": "Acme Corp"
  }
}
Check Generation Status
Monitor the progress of a generation job
# Using job ID from generation response
curl -X GET "https://magnetite.ai/api/generation/job_xyz789/status" \
  -H "Authorization: Bearer $MAGNETITE_API_KEY"

Response Examples:

Processing:
{
  "success": true,
  "job": {
    "status": "processing",
    "progressPercentage": 45,
    "currentPhase": "research_running",
    "estimatedTimeRemaining": 90,
    "processingTime": 55
  }
}
Completed:
{
  "success": true,
  "job": {
    "status": "completed",
    "progressPercentage": 100,
    "currentPhase": "completed",
    "processingTime": 127,
    "leadMagnetUrl": "https://acme-corp.go.magnetite.ai/lead_abc123"
  }
}
Check Status by Lead ID
Alternative way to check status using lead ID
# Using lead ID from generation response
curl -X GET "https://magnetite.ai/api/leads/lead_abc123/job-status" \
  -H "Authorization: Bearer $MAGNETITE_API_KEY"

Advanced Examples

Generate with Custom Fields
Include project-specific custom fields for better personalization
curl -X POST "https://magnetite.ai/api/projects/$MAGNETITE_PROJECT_ID/generate" \
  -H "Authorization: Bearer $MAGNETITE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "jane.doe@techcorp.com",
    "fullName": "Jane Doe",
    "company": "TechCorp Inc",
    "domain": "techcorp.com",
    "title": "Marketing Director",
    "industry": "Technology",
    "companySize": "51-200",
    "customFields": {
      "budget": "100000",
      "timeline": "Q2 2024",
      "interests": ["marketing automation", "lead generation"]
    }
  }'
Rate Limit Monitoring
View response headers including rate limit information
curl -X POST "https://magnetite.ai/api/projects/$MAGNETITE_PROJECT_ID/generate" \
  -H "Authorization: Bearer $MAGNETITE_API_KEY" \
  -H "Content-Type: application/json" \
  -v \
  -d '{
    "email": "test@example.com",
    "fullName": "Test User",
    "company": "Test Company"
  }'

Look for these headers in the response:

X-RateLimit-Limit: 10
X-RateLimit-Remaining: 9
X-RateLimit-Reset: 1703123456
Error Handling
Handle different types of API errors
# Example with invalid API key
curl -X POST "https://magnetite.ai/api/projects/$MAGNETITE_PROJECT_ID/generate" \
  -H "Authorization: Bearer invalid_key" \
  -H "Content-Type: application/json" \
  -w "HTTP Status: %{http_code}\n" \
  -d '{
    "email": "test@example.com"
  }'

Error Response:

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

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 '.jobId'
Set environment variables to keep API keys secure in scripts