Creating a RapidBridge sync job
Build a sync job that sends Zendesk users, contacts, tickets and each ticket's comments to your webhook, run it, then make it incremental and put it on a schedule.
Skip the reading — fast path for coding agents
truto sync-job-runs create --sync-job-id <sync_job_id> --integrated-account-id <integrated_account_id> --webhook-id <webhook_id>
/skill truto-operator
The sync job definitions in this guide use the resource format of sync job runtime versions 1 to 3. A sync job created through the API without default_runtime_version runs on version 3. For new jobs, use version 4; see the V4 sync job reference.
Creating a webhook
A sync job run needs a webhook to send its records to. Create one that subscribes to the events this guide uses:
curl -X POST https://api.truto.one/webhook \
-H "Authorization: Bearer <API token>" \
-H "Content-Type: application/json" \
-d '{
"target_url": "https://webhook.site/6a7cc86e-9286-4be8-ba79-bcd8dfdbeee1",
"is_active": true,
"event_types": [
"sync_job_run:created",
"sync_job_run:updated",
"sync_job_run:started",
"sync_job_run:completed",
"sync_job_run:failed",
"sync_job_run:deleted",
"sync_job_run:record",
"sync_job_run:record_error",
"sync_job_run:rate_limited",
"sync_job_cron_trigger:failed",
"integrated_account:created",
"integrated_account:active",
"integrated_account:post_connect_form_submitted"
]
}'truto webhooks create -b '{
"target_url": "https://webhook.site/6a7cc86e-9286-4be8-ba79-bcd8dfdbeee1",
"is_active": true,
"event_types": [
"sync_job_run:created",
"sync_job_run:updated",
"sync_job_run:started",
"sync_job_run:completed",
"sync_job_run:failed",
"sync_job_run:deleted",
"sync_job_run:record",
"sync_job_run:record_error",
"sync_job_run:rate_limited",
"sync_job_cron_trigger:failed",
"integrated_account:created",
"integrated_account:active",
"integrated_account:post_connect_form_submitted"
]
}'You can also follow our more detailed guide to creating webhooks.
Creating a sync job
In this guide, we'll be syncing users, contacts, tickets and comments for each ticket from Zendesk using the Unified API for Ticketing.
Create the sync job:
curl -X POST https://api.truto.one/sync-job \
-H "Authorization: Bearer <API token>" \
-H "Content-Type: application/json" \
-d '{
"integration_name": "zendesk",
"resources": [
{
"resource": "ticketing/users",
"method": "list"
},
{
"resource": "ticketing/contacts",
"method": "list"
},
{
"resource": "ticketing/tickets",
"method": "list"
},
{
"resource": "ticketing/comments",
"method": "list",
"depends_on": "ticketing/tickets",
"query": {
"ticket_id": "{{resources.ticketing.tickets.id}}"
}
}
]
}'truto sync-jobs create -b '{
"integration_name": "zendesk",
"resources": [
{ "resource": "ticketing/users", "method": "list" },
{ "resource": "ticketing/contacts", "method": "list" },
{ "resource": "ticketing/tickets", "method": "list" },
{
"resource": "ticketing/comments",
"method": "list",
"depends_on": "ticketing/tickets",
"query": { "ticket_id": "{{resources.ticketing.tickets.id}}" }
}
]
}'In the request above,
integration_nameis the identifier of the integration that the sync job is for. In this case Zendesk, so its value is set tozendesk.resourcesis the list of resources to fetch from Zendesk. Each item in the list has the following schema,resource(required) is the name of the Unified API resource or the Proxy API resource. For Unified APIs, use the formatunified_api_name/resource_nameand for the Proxy APIs, just useresource_name.method(required) can belistorgetfor Unified APIs. For Proxy APIs, it can belist,getor any other read-like custom method.depends_on(optional) creates a dependency between this resource and some other resource in theresourceslist. In the example above,ticketing/commentsresource needs aticket_idquery parameter to fetch the comments for, so we first fetch the list ofticketsand then for each ticket, we fetch thecomments.query(optional) are the query parameters to be passed to each request. Placeholders can be used to populate the query parameters dynamically, like in the example above,ticketing/commentsuses the{{resources.ticketing.tickets.id}}placeholder to refer to theidproperty of a Unified Ticket Resource and set it as theticket_id. Refer the placeholder reference section for more details on the placeholders that can be used.persist(optional) decides whether the records this resource fetches are sent to the run's destination. Unified API resources are sent unless you setpersisttofalse. Proxy API resources are sent only when you setpersisttotrue, so set it on every Proxy API resource whose records you want to receive.
Running a sync job
With the webhook and the sync job in place, start a sync job run.
You need a Zendesk integrated account; see Connecting an account. The account must be of the job's integration_name, or the run is refused with 400.
curl -X POST https://api.truto.one/sync-job-run \
-H "Authorization: Bearer <API token>" \
-H "Content-Type: application/json" \
-d '{
"sync_job_id": "7279a917-b447-4629-9e46-a1eeb791ad6b",
"integrated_account_id": "7ae7b0ab-c6a7-4f29-aec1-1f123517af5d",
"webhook_id": "a5b21886-3b4d-4fd0-9956-ffc0714d701c"
}'truto sync-job-runs create -b '{
"sync_job_id": "7279a917-b447-4629-9e46-a1eeb791ad6b",
"integrated_account_id": "7ae7b0ab-c6a7-4f29-aec1-1f123517af5d",
"webhook_id": "a5b21886-3b4d-4fd0-9956-ffc0714d701c"
}'The run starts, and your webhook starts receiving events.
In the request above,
sync_job_idis theidof the sync job we created in the previous stepintegrated_account_idis theidof the integrated account connected to a Zendesk accountwebhook_idis theidof the webhook created in the first step.
A run sends its records to exactly one destination. Pass one of webhook_id (a webhook), super_query or daemon_group_key (a daemon group). A request with none of them, or with more than one, returns 400.
A run no longer takes a datastore_id, and a request with one returns 400. To write records to a datastore, use a destination node on a runtime version 4 sync job.
Only one run at a time can work on the same sync job, integrated account and args. Starting a run while such a run is still created, running or otherwise not completed, failed or stopped returns 400 with truto_error_code set to sync_job_run_not_completed and the unfinished run's id in running_sync_job_runs. Wait for it to finish, or pass "force": true to start another run anyway.
curl -X POST https://api.truto.one/sync-job-run \
-H "Authorization: Bearer <API token>" \
-H "Content-Type: application/json" \
-d '{
"sync_job_id": "7279a917-b447-4629-9e46-a1eeb791ad6b",
"integrated_account_id": "7ae7b0ab-c6a7-4f29-aec1-1f123517af5d",
"webhook_id": "a5b21886-3b4d-4fd0-9956-ffc0714d701c",
"force": true
}'truto sync-job-runs create -b '{
"sync_job_id": "7279a917-b447-4629-9e46-a1eeb791ad6b",
"integrated_account_id": "7ae7b0ab-c6a7-4f29-aec1-1f123517af5d",
"webhook_id": "a5b21886-3b4d-4fd0-9956-ffc0714d701c",
"force": true
}'These rules apply to runtime versions 1 to 3, which this guide uses.
Error handling
Truto by default ignores any errors that occur during a sync job run and continues with the next resource, sending you sync_job_run:record_error webhook events for each error encountered. The error_handling attribute in the sync job run request controls this. It accepts ignore (the default), fail_fast, and batch.
fail_fastmakes the sync job run fail as soon as an error occurs. It applies only to runtime version 1. On other runtime versions the run continues past errors, as withignore.batchholds back thesync_job_run:record_errorevents until the end of the run and then sends them together, up to 100 errors per event, witherrorandmetaas arrays. It applies to runtime versions 2 and 3, and only to runs started with awebhook_id. On runtime version 1, or without awebhook_id, it behaves likeignore.
curl -X POST https://api.truto.one/sync-job-run \
-H "Authorization: Bearer <API token>" \
-H "Content-Type: application/json" \
-d '{
"sync_job_id": "7279a917-b447-4629-9e46-a1eeb791ad6b",
"integrated_account_id": "7ae7b0ab-c6a7-4f29-aec1-1f123517af5d",
"webhook_id": "a5b21886-3b4d-4fd0-9956-ffc0714d701c",
"error_handling": "batch"
}'truto sync-job-runs create -b '{
"sync_job_id": "7279a917-b447-4629-9e46-a1eeb791ad6b",
"integrated_account_id": "7ae7b0ab-c6a7-4f29-aec1-1f123517af5d",
"webhook_id": "a5b21886-3b4d-4fd0-9956-ffc0714d701c",
"error_handling": "batch"
}'Incremental syncing of data
By default, the sync job above will fetch all the objects for a resource in every sync job run, i.e. all the tickets will be synced on every sync job run. In most cases, an incremental way of syncing would be preferred, where only tickets that have changed from the time the previous sync job ran.
To do this, updated_at query parameter of the ticketing/tickets Unified API resource can be used, bound to previous_run_date. The binding can be created like so,
{
"resource": "ticketing/tickets",
"method": "list",
"query": {
"updated_at": {
"gt": "{{previous_run_date}}"
}
}
}previous_run_date is a special attribute tracked by Truto. It holds the start time of the latest sync job run that completed successfully for the sync job and a particular integrated account. It's set to '1970-01-01T00:00:00.000Z' on the very first sync job run.
A run can complete even when some of its requests failed: each failure sends sync_job_run:record_error, and the run carries on without that resource's later pages. previous_run_date still moves to that run's start, so the next run skips records the failed requests would have fetched.
The previous sync job can be updated with the new resource binding. Send the full resources list, since it replaces the existing one,
curl -X PATCH https://api.truto.one/sync-job/7279a917-b447-4629-9e46-a1eeb791ad6b \
-H "Authorization: Bearer <API token>" \
-H "Content-Type: application/json" \
-d '{
"resources": [
{
"resource": "ticketing/users",
"method": "list"
},
{
"resource": "ticketing/contacts",
"method": "list"
},
{
"resource": "ticketing/tickets",
"method": "list",
"query": {
"updated_at": {
"gt": "{{previous_run_date}}"
}
}
},
{
"resource": "ticketing/comments",
"method": "list",
"depends_on": "ticketing/tickets",
"query": {
"ticket_id": "{{resources.ticketing.tickets.id}}"
}
}
]
}'truto sync-jobs update 7279a917-b447-4629-9e46-a1eeb791ad6b -b '{
"resources": [
{ "resource": "ticketing/users", "method": "list" },
{ "resource": "ticketing/contacts", "method": "list" },
{
"resource": "ticketing/tickets",
"method": "list",
"query": { "updated_at": { "gt": "{{previous_run_date}}" } }
},
{
"resource": "ticketing/comments",
"method": "list",
"depends_on": "ticketing/tickets",
"query": { "ticket_id": "{{resources.ticketing.tickets.id}}" }
}
]
}'Now, every time the sync job executes, it will fetch only the tickets which have been changed since the last sync job run.
Doing a full sync on demand
Sometimes you want to fully sync the data and just ignore the previous_run_date. It's possible to do it using ignore_previous_run attribute set to true in the sync job run request.
curl -X POST https://api.truto.one/sync-job-run \
-H "Authorization: Bearer <API token>" \
-H "Content-Type: application/json" \
-d '{
"sync_job_id": "7279a917-b447-4629-9e46-a1eeb791ad6b",
"integrated_account_id": "7ae7b0ab-c6a7-4f29-aec1-1f123517af5d",
"webhook_id": "a5b21886-3b4d-4fd0-9956-ffc0714d701c",
"ignore_previous_run": true
}'truto sync-job-runs create -b '{
"sync_job_id": "7279a917-b447-4629-9e46-a1eeb791ad6b",
"integrated_account_id": "7ae7b0ab-c6a7-4f29-aec1-1f123517af5d",
"webhook_id": "a5b21886-3b4d-4fd0-9956-ffc0714d701c",
"ignore_previous_run": true
}'Running a sync job on schedule
The cron expression is in UTC timezone. Runs must be at least 5 minutes apart.
To run a sync job on a recurring schedule, create a sync job cron trigger:
curl -X POST https://api.truto.one/sync-job-cron-trigger \
-H "Authorization: Bearer <API token>" \
-H "Content-Type: application/json" \
-d '{
"sync_job_id": "d7fd45d6-136a-4244-aeb9-b6439bfa8b71",
"integrated_account_id": "6680c7ff-9f0e-45be-9915-a7334dc37f23",
"webhook_id": "a5b21886-3b4d-4fd0-9956-ffc0714d701c",
"cron_expression": "0 */6 * * *"
}'truto sync-job-triggers create -b '{
"sync_job_id": "d7fd45d6-136a-4244-aeb9-b6439bfa8b71",
"integrated_account_id": "6680c7ff-9f0e-45be-9915-a7334dc37f23",
"webhook_id": "a5b21886-3b4d-4fd0-9956-ffc0714d701c",
"cron_expression": "0 */6 * * *"
}'The body takes the same fields as a sync job run, plus cron_expression and is_active, except force, ignore_previous_run, delay_between_requests_ms and version, which a trigger drops without an error. A datastore_id is refused with 400, as on a run. The cron expression above runs the sync job every 6 hours.
When the trigger is saved, Truto checks the gap between its next two runs. If the gap is under 5 minutes, as with */2 * * * *, or the expression doesn't parse, the request is rejected with a 400 that says why, and no trigger is saved.
To pause a trigger without deleting it, set is_active to false:
curl -X PATCH https://api.truto.one/sync-job-cron-trigger/<trigger_id> \
-H "Authorization: Bearer <API token>" \
-H "Content-Type: application/json" \
-d '{ "is_active": false }'truto sync-job-triggers update <trigger_id> -b '{ "is_active": false }'While the trigger is inactive, its scheduled times create no sync job run and send no webhook events. Set is_active back to true to resume it. It runs again at its next scheduled time. A trigger created with "is_active": false is saved without being scheduled, and starts running once you set it to true.
Passing arguments to a sync job
Arguments can be passed to a sync job run to fetch data dynamically. Imagine if in the example above, we needed to fetch tickets incrementally based on the previous sync job run date, but also based on a date of our choosing for the initial sync.
Declare the arguments in the sync job's args_schema so the dashboard's Trigger run form shows them; the API passes args through either way.
{
"args_schema": {
"ticket_sync_start_date": {
"type": "string",
"format": "date-time"
}
}
}Next, we use this argument in the ticketing/tickets resource like so, but instead of the normal variable binding, a JSONata expression is used for query. The JSONata expression is like so,
{
'updated_at': {
'gt': args.ticket_sync_start_date ? args.ticket_sync_start_date : previous_run_date
}
}The expression above uses ticket_sync_start_date from the arguments if it's passed or falls back to previous_run_date.
Conditional placeholders can achieve the same result without the need for JSONata expressions. You'd still need JSONata expressions for more complex scenarios.
{
"updated_at": {
"gt": "{{args.ticket_sync_start_date|previous_run_date}}"
}
}The updated resource definition looks like so,
{
"resource": "ticketing/tickets",
"method": "list",
"query": "{ 'updated_at': { 'gt': args.ticket_sync_start_date ? args.ticket_sync_start_date : previous_run_date } }"
}The final request to create a sync job with arguments,
curl -X POST https://api.truto.one/sync-job \
-H "Authorization: Bearer <API token>" \
-H "Content-Type: application/json" \
-d '{
"integration_name": "zendesk",
"args_schema": {
"ticket_sync_start_date": {
"type": "string",
"format": "date-time"
}
},
"resources": [
{
"resource": "ticketing/users",
"method": "list"
},
{
"resource": "ticketing/contacts",
"method": "list"
},
{
"resource": "ticketing/tickets",
"method": "list",
"query": "{ '\''updated_at'\'': { '\''gt'\'': args.ticket_sync_start_date ? args.ticket_sync_start_date : previous_run_date } }"
},
{
"resource": "ticketing/comments",
"method": "list",
"depends_on": "ticketing/tickets",
"query": {
"ticket_id": "{{resources.ticketing.tickets.id}}"
}
}
]
}'truto sync-jobs create -b '{
"integration_name": "zendesk",
"args_schema": {
"ticket_sync_start_date": { "type": "string", "format": "date-time" }
},
"resources": [
{ "resource": "ticketing/users", "method": "list" },
{ "resource": "ticketing/contacts", "method": "list" },
{
"resource": "ticketing/tickets",
"method": "list",
"query": "{ '\''updated_at'\'': { '\''gt'\'': args.ticket_sync_start_date ? args.ticket_sync_start_date : previous_run_date } }"
},
{
"resource": "ticketing/comments",
"method": "list",
"depends_on": "ticketing/tickets",
"query": { "ticket_id": "{{resources.ticketing.tickets.id}}" }
}
]
}'To run a sync job with arguments, add the args attribute to the request body,
{
"args": {
"ticket_sync_start_date": "2023-07-23T18:10:56.072Z"
}
}The request would be,
curl -X POST https://api.truto.one/sync-job-run \
-H "Authorization: Bearer <API token>" \
-H "Content-Type: application/json" \
-d '{
"args": {
"ticket_sync_start_date": "2023-07-23T18:10:56.072Z"
},
"sync_job_id": "7279a917-b447-4629-9e46-a1eeb791ad6b",
"integrated_account_id": "7ae7b0ab-c6a7-4f29-aec1-1f123517af5d",
"webhook_id": "a5b21886-3b4d-4fd0-9956-ffc0714d701c"
}'truto sync-job-runs create -b '{
"args": { "ticket_sync_start_date": "2023-07-23T18:10:56.072Z" },
"sync_job_id": "7279a917-b447-4629-9e46-a1eeb791ad6b",
"integrated_account_id": "7ae7b0ab-c6a7-4f29-aec1-1f123517af5d",
"webhook_id": "a5b21886-3b4d-4fd0-9956-ffc0714d701c"
}'Looping a request over an array
Taking the arguments example forward, imagine a hypothetical scenario where we need to fetch a specific set of tickets based on a list of ticket ids. This can be achieved using the loop_on attribute on the resource.
To create such a sync job, we first need to define the args_schema like so,
{
"args_schema": {
"ticket_ids": {
"type": "array",
"items": {
"type": "string"
}
}
}
}Then define the ticketing/tickets resource like so,
{
"resource": "ticketing/tickets",
"method": "get",
"loop_on": "args.ticket_ids",
"id": "{{args.ticket_ids}}"
}Here, the loop_on attribute specifies that for each element in the ticket_ids array, a request should be made. The id attribute specifies the placeholder to be used for the id of the ticket.
Complete request to create a sync job with looping,
curl -X POST https://api.truto.one/sync-job \
-H "Authorization: Bearer <API token>" \
-H "Content-Type: application/json" \
-d '{
"integration_name": "zendesk",
"args_schema": {
"ticket_ids": {
"type": "array",
"items": {
"type": "string"
}
}
},
"resources": [
{
"resource": "ticketing/tickets",
"method": "get",
"loop_on": "args.ticket_ids",
"id": "{{args.ticket_ids}}"
}
]
}'truto sync-jobs create -b '{
"integration_name": "zendesk",
"args_schema": {
"ticket_ids": { "type": "array", "items": { "type": "string" } }
},
"resources": [
{
"resource": "ticketing/tickets",
"method": "get",
"loop_on": "args.ticket_ids",
"id": "{{args.ticket_ids}}"
}
]
}'Recursively fetching data for the same resource
There are cases where you might need to fetch data for the same resource, where the resources might have a parent-child relationship. For example, in drive-items for the Unified File Storage API, there could be drive items of the type folder which might have child drive items within them. To fetch such resources, you can use the recurse attribute in the sync job resource,
{
"resource": "file-storage/drive-items",
"method": "list",
"recurse": {
"if": "{{resources.file-storage.drive-items.has_children:bool}}",
"config": {
"query": {
"parent": {
"id": "{{resources.file-storage.drive-items.id}}"
}
}
}
}
}In the above example, we set the recurse condition in the if attribute. Most of the resources which follow this parent-child relation have a has_children attribute which is a boolean (you'll need to check the documentation to make sure). If the has_children attribute is true, then the config attribute will be used to fetch the child resources. The query attribute in the config specifies the query parameters to be passed to the request. The parent.id is set to the id of the parent resource. You can use placeholders to refer to the values of other fields.
Running a sync job after an integrated account is connected
To run a sync job after an integrated account is connected, listen to the integrated_account:active event. This event is sent when an integrated account is created and is ready to be used. If you have a RapidForm configured for the integration, then you'll need to listen to the integrated_account:post_connect_form_submitted event.
An example webhook event for both is shown below. The payload has more fields than the three shown here.
{
"id": "bed2145c-46d7-41fa-ad69-3e70cb5bb74d",
"event": "integrated_account:active",
"payload": {
"id": "937fed13-712d-4647-dfe3-7613948b0348",
"tenant_id": "acme-1",
"environment_integration_id": "f7d82f6d-20f0-4bed-231c-d9c31e023710"
},
"environment_id": "ac15abdc-b38e-47d0-97a2-6f494017c177",
"created_at": "2023-08-31T18:08:27.879Z",
"webhook_id": "a5b21886-3b4d-4fd0-9956-ffc0714d701c"
}The sync job run can be scheduled or executed immediately after receiving the webhook event by using the payload.id attribute as the integrated_account_id in the sync job run request.
# integrated_account_id is payload.id from the webhook event
curl -X POST https://api.truto.one/sync-job-run \
-H "Authorization: Bearer <API token>" \
-H "Content-Type: application/json" \
-d '{
"sync_job_id": "7279a917-b447-4629-9e46-a1eeb791ad6b",
"integrated_account_id": "937fed13-712d-4647-dfe3-7613948b0348",
"webhook_id": "a5b21886-3b4d-4fd0-9956-ffc0714d701c"
}'# integrated_account_id is payload.id from the webhook event
truto sync-job-runs create -b '{
"sync_job_id": "7279a917-b447-4629-9e46-a1eeb791ad6b",
"integrated_account_id": "937fed13-712d-4647-dfe3-7613948b0348",
"webhook_id": "a5b21886-3b4d-4fd0-9956-ffc0714d701c"
}'Reference
Transforming the data fetched by the resources
Sometimes you might need to transform the data fetched by the resources before sending it to the webhook. This can be achieved using the transform nodes in the sync job.
Transform nodes accept a JSONata expression which should return the final result to be sent to the webhook. These nodes are always dependent on a resource node (using depends_on), so you can't have an independent transform node. Also, the resource node which the transform nodes depend on should have a name attribute and the transform node itself should have a name attribute. You can also have transform nodes dependent on another transform node, and resource nodes dependent on transform nodes.
Some use cases where the transform nodes are especially helpful --
- Filtering out the data fetched by the resource -- When the underlying API doesn't support the filters you need, like updated_at, tags, etc., you can use the transform nodes to filter out the data.
- Modifying the output of the resource without modifying the Unified mappings -- You might need to modify the output of the resource before sending it to the webhook, like adding a new field, modifying the existing fields, etc.
This is the context object available for the JSONata expressions in the transform nodes,
args- The arguments passed to the sync job run.resources.<resource path>- Contains the data fetched by the resource, keyed by itsresourcevalue split on/. For example, the data ofticketing/contactsis atresources.ticketing.contacts.previous_run_date- Refers to the start time of the latest sync job run that completed successfully for the sync job and an integrated account. It's set to '1970-01-01T00:00:00.000Z' on the very first sync job run.resource- Refers to the parent resource's attributes defined in the sync job with placeholders resolved.<all_context_variables>- Refers to the context variables set in the integrated account.
Taking the example from Zendesk, this sync job ignores the contacts NOT updated from the last time the sync job ran. Both nodes have a name, and the transform's depends_on refers to the resource node by that name:
{
"integration_name": "zendesk",
"args_schema": {},
"resources": [
{
"name": "all-contacts",
"resource": "ticketing/contacts",
"method": "list",
"persist": false
},
{
"name": "filtered-contacts",
"type": "transform",
"config": {
"expression": "resources.ticketing.contacts[updated_at >= %.%.%.previous_run_date]"
},
"depends_on": "all-contacts",
"persist": true
}
]
}To make sure that you only get the filtered contacts on the webhook in the example above, persist has been set to true for the transform node and false for all the contacts.
Transform nodes need to have the persist attribute set to true if you need their output to be sent to the webhook. By default, it's set to false.
If the resource name contains special characters apart from underscore _, like -, then in JSONata you need to refer to them using backticks. For example, if the resource name is knowledge-base/page-content, then you need to refer to it as
resources.`knowledge-base`.`page-content`in JSONata.
Spooling data into a single webhook event
Spool nodes allow you to paginate and fetch the complete resource and then send it in a single webhook event. One of the places where this is useful is in the Knowledge Base APIs where the page content might be split into multiple blocks and is provided through a paginated API. You can use the spool nodes to fetch all the blocks and then send them in a single webhook event. You can also have transform nodes dependent on spool nodes, which can transform the data fetched by the spool nodes.
As with transform nodes, spool nodes can't be independent: each depends on a resource node or a transform node. The node which the spool nodes depend on should have a name attribute and the spool node itself should have a name attribute. You can't have a spool node dependent on another spool node.
Taking the example of a Notion integration, where we need the content of a Notion page as a markdown,
{
"integration_name": "notion",
"args_schema": {
"page_id": {
"type": "string",
"required": true
}
},
"resources": [
{
"name": "page-content",
"resource": "knowledge-base/page-content",
"method": "list",
"query": {
"page": {
"id": "{{args.page_id}}"
},
"truto_ignore_remote_data": true
},
"recurse": {
"if": "{{resources.knowledge-base.page-content.has_children:bool}}",
"config": {
"query": {
"page_content_id": "{{resources.knowledge-base.page-content.id}}"
}
}
},
"persist": false
},
{
"name": "remove-remote-data",
"type": "transform",
"config": {
"expression": "[resources.`knowledge-base`.`page-content`.$sift(function($v, $k) {$k != 'remote_data'})]"
},
"depends_on": "page-content"
},
{
"name": "all-page-content",
"type": "spool",
"depends_on": "remove-remote-data"
},
{
"name": "combine-page-content",
"type": "transform",
"config": {
"expression": "$blob($reduce($sortNodes(resources.`knowledge-base`.`page-content`, 'id', 'parent.id'), function($acc, $v) { $acc & $v.body.content }, ''), { \"type\": \"text/markdown\" })"
},
"depends_on": "all-page-content",
"persist": true
}
]
}In the example above,
- We first fetch the page-content blocks for the page provided in the argument. While the pages are fetched, the
recurselogic fetches the child blocks of every block that has any. - Each fetched page goes through the
remove-remote-datatransform node, which removes theremote_dataattribute from its blocks. - The
all-page-contentspool node collects the blocks from every page and passes them on once all of them have been fetched. - Finally, the
combine-page-contenttransform node combines all the blocks collected by theall-page-contentspool node and sends them as onesync_job_run:recordevent: atext/markdownfile in amultipart/form-databody.
In spool nodes, the data is stored temporarily on Truto's servers. Once the sync job run completes or fails, the data is deleted.
Limitations
The amount of data you can store in spool nodes is limited to 128KB, so make sure that the data you are fetching in each page falls within that limit. That is the reason why in the example above, we have a remove-remote-data transform node to remove the remote_data attribute from the fetched blocks, as it might contain a lot of data.
Placeholder Reference
Placeholders can be used in the sync job resources to refer to the values of other fields in the sync job. The placeholders are enclosed in double curly braces {{}}.
The placeholders available are,
{{args.<arg_name>}}- Refers to the value of the argument passed to the sync job run.{{resources.<resource_path>.<field_name>}}- Refers to the value of a field in a resource fetched in the sync job. Theresource_pathis the parent'sresourcevalue split on/, like{{resources.ticketing.tickets.id}}forticketing/tickets. Thefield_namecan be any field in the resource. This is only available when the resource is dependent on another resource using thedepends_onattribute.{{previous_run_date}}- Refers to the start time of the latest sync job run that completed successfully for the sync job and an integrated account. It's set to'1970-01-01T00:00:00.000Z'on the very first sync job run.{{truto_parent_resource.<attribute>}}- If usingdepends_on, then the parent resource's attributes can be accessed using this placeholder. For example, you could use the queries used in the parent resource by using{{truto_parent_resource.query.<query_name>}}. This can be useful for recurse use cases.{{truto_parent_resource.query.<parameter_name>}}{{truto_parent_resource.method}}{{truto_parent_resource.resource}}{{truto_parent_resource.id}}{{truto_parent_resource.body.<attribute_name>}}
{{<integrated_account_context_variable>}}- Refers to the value of a context variable set in the integrated account. For example, if you have a variable with namefooin the integrated account, you can refer to it using{{foo}}.
Next
Every request on this page is in the sync job API reference. For new jobs, use runtime version 4; see the V4 sync job reference. To manage jobs, runs and schedules in the dashboard, see Using the Sync Jobs UI.