Use this file to discover all available pages before exploring further.
Sync functions keep external API data fresh in your app. They run on a recurring cadence, write records to Nango’s records cache, and let your app consume changes reliably.Use sync functions when your app needs to replicate a dataset from an external system for sync, indexing, RAG, reporting, or change-detection workflows.
Sync implementation quality matters. Suboptimal syncs can consume far more API calls, compute, memory, and storage than needed; they can also become expensive, crash, behave unreliably, or hit provider rate limits. Before deploying a sync to production, review the Sync efficiency guide.
For agents
Before generating a sync, collect the integration ID, connection ID for testing, target records, provider pagination style, incremental filter, deletion strategy, required metadata, and expected sync frequency.Prefer incremental syncs when the provider supports them. Save records page by page, checkpoint after successful writes, and keep the record model limited to fields the app actually needs.
Customer configuration, such as selected folders, projects, accounts, regions, or custom field mappings.
Provider context discovered after authorization.
Feature flags or filters that change what the sync fetches.
If the sync should not run before configuration exists, set autoStart: false, save the required metadata from your app, then start the schedule after configuration is complete.From your app, call the Node SDK nango.startSync() method:
If autoStart: true, Nango starts the schedule for new connections automatically. Otherwise, start it after the connection is ready and required metadata is saved:
Configure your app’s Nango webhook URL in Environment Settings > Webhook URLs. After a run, Nango sends a sync webhook with the connection, integration, sync name, model, and change counts. Your app should then read records by cursor:
TypeScript
cURL
import { Nango } from '@nangohq/node';const nango = new Nango({ secretKey: process.env.NANGO_SECRET_KEY! });const result = await nango.listRecords({ providerConfigKey: 'crm', connectionId: '<CONNECTION-ID>', model: 'Contact', cursor: '<last-processed-cursor>'});
The consumer loop is: receive a sync webhook from Nango, look up the last cursor processed for that connection and model, fetch records with that cursor, process them, then store the cursor from the last record fetched.
You can implement two-way syncs by combining sync functions with action functions:
Use a sync function to replicate external data into your app and keep your local state fresh.
Use action functions for writes back to the external API, such as creating, updating, or deleting records.
After a write action succeeds, update your local state optimistically or trigger the relevant sync so the records cache catches up with the external source of truth.
This keeps the read path and write path explicit. The sync owns ongoing data freshness, checkpoints, record storage, and change delivery. Actions own user-initiated writes and provider-specific validation or side effects.For unified models, use the same schema for synced records and write action input where possible. This keeps your app from branching on each provider while still letting each provider implementation handle API-specific fields and edge cases.