@nangohq/node.
Instantiate the backend SDK
Install it with your favorite package manager, e.g.:npm i -S @nangohq/node
Nango class:
import { Nango } from '@nangohq/node';
const nango = new Nango({ secretKey: '<SECRET-KEY>' });
Show child attributes
Show child attributes
Rate limits
The Nango SDK is rate-limited to prevent abuse and ensure fair usage across all clients. The rate limit is enforced on a per-account basis, with a fixed window of time and a maximum number of requests allowed within that window. If a client exceeds the rate limit, the API will respond with a 429Too Many Requests status code. In this case, the Retry-After header is included, indicating the number of seconds the client should wait before making another request to avoid being rate-limited.
To handle rate limiting gracefully, clients should monitor for the 429 status code and honor the Retry-After header value provided in the response.
// Example:
try {
const res = await nango.listIntegrations();
...
} catch(err) {
if (err.response.status === 429) {
const retryAfter = err.response.headers['retry-after'];
// wait and retry
...
}
...
}
Integrations
List all integrations
Returns a list of integrations.await nango.listIntegrations()
Show child attributes
Show child attributes
{
"configs": [
{
"unique_key": "slack-nango-community",
"provider": "slack"
},
{
"unique_key": "github-prod",
"provider": "github"
},
]
}
Get an integration
Returns a specific integration.await nango.getIntegration(<INTEGRATION-ID>);
Show child attributes
Show child attributes
Show child attributes
Show child attributes
{
"config": {
"unique_key": "slack-nango-community",
"provider": "slack",
"syncs": [
{
"name": "slack-messages",
"created_at": "2023-10-16T08:45:26.241Z",
"updated_at": "2023-10-16T08:45:26.241Z",
"description": "Continuously fetch the latest Slack messages. Details: full refresh. Required scopes(s): channels:read, groups:read, mpim:read, im:read"
}
],
"actions": [
{
"name": "github-list-repos-action",
"created_at": "2023-10-17T17:28:03.839Z",
"updated_at": "2023-10-17T17:28:03.839Z"
}
]
}
}
Create an integration
Create a new integration.await nango.createIntegration(<PROVIDER-ID>, <INTEGRATION-ID>);
Show child attributes
Show child attributes
Show child attributes
Show child attributes
{
"config": {
"unique_key": "slack-nango-community",
"provider": "slack"
}
}
Update an integration
Edits an integration (only for OAuth APIs).await nango.updateIntegration(<PROVIDER-ID>, <INTEGRATION-ID>);
Show child attributes
Show child attributes
Show child attributes
Show child attributes
{
"config": {
"unique_key": "slack-nango-community",
"provider": "slack"
}
}
Delete an integration
Deletes a specific integration.await nango.deleteIntegration(<INTEGRATION-ID>);
Show child attributes
Show child attributes
Show child attributes
Show child attributes
{
"config": {
"unique_key": "slack-nango-community",
"provider": "slack"
}
}
Connections
List connections
Returns a list of connections without credentials.await nango.listConnections();
Show child attributes
Show child attributes
Show child attributes
Show child attributes
{
"connections": [
{
"id": 1,
"connection_id": "test-1",
"provider": "slack",
"provider_config_key": "slack-nango-community",
"created": "2023-06-03T14:53:22.051Z",
"metadata": null
},
{
"id": 2,
"connection_id": "test-2",
"provider": "slack",
"provider_config_key": "slack-nango-community",
"created": "2023-06-03T15:00:14.945Z",
"metadata": {
"bot_id": "some-uuid"
}
}
]
}
Get a connection (with credentials)
Returns a specific connection with credentials.await nango.getConnection();
Show child attributes
Show child attributes
false. If false, the token will only be refreshed if it expires within 15 minutes. If true, a token refresh attempt will happen on each request. This is only useful for testing and should not be done at high traffic.false. If false, the refresh token is not included in the response, otherwise it is. In production, it is not advised to return the refresh token, for security reasons, since only the access token is needed to sign requests.Show child attributes
Show child attributes
{
"id": 18393,
"created_at": "2023-03-08T09:43:03.725Z",
"updated_at": "2023-03-08T09:43:03.725Z",
"provider_config_key": "github",
"connection_id": "1",
"credentials": {
"type": "OAUTH2",
"access_token": "gho_tsXLG73f....",
"refresh_token": "gho_fjofu84u9....",
"expires_at": "2024-03-08T09:43:03.725Z",
"raw": { // Raw token response from the OAuth provider: Contents vary!
"access_token": "gho_tsXLG73f....",
"refresh_token": "gho_fjofu84u9....",
"token_type": "bearer",
"scope": "public_repo,user"
}
},
"connection_config": {
"subdomain": "myshop",
"realmId": "XXXXX",
"instance_id": "YYYYYYY"
},
"account_id": 0,
"metadata": {
"myProperty": "yes",
"filter": "closed=true"
}
}
Get connection metadata
Returns a connection’s metadata.await nango.getMetadata('<INTEGRATION-ID>', 'CONNECTION-ID');
interface CustomMetadata {
anyKey: Record<string, string>;
}
const myTypedMetadata = await nango.getMetadata<CustomMetadata>('<INTEGRATION-ID>', '<CONNECTION-ID>');
Show child attributes
Show child attributes
Show child attributes
Show child attributes
{
"custom_key1": "custom_value1"
}
Set connection metadata
Set custom metadata for the connection (overrides existing metadata).await nango.setMetadata('<INTEGRATION-ID>', 'CONNECTION-ID', { 'CUSTOM_KEY1': 'CUSTOM_VALUE1' });
Show child attributes
Show child attributes
Edit connection metadata
Edit custom metadata for the connection. Only overrides specified properties, not the entire metadata.await nango.updateMetadata('<INTEGRATION-ID>', 'CONNECTION-ID', { 'CUSTOM_KEY1': 'CUSTOM_VALUE1' });
Show child attributes
Show child attributes
Delete a connection
Deletes a specific connection.await nango.deleteConnection('<INTEGRATION-ID>', 'CONNECTION-ID');
Show child attributes
Show child attributes
Scripts
Get scripts config
Return the configuration for all scriptsconst scriptsConfig = await nango.getScriptsConfig();
Show child attributes
Show child attributes
[
{
"providerConfigKey": "demo-github-integration",
"syncs": [
{
"name": "github-issue-example",
"type": "sync",
"models": [
{
"name": "GithubIssue",
"fields": [
{
"name": "id",
"type": "integer"
},
{
"name": "owner",
"type": "string"
},
{
"name": "repo",
"type": "string"
},
{
"name": "issue_number",
"type": "number"
},
{
"name": "title",
"type": "string"
},
{
"name": "author",
"type": "string"
},
{
"name": "author_id",
"type": "string"
},
{
"name": "state",
"type": "string"
},
{
"name": "date_created",
"type": "date"
},
{
"name": "date_last_modified",
"type": "date"
},
{
"name": "body",
"type": "string"
}
]
}
],
"sync_type": "FULL",
"runs": "every half hour",
"track_deletes": false,
"auto_start": false,
"last_deployed": "2024-02-28T20:16:38.052Z",
"is_public": false,
"pre_built": false,
"version": "4",
"attributes": {},
"input": {},
"returns": [
"GithubIssue"
],
"description": "Fetches the Github issues from all a user's repositories.\nDetails: full sync, doesn't track deletes, metadata is not required.\n",
"scopes": [
"public_repo"
],
"endpoints": [
{
"GET": "/github/issue-example"
}
],
"nango_yaml_version": "v2",
"webhookSubscriptions": []
}
],
"actions": [
{
"name": "fetch-issues",
"type": "action",
"models": [
{
"name": "GithubIssue",
"fields": [
{
"name": "id",
"type": "integer"
},
{
"name": "owner",
"type": "string"
},
{
"name": "repo",
"type": "string"
},
{
"name": "issue_number",
"type": "number"
},
{
"name": "title",
"type": "string"
},
{
"name": "author",
"type": "string"
},
{
"name": "author_id",
"type": "string"
},
{
"name": "state",
"type": "string"
},
{
"name": "date_created",
"type": "date"
},
{
"name": "date_last_modified",
"type": "date"
},
{
"name": "body",
"type": "string"
}
]
}
],
"runs": "",
"is_public": false,
"pre_built": false,
"version": "4",
"last_deployed": "2024-02-28T20:16:38.052Z",
"attributes": {},
"returns": [
"GithubIssue"
],
"description": "",
"scopes": [],
"input": {},
"endpoints": [
{
"GET": "/github/issues"
}
],
"nango_yaml_version": "v2"
}
],
"postConnectionScripts": [],
"provider": "github"
}
]
Syncs
Get records
Returns the synced data.import type { ModelName } from '<path-to-nango-integrations>/models'
const records = await nango.listRecords<ModelName>({
providerConfigKey: '<INTEGRATION-ID>',
connectionId: '<CONNECTION-ID>',
model: '<MODEL-NAME>'
});
nango.getRecords() is deprecated and will be removed in future releases as it does not support efficient pagination. Please use nango.listRecords() detailed below.Show child attributes
Show child attributes
Hide config
Hide config
_nango_metadata.cursor.Save the last fetched record’s cursor to track how far you’ve synced.By providing the cursor to this method, you’ll continue syncing from where you left off, receiving only post-cursor changes.This same cursor is used to paginate through the results of this endpoint.Show child attributes
Show child attributes
{
records:
[
{
id: 123,
..., // Fields as specified in the model you queried
_nango_metadata: {
deleted_at: null,
last_action: 'ADDED',
first_seen_at: '2023-09-18T15:20:35.941305+00:00',
last_modified_at: '2023-09-18T15:20:35.941305+00:00',
cursor: 'MjAyNC0wMi0yNlQwMzowMDozOS42MjMzODgtMDU6MDB8fGVlMDYwM2E1LTEwNDktNDA4Zi05YTEwLTJjNzVmNDkwODNjYQ=='
}
},
...
],
next_cursor: "Y3JlYXRlZF9hdF4yMDIzLTExLTE3VDExOjQ3OjE0LjQ0NyswMjowMHxpZF4xYTE2MTYwMS0yMzk5LTQ4MzYtYWFiMi1mNjk1ZWI2YTZhYzI"
}
Trigger sync(s)
Triggers an additional, one-off execution of specified sync(s) for a given connection or all applicable connections if no connection is specified.const records = await nango.triggerSync('<INTEGRATION-ID>', ['SYNC_NAME1', 'SYNC_NAME2'], '<CONNECTION_ID>');
Show child attributes
Show child attributes
Start schedule for sync(s)
Starts the schedule of specified sync(s) for a given connection or all applicable connections if no connection is specified.await nango.startSync('<INTEGRATION-ID>', ['SYNC_NAME1', 'SYNC_NAME2'], '<CONNECTION_ID>')
Show child attributes
Show child attributes
Pause schedule for sync(s)
Pauses the schedule of specified sync(s) for a given connection or all applicable connections if no connection is specified.await nango.startSync('<INTEGRATION-ID>', ['SYNC_NAME1', 'SYNC_NAME2'], '<CONNECTION_ID>')
Show child attributes
Show child attributes
Sync status
Get the status of specified sync(s) for a given connection or all applicable connections if no connection is specified.await nango.syncStatus('<INTEGRATION-ID>', ['SYNC_NAME1', 'SYNC_NAME2'], '<CONNECTION_ID>')
Show child attributes
Show child attributes
Show child attributes
Show child attributes
{
"syncs": [
{
"id": "<string>",
"name": "<string>",
"status": "RUNNING",
"type": "INCREMENTAL",
"finishedAt": "<string>",
"nextScheduledSyncAt": "<string>",
"frequency": "<string>",
"latestResult": {}
}
]
}
Override sync connection frequency
Override a sync’s default frequency for a specific connection, or revert to the default frequency.await nango.updateSyncConnectionFrequency('<INTEGRATION-ID>', 'SYNC_NAME', '<CONNECTION_ID>', '<FREQUENCY>')
Show child attributes
Show child attributes
Show child attributes
Show child attributes
{
"frequency": "<string>"
}
Get environment variables
Retrieve the environment variables as added in the Nango dashboard.await nango.getEnvironmentVariables();
Show child attributes
Show child attributes
[
{
"name": "MY_SECRET_KEY",
"value": "SK_373892NSHFNCOWFO..."
}
]
Actions
Trigger an action
Triggers an action for a connection.await nango.triggerAction('<INTEGRATION-ID>', '<CONNECTION_ID>', '<ACTION-NAME>', { 'custom_key1': 'custom_value1' });
Show child attributes
Show child attributes
Show child attributes
Show child attributes
{
"your-properties": "The data returned by the action"
}
Proxy
Proxy - GET requests
Triggers an action for a connection.const res = await nango.get({
endpoint: '/endpoint',
providerConfigKey: '<INTEGRATION-ID>',
connectionId: '<CONNECTION-ID>',
baseUrlOverride: 'https://base-url.com'
});
Show child attributes
Show child attributes
Hide config
Hide config
Show child attributes
Show child attributes
- response code
- response headers
- response body
Proxy - POST requests
Triggers an action for a connection.const res = await nango.post({
endpoint: '/endpoint',
providerConfigKey: '<INTEGRATION-ID>',
connectionId: '<CONNECTION-ID>',
baseUrlOverride: 'https://base-url.com'
});
Show child attributes
Show child attributes
Hide config
Hide config
Show child attributes
Show child attributes
- response code
- response headers
- response body
Proxy - PUT requests
Triggers an action for a connection.const res = await nango.put({
endpoint: '/endpoint',
providerConfigKey: '<INTEGRATION-ID>',
connectionId: '<CONNECTION-ID>',
baseUrlOverride: 'https://base-url.com'
});
Show child attributes
Show child attributes
Hide config
Hide config
Show child attributes
Show child attributes
- response code
- response headers
- response body
Proxy - PATCH requests
Triggers an action for a connection.const res = await nango.patch({
endpoint: '/endpoint',
providerConfigKey: '<INTEGRATION-ID>',
connectionId: '<CONNECTION-ID>',
baseUrlOverride: 'https://base-url.com'
});
Show child attributes
Show child attributes
Hide config
Hide config
Show child attributes
Show child attributes
- response code
- response headers
- response body
Proxy - DELETE requests
Triggers an action for a connection.const res = await nango.delete({
endpoint: '/endpoint',
providerConfigKey: '<INTEGRATION-ID>',
connectionId: '<CONNECTION-ID>',
baseUrlOverride: 'https://base-url.com'
});
Show child attributes
Show child attributes
Hide config
Hide config
Show child attributes
Show child attributes
- response code
- response headers
- response body