Examples
- Sync function
- Action function
Configuration
createSync
The description of the sync.
The function that will be called when the sync is triggered.
The frequency of the sync.
The models that will be synced by this function.
You need one endpoint per model.
Optional schema defining the shape of checkpoint data for this sync.
Use checkpoints to save progress and avoid re-fetching all data on every run. See the checkpoints guide for details.
If
true, automatically runs the sync when a new connection is created.
Otherwise, it needs to be triggered via the API or Nango UI.The connectionβs metadata of the action.
The function that will be called when a webhook is received.
The integrationβs scopes required by the action.
This field is for documentation purposes only and currently not enforced by Nango.
[DEPRECATED] Instead use
await nango.trackDeletesStart('modelName') and await nango.trackDeletesEnd('modelName') inside the sync exec function.When trackDeletes is set to true, Nango automatically detects deleted records during full syncs only and marks them as deleted in each recordβs metadata (soft delete). These records remain stored in the cache.When set to false, Nango does not mark missing records as deleted, even if they werenβt returned in the latest full syncβthey simply remain in the cache unchanged.Defaults to false.The version of the sync.
Use it to track changes to the sync inside Nangoβs UI.
The webhook subscriptions of the sync.
Specify the types of webhooks the method
onWebhook will handle.
If a webhook type is not on the list, it will not be handled.[DEPRECATED] Use the
GET /records API endpoint to fetch records.createAction
The description of the sync.
The function that will be called when the action is triggered.
The input required by the action when triggering it.
The output of the action.
The version of the sync.
Use it to track changes to the sync inside Nangoβs UI.
The connectionβs metadata of the action.
The integrationβs scopes required by the action.
This field is for documentation purposes only and currently not enforced by Nango.
[DEPRECATED] Use the
POST /action/trigger API endpoint to trigger actions.createOnEvent
The description of the sync.
The event that will trigger this function.
The function that will be called when the action is triggered.
The version of the onEvent function.
Use it to track changes to the onEvent function inside Nangoβs UI.
The connectionβs metadata of the function.
HTTP requests
Makes an HTTP request inside an integration function:HTTP request retries
Configure behavior with two optional fields on your HTTP request config:retries and retryOn.
When a failed request is retried
Nango retries only when the failure looks transient. Exact rules depend on the integration:| Field | Condition for Retry |
|---|---|
| Network Error | If code is one of:ECONNRESET, ETIMEDOUT, ECONNABORTED, ECONNREFUSED, EHOSTUNREACH, EAI_AGAIN |
| Transient HTTP Error | If provider specific proxy.retry.error_code is configured in providers.yaml, only matching statuses are retried.Otherwise, by default, status codes 401, 429, 5xx are retried. Additional status specified in retryOn are always retried in addition to the above statuses. |
Status
401 is retryable so Nango can recover after refreshing the connection with potentially updated credentials. If a 401 happens and the connection credentials do not change on the next fetch, Nango treats that as a definitive authentication failure and stops performing additional retriesBackoff
Between retry attempts Nango waits with exponential backoff: first wait 3000ms, then each wait doubles, capped at 10 minutes.Logging
You can collect logs in integration functions. This is particularly useful when:- developing, to debug your integration functions
- in production, to collect information about integration function executions & understand issues
Log Levels
Nango supports the following log levels (from most to least verbose):debug, info, warn, error, off.
Only logs with a level greater than or equal to the configured logger level will surfaced in the Nango UI Logs tab. For example, if the logger level is set to warn, only warn and error logs will be shown.
Default log levels:
- All cloud environments:
warn(only warnings and errors are logged by default) - CLI dry-run:
debug(all logs are shown in the console)
Configuring Log Level
You can override the default log level in two ways:-
Environment variable: Set
NANGO_LOGGER_LEVELin your environment settings (values:debug,info,warn,error,off). It will apply to all your functions running in this environment and can be overridden in functions by usingnango.setLogger(...) - In your function code:
Environment variables
Integration functions sometimes need to access sensitive variables that should not be revealed directly in the code. For this, you can define environment variables in the Nango UI, in the Environment Settings tab. Then you can retrieve these environment variables from integration functions with:Trigger action
You can call action functions from other integration functions with:Paginate through API responses
Nango provides a helper to automatically paginate endpoint responses. Similar to HTTP requests, thenango.paginate() method takes in a ProxyConfiguration parameter.
Use the paginate field to of the ProxyConfiguration to specify how the endpointβs pagination work. Hereβs an example for a Jira endpoint:
for loop to iterate through the paginated results.
The pagination helper supports 3 types of pagination: cursor, link or offset with the following settings:
Get Integration
Returns the current integration informationGET /integrations/{uniqueKey} query parameters: documentation
Response
See GET /integrations/{uniqueKey} response: documentation
Manage connection metadata
Get connection metadata
Returns the connectionβs metadata.Set connection metadata
Set custom metadata for the connection (overrides existing metadata).Edit connection metadata
Edit custom metadata for the connection. Only overrides & adds specified properties, not the entire metadata.Get the connection credentials
Returns a specific connection with credentials.The response content depends on the API authentication type (OAuth 2, OAuth 1, API key, Basic auth, etc.).
Sync-specific helper methods
Sync functions persist data updates to the Nango cache, which your app later fetches. See the sync functions section.Checkpoints
Checkpoints allow syncs to save their progress and resume from where they left off. This is useful for:- Resuming after failures without re-fetching all data
- Tracking pagination state across sync runs
- Storing custom cursor/offset values
checkpoint schema in your sync configuration (see Configuration). For a complete guide on implementing incremental syncs with checkpoints, see the checkpoints guide. If you are migrating from nango.lastSyncDate, see the migration guide.
getCheckpoint()
Retrieves the current checkpoint. Returnsnull on first run or after a reset.
null if no checkpoint exists.
saveCheckpoint()
Saves the current progress. Call this after processing each batch of data to enable resumption if the sync fails.clearCheckpoint()
Clears the checkpoint. Use at the end of a full sync so the next run starts from the first page. Checkpoints are also automatically cleared when triggering a sync withreset: true.
Save records
Upserts records to the Nango cache (i.e. create new records, update existing ones). Each record needs to contain a uniqueid field used to dedupe records.
Delete records
Marks records as deleted in the Nango cache. Deleted records are still returned when you fetch them, but they are marked as deleted in the recordβs metadata (i.e. soft delete). To implement deletion detection in your syncs, follow this guide. The only field that needs to be present in each record when callingbatchDelete is the unique id; the other fields are ignored.
Detect deletions automatically
Automatically detects and marks records as deleted by comparing what existed beforetrackDeletesStart with what was saved between trackDeletesStart and trackDeletesEnd.
trackDeletesStart at the beginning of your sync execution, before fetching any data. Call trackDeletesEnd after all records have been saved with batchSave. Nango will compare the records that existed before trackDeletesStart with those saved in the window and mark any missing records as deleted.
Parameters (both functions)
Important considerations:
- Only use within syncs that fetch the complete dataset between
trackDeletesStartandtrackDeletesEnd - If your sync fails or doesnβt fetch the complete dataset, avoid calling
trackDeletesEndas it may cause false deletions - Records are soft deleted (marked with
_metadata.deleted = true) and remain in the cache
deleteRecordsFromPreviousExecutions is deprecated. Use trackDeletesStart/trackDeletesEnd instead.Update records
Updates records in the Nango cache by merging the given data into the existing record. Theid field is required in each record and used to determine what existing record to merge into.
batchUpdate is primarily useful in webhook sync functions, where you receive partial updates from a webhook and want to merge them into the existing records.
The merge algorithm used is a deep merge. Nested objects are merged recursively, while arrays always use the new value for the array. Any fields not present in the update record are left unchanged.
Take special care when using batchUpdate with records containing arrays. The merge algorithm does not attempt to merge arrays, but rather always uses the value of the new array.
Get records
Fetches records from the Nango cache by ID. Returns a Map where the keys are the requested IDs, and the values are the corresponding records. Any records that are not found will simply be absent from the map. Example usage:Variant
If you are using sync variants, you can access the current variant name via thenango.variant property.
Action-specific helper methods
ActionError
You can use ActionError in an action function to return a descriptive error to your app when needed:
Relative imports in functions
You can import relative files into your functions to allow for code abstraction and to maintain DRY (Donβt Repeat Yourself) principles. This means you can reuse code across different functions by importing it. The imported file must live in thenango-integrations
directory and can be imported in the following way: