Skip to main content

Overview

The lead sync API lets you push leads from your CRM (HubSpot, Salesforce, Pipedrive, or any custom system) into Naturalead. It supports idempotent upserts using an external lead_id, so you can run periodic syncs without creating duplicates.

Idempotent Upserts

Use your CRM’s lead ID as the external identifier. Re-syncing the same lead updates it instead of creating a duplicate.

Bulk Operations

Sync up to 100 leads per request. The API handles partial failures gracefully.

Authentication

Authenticate sync requests with an API key.
Sync requests require an API key with the leads:sync_create scope. Create one in Settings > API Keys in the dashboard.

Using External lead_id for Idempotent Upserts

Every lead in the sync payload can include a lead_id field that maps to your CRM’s unique identifier. When Naturalead receives a lead with a lead_id that already exists in your account, it updates the existing lead instead of creating a new one. This makes your sync operations idempotent — running the same sync twice produces the same result.

Bulk Sync Example

Send an array of leads to the sync endpoint. Each lead should include a lead_id from your CRM.

Syncing Incomplete Records

Only lead_id and phone are required. CRM records that are missing a name, an email address, or both are accepted and synced as-is. On a re-sync, a field you omit keeps whatever value is already stored, so a partial payload never overwrites data with blanks. To clear a stored name or email, send it explicitly as "" or null.

Handling Partial Failures

When syncing multiple leads, some may succeed while others fail validation. The API does not roll back successful operations when others fail. Instead, it returns a detailed breakdown.
Always check the errors array in the response. A 200 status code does not mean every lead was synced successfully — it means the request was processed, and the response contains the outcome for each lead.
Recommended error handling strategy:
  1. Log all entries from the errors array with their lead_id for investigation.
  2. Fix the invalid data in your CRM.
  3. Re-sync only the failed leads in the next run.

Bulk Delete for Synced Leads

To remove leads that were deleted in your CRM, use the bulk delete endpoint with the external lead_id values.

Rate Limit Considerations

The sync API has a dedicated rate limit to protect system stability.
If you exceed the rate limit, the API returns a 429 Too Many Requests response with a Retry-After header indicating how many seconds to wait before retrying.
For large initial imports (more than 5,000 leads), break the sync into batches:

Best Practices for Periodic Sync

1

Use External lead_id Consistently

Always include the CRM’s unique lead identifier as lead_id. This is the key that makes upserts idempotent. Never omit it, or you risk creating duplicates.
2

Sync Incrementally

Rather than syncing your entire CRM on every run, track the last sync timestamp and only send leads that were created or modified since then. This reduces API calls and processing time.
3

Handle Deletes Separately

After syncing new and updated leads, query your CRM for recently deleted records and send those to the bulk delete endpoint.
4

Schedule During Off-Peak Hours

If you are syncing large volumes, schedule your sync jobs during off-peak hours to avoid competing with real-time conversation traffic for rate limit capacity.
5

Monitor and Alert on Failures

Log every sync response and set up alerts when the failed count exceeds a threshold. Persistent failures often indicate data quality issues in the CRM that should be resolved at the source.
For real-time sync (pushing leads as they are created in your CRM), consider using your CRM’s webhook or event system to trigger individual lead creation via POST /api/leads instead of the bulk sync endpoint.