How to create & use syncs in Nango
nango-integrations
folder yet, follow the initial Functions setup guide first.
Otherwise, you can skip to the next step.
nango-integrations
folder, create the file for your new sync function.
Sync files should be within a syncs
folder, which is nested under the integration’s folder.
For example, if you want to create a new sync to sync contacts
from salesforce
, your structure should look like this:
index.ts
file:
exec
method, implement the logic of your sync. Edit MyObject
to contain the properties you need.
The following can help you with your implementation:
nango
object reference to understand the SDK methods available in syncsnango.lastSyncDate
is the last date at which the sync has runawait nango.batchSave()
to persist external data in Nango’s cacheawait nango.get()
to perform an API request (automatically authenticated by Nango)await nango.log()
to write custom log messagesdryrun
function of the CLI:
nango dryrun --help
Because this is a dry run, syncs won’t persist data in Nango. Instead, the retrieved data is printed to the console.
dryrun
retrieves connections from your dev
environment. You can change this with a CLI flag.nango-integrations
folder, run:
--sync
parameter:
nango deploy -h
for more options to deploy only parts of your integrations.
To fetch the synced data in your product, follow the steps in the next setion.
modifiedAfter
timestamp from the webhook payload as a parameter in your request to fetch only the modified records.
_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: