Read from an API
Step-by-step guide on how to continuously sync data from an API (using a sync template).
Pre-requisite: complete the Configure an integration guide.
Activate a sync template
Nango uses syncs to read data from APIs continuously. For common use cases, templates are available to let you get started fast.
Select your integration in the Integrations tab, and navigate to the Endpoints tab. Available sync templates will appear in the endpoint list. Select the relevant one and enable it with the toggle.
Nango will automatically sync the corresponding records in the background for each relevant connection.
Is there no template for your API? Or none matching your exact use case?
Learn more about how to build a custom integration and extend a template.
Listen for webhooks from Nango
Nango sends webhook notifications to your backend whenever new data is available for a connection & sync combination.
To set this up, go to the Environment Settings tab and configure a Webhook URL to which Nango will send notifications.
The webhook from Nango is a POST request with the following body:
Webhooks with non-2xx responses are retried with exponential backoff.
Before using webhooks in production, verify their origin (step-by-step guide).
Fetch the latest data
After receiving a Nango webhook, fetch the latest records using the backend SDK (reference) or API (reference).
Use the modifiedAfter
timestamp from the webhook payload as a parameter in your request to fetch only the modified records.
This returns an array of records conforming to the specified data model.
Each record contains useful metadata automatically generated by Nango:
Cursor-based synchronization
In practice, webhook notifications can be missed, and relying solely on the webhook payload to fetch modified records can cause you to miss some updates.
A more reliable way of keeping track of how far you’ve synced records (for each connection & sync combination) is to rely on record cursors.
Each record comes with a synchronization cursor in _nango_metadata.cursor
. Nango uses cursors internally to keep a chronological list of record modifications.
Each time you fetch records, you should store the cursor
of the last record you fetched to remember how far you’ve synced (for each connection & sync combination).
The next time you fetch records, pass in the cursor of the last-fetched record to only receive records modified after that record:
So, the overall logic for cursor-based synchronization should be:
- Receive a webhook notification from Nango
- Query your database for the cursor of the last-fetched record
- Fetch the modified records (passing the cursor)
- Store the modified records
- Store the last-fetched record cursor
Write back to APIs (2-way syncing)
Write back to APIs with actions (step-by-step guide) or proxy requests (step-by-step guide).
Troubleshoot errors & monitor
Navigate to the Logs tab to inspect potential errors & monitor sync executions.
Questions, problems, feedback? Please reach out in the Slack community.
Was this page helpful?