<@U04S8PLJWMT> how do I know when sync is complete...
# ask-ai
t
@kapa.ai how do I know when sync is complete using API?
k
To determine when a sync is complete using the Airbyte API, you should: 1. Trigger a sync job using the API (for example, by POSTing to
/jobs
with the appropriate
connectionId
and
jobType
). 2. Monitor the job status by polling the job status endpoint (
GET /jobs/{jobId}
) at intervals. A sync is considered complete when the job status is one of the terminal states:
succeeded
,
failed
,
incomplete
, or
cancelled
. The status
running
means the sync is still in progress. Here’s a simplified workflow: 1. Trigger the sync and get the jobId:
Copy code
csharp     var client = new RestClient("https://api.airbyte.com/v1/jobs");     var request = new RestRequest();     request.AddHeader("accept", "application/json");     request.AddHeader("content-type", "application/json");     request.AddHeader("Authorization", "Bearer {YourApiKey}");     request.AddParameter("application/json", "{\"connectionId\":\"YourConnectionID\",\"jobType\":\"sync\"}", ParameterType.RequestBody);     dynamic response = client.ExecutePost(request);     string jobId = response.jobId;
2. Poll the job status:
Copy code
csharp     string jobStatus = response.status;     while(jobStatus == "running")     {         client = new RestClient("https://api.airbyte.com/v1/jobs/" + jobId);         request = new RestRequest();         request.AddHeader("accept", "application/json");         request.AddHeader("content-type", "application/json");         request.AddHeader("Authorization", "Bearer {YourApiKey}");         dynamic statusResponse = client.ExecuteGet(request);         jobStatus = statusResponse.status;         Thread.Sleep(10000); // Wait 10 seconds before checking again     }     // At this point, jobStatus is no longer "running" and the sync is complete
The job status values you should check for are:
pending
,
running
,
incomplete
,
failed
,
succeeded
, and
cancelled
. When the status is no longer
running
, the sync is complete and you can check the final status to determine if it succeeded or failed [Create and Monitor a Data Pipeline Using the Airbyte API](https://airbyte.com/tutorials/create-and-monitor-a-data-pipeline-using-the-airbyte-api), [Airbyte Public API - Jobs](https://raw.githubusercontent.com/airbytehq/airbyte-platform/f284238f0099c4c0a3542d4c42a88773c45c363d/airbyte-api/src/main/openapi/api.yaml).