API reference
Margo API Reference
Research prospects from your apps and workflows. Inspect available contact details, source evidence and limitations before choosing a next step.
/api/v1/leads/generateGetting Started
Using Claude Code, ChatGPT or Codex? Read the AI agents / MCP documentation for setup, tools, permissions and troubleshooting. The REST API below is for developer tools and workflow automation.
The Margo API lets you programmatically generate local business leads. To get started:
- Create a Margo account and subscribe to the Business plan (API access is exclusive to Business)
- Go to Dashboard → API Keys and generate a key
- Verify your email, review current credit costs, then make an API call using the example below
Set MARGO_API_KEY and a unique MARGO_REQUEST_KEY for each intended search. Use a UUID or an 8–160 character key containing letters, digits, dots, underscores, colons or hyphens. Preserve the same key and body when reconciling the same job after a timeout; do not automatically resubmit a new search.
curl --max-time 30 -i -X POST https://www.margoleads.io/api/v1/leads/generate \
-H "Authorization: Bearer $MARGO_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $MARGO_REQUEST_KEY" \
-d '{
"category": "dentist",
"country": "US",
"state": "Florida",
"city": "Miami",
"maxResults": 10
}'Authentication
All API requests require a Bearer token in the Authorization header.
Authorization: Bearer margo_sk_xxxxxxxxxxxxxxxxxxxxSecurity: Never expose your API key in client-side code. Store it in environment variables (e.g. MARGO_API_KEY) and make API calls from your backend.
Managing Keys
Create, view, and revoke API keys from the API Keys page in your dashboard. Keys are shown only once at creation — store them securely.
Generate Leads
/api/v1/leads/generateGenerate local business leads by category and location. Contact fields, source evidence and review data are returned where available. Longer searches return HTTP 202 and a job URL to poll. Read limitations, constraint coverage and terminal status.
Request Body
categorystringrequiredBusiness type to search for. Examples: "dentist", "restaurant", "plumber", "hair_salon"
countrystringrequiredCountry code (ISO 3166-1 alpha-2). Examples: "US", "GB", "DE", "AU"
statestringRegion or location name, such as Florida or London. Use city or state for Maps targeting; state is not the country code.
citystringCity or region name to narrow results. Examples: "Miami", "London", "Berlin"
keywordstringAdditional keyword filter for more specific results. Example: "endodontist", "matcha"
maxResultsnumberMaximum number of leads requested. Governed API default: 20. Max: 300. Partial or empty results are possible.
Supported Business Categories
accountantarchitectbakerybankbarbeauty_saloncafecar_dealercar_repaircleaning_serviceclothing_storeconsultantcontractordentistdoctorelectricianelectronics_storeentertainmentevent_servicefinancial_advisorfurniture_storegymhair_salonhotelhvacinsurance_agencyit_serviceslandscapinglawyermarketing_agencymedia_productionmedical_specialistpet_storephotographerplumberreal_estate_agencyrestaurantschoolspatherapistveterinarianweb_designeryoga_studioSupported Countries
US, GB, AU, CA, NZ, AE, AR, BE, BR, ES, IE, KR, MX, NL, PL, SE, TH, TR, FR, IT, IN, JP, DE
Response Format
A search may finish immediately or return HTTP 202 with a durable job. Read terminal.status, not just the HTTP status. This illustrative response starts polling without starting another search:
{
"jobId": "your_job_id",
"terminal": { "status": "QUEUED", "requestedCount": 10, "deliveredCount": 0 },
"limitations": [],
"constraintCoverage": { "enforced": [], "notGuaranteed": [] },
"pollUrl": "/api/v1/leads/jobs/your_job_id"
}Poll GET /api/v1/leads/jobs/:id with the same API key. The response contains job, terminal, limitations and constraintCoverage. QUEUED/RUNNING are in progress. COMPLETE, PARTIAL, EMPTY, FAILED and CANCELLED are terminal. Results are in job.result when available; an immediate generation response can contain the result at the top level.
Inspect delivered counts, stop reasons and constraints before using the records. PARTIAL is not full coverage, and EMPTY does not prove no prospects exist. Cancel an active owned job with POST /api/v1/leads/jobs/:id/cancel; already delivered research may remain billable.
Lead fields, where available
businessNamestringBusiness name
contactNamestring | nullContact name, where available
emailstring | nullEmail address; availability is not verification
phonestring | nullPhone number, where available
addressstring | nullAddress, where available
websitestring | nullWebsite URL, where available
emailVerifiedboolean | nullOnly treat an address as verified when independent verification evidence supports it
rawDataobjectSource-specific review fields, social profiles and source links, where supplied. These fields can be absent.
Skill Manifest (AI Agents)
Margo provides a machine-readable skill manifest that AI agents can use to discover and interact with the API. Download it with:
curl -o margo-skill.json https://www.margoleads.io/api/v1/skillThe JSON manifest describes available endpoints, parameters, authentication and response schemas for developers. For agent tool discovery and account linking, use the MCP documentation.
Tip: You can also download the skill file from the API Keys page in your dashboard.
Rate Limits & Credits
API usage requires Business access and a verified email. Credits depend on the source and current research policy, including any disclosed search minimum. Read current tariffs in the API manifest or the MCP credit reference before starting a search.
Use a stable Idempotency-Key for each intended search and reuse it for identical retries. Use a new key only for a new search. Polling the existing job does not start another search.
HTTP 429 indicates a request or quota limit; inspect the returned error and back off rather than retrying rapidly. Research credit availability is separate from request admission. Check current allowance and purchased credits in your account; plan details are on Pricing.
Error Handling
Inspect both HTTP status and JSON body. A generation request can return HTTP 200 with a terminal FAILED result, or HTTP 202 while work continues.
400: check JSON, source inputs and the required Idempotency-Key (8–160 letters, digits, periods, underscores, colons or hyphens).401: missing, expired or revoked API key.403: Business access or email verification required.404: job not found for this account.409: conflicting retry inputs, or cancellation of an already-terminal/unknown job.422: unsupported targeting, such as strict city targeting on a country-level source.429: rate or quota limit; inspect the error and back off.5xx: unavailable source or server error. Retry identical searches with their existing key; contact support if persistent.
{ "error": "Idempotency-Key is required." }Examples
For bounded polling with strict terminal-state handling, see the CrewAI integration guide and download its tested Python source. For a workflow integration, follow the Make guide.
Preserve the same ID for retries; use a new ID for each new intended search. Poll the existing job, not the generation endpoint. These examples stop after three minutes; check the same job later if it is still running.
Python
import requests
import os
import time
base = "https://www.margoleads.io"
headers = {"Authorization": f"Bearer {os.environ['MARGO_API_KEY']}"}
response = requests.post(
f"{base}/api/v1/leads/generate",
headers={
**headers,
"Idempotency-Key": "london-restaurants-example-001",
},
json={
"category": "restaurant",
"country": "GB",
"city": "London",
"maxResults": 10,
},
timeout=35,
)
response.raise_for_status()
data = response.json()
for _ in range(60):
if data.get("terminal", {}).get("status") not in ("QUEUED", "RUNNING"):
break
time.sleep(3)
job_id = data.get("jobId") or data["job"]["id"]
response = requests.get(f"{base}/api/v1/leads/jobs/{job_id}",
headers=headers, timeout=15)
response.raise_for_status()
data = response.json()
else:
raise TimeoutError("Check this same job again later.")
if data.get("terminal", {}).get("status") in ("FAILED", "CANCELLED"):
raise RuntimeError(f"Search ended: {data['terminal']['status']}")
print(data.get("terminal"), data.get("limitations"), data.get("constraintCoverage"))
result = data.get("job", {}).get("result") or data
for lead in result.get("leads", []):
print(lead.get("businessName"), lead.get("email"))JavaScript / Node.js
const base = "https://www.margoleads.io";
const headers = { Authorization: `Bearer ${process.env.MARGO_API_KEY}` };
async function json(response) {
const data = await response.json();
if (!response.ok) throw new Error(data.error || `HTTP ${response.status}`);
return data;
}
let data = await json(await fetch(base + "/api/v1/leads/generate", {
method: "POST",
headers: {
...headers,
"Content-Type": "application/json",
"Idempotency-Key": "new-york-plumbers-example-001",
},
body: JSON.stringify({
category: "plumber",
country: "US",
city: "New York",
maxResults: 10,
}),
signal: AbortSignal.timeout(35000),
}));
let polls = 0;
while (["QUEUED", "RUNNING"].includes(data.terminal?.status)) {
if (++polls > 60) throw new Error("Check this same job again later.");
await new Promise(resolve => setTimeout(resolve, 3000));
const jobId = data.jobId || data.job.id;
data = await json(await fetch(base + "/api/v1/leads/jobs/" + encodeURIComponent(jobId), {
headers, signal: AbortSignal.timeout(15000),
}));
}
if (["FAILED", "CANCELLED"].includes(data.terminal?.status)) {
throw new Error("Search ended: " + data.terminal.status);
}
console.log(data.terminal, data.limitations, data.constraintCoverage);
const result = data.job?.result || data;
for (const lead of result.leads || []) console.log(lead.businessName, lead.email);cURL
curl -X POST https://www.margoleads.io/api/v1/leads/generate \
-H "Authorization: Bearer $MARGO_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: sydney-gyms-example-001" \
-d '{"category":"gym","country":"AU","city":"Sydney","maxResults":20}'
# If still QUEUED or RUNNING, poll its jobId:
curl https://www.margoleads.io/api/v1/leads/jobs/YOUR_JOB_ID \
-H "Authorization: Bearer $MARGO_API_KEY"Plans & Pricing
- Starter: $9/month with 2,000 credits.
- Professional: $39/month with 9,000 credits.
- Business: $129/month with 30,000 credits.
Credits are work units, not a universal one-lead allowance. Discovery, enrichment and verification consume different amounts.
REST requires the Business API entitlement. MCP access is available on Professional and higher plans. Both use account credits. Source-specific tariffs and search minimums apply; a requested count is not a guarantee of complete delivery or contact availability.
Support
Need help with the API?
- Email: Contact us
- Website: margoleads.io