How Can I Trigger Syncs Manually Using the REST API for Custom Scheduling?
Question
How can I use the Fivetran REST API to manually sync a connection and determine when the sync has completed from the command line? I want to do this to run my connection on a custom schedule with cron.
Answer
We recommend that you use the scripting language of your choice to call the Fivetran REST API to manually sync the connection and then poll our API for a completion status.
Find the connection ID for your connection.
Use the Update Connection endpoint to switch your connector's
schedule_type
tomanual
:PATCH https://api.fivetran.com/v1/connections/{connection_id}
{ "schedule_type": "manual", "run_setup_tests": false }
Use the Sync Connection Data endpoint request to force a sync of your connector:
POST https://api.fivetran.com/v1/connections/{connection_id}/sync
{ "force": true }
NOTE: Using the
"force": true
payload parameter in the request stops a sync that is in progress. If you don't want to stop a current sync, leave the payload empty.Do either of the following:
Use the Retrieve Connection Details endpoint request to check the status of the connector:
GET https://api.fivetran.com/v1/connections/{your_connection_id}
Create a group webhook and configure it to send the
sync_end
event.
Considerations:
Using polling, you will know whether a sync has completed but not necessarily get an accurate estimate of how long the sync actually took. Polling adds some time value, which may be as large as your polling frequency interval, to that estimate.
IMPORTANT: If you set the sync scheduling for your connection to
manual
, you need to manually trigger your syncs after you make this change. If a manually-triggered sync wasrescheduled
, you need to manually re-trigger that sync, since sync rescheduling only works with automatic sync scheduling.