Managing jobs in Management API#
This article documents how to list current jobs, list past jobs, obtain a status of jobs in progress, and how to stop jobs with the Management API.
Listing jobs#
Listing all jobs in an instance#
Use the API call documented in this section to list all currently running and scheduled jobs (for example, fetch jobs) in a whole instance.
To list all running and scheduled jobs, follow these steps:
Create a GET request to the following endpoint:
https://{{INSTANCE}}/api/jobs
In the HTTP request header, include the parameter
Authorizationwith one of the following values:Token {{KEY}}if you use a key generated with user credentials in Management API.Bearer {{KEY}}if you use a key generated in the Adverity user interface.
Send the request.
Import the request example as raw text to your HTTP client (such as Postman). The cURL request example is the following:
curl --location --request GET 'https://{{INSTANCE}}/api/jobs/' \
--header 'Authorization: Token {{KEY}}'
The response to this request includes the state_label parameter with
one of the following values assigned:
Scheduled
Running
Success
Cancelled
Failed
Discarded - this status is set in the following cases:
If a preceding job failed or was cancelled, the follow up jobs are discarded.
If a job does not start running within 2 days of the fetch start, it is discarded.
If a job is cancelled manually, it is discarded.
Stale - this status is not set currently. Generally, it can be used to label jobs that will not complete due to internal failures and lost or removed tasks.
The response of a fetch job also includes the user field:
Field |
Description |
|---|---|
|
The email of the user who triggered the fetch. This field is
|
Note
Adverity records the triggering user only for fetches triggered after this feature was released. Fetches triggered through the Management API before the release have no user recorded, and this information cannot be reconstructed retroactively.
Filtering the jobs#
You can filter the jobs returned from this endpoint with a number of parameters:
Parameter |
Value |
Description |
|---|---|---|
|
|
Use this parameter to list the jobs of a specific datastream. |
|
Dates |
Use these parameters to list the jobs within a specific date or time range. |
|
One of the options: |
Use this parameter to list the jobs of a specific type. |
|
An email address, for example |
Use this parameter to list only the jobs triggered by a specific user. |
|
|
Use this parameter to list only human-triggered jobs ( |
For example, to list the jobs of a datastream, import the following request example as raw text to your HTTP client (such as Postman):
curl --location -g --request GET 'https://{{INSTANCE}}/api/jobs/?datastream_id={{DATASTREAM_ID}}/' \
--header 'Authorization: Token {{KEY}}'
For example, to list the jobs within a given date range, import the following request example as raw text to your HTTP client (such as Postman):
curl --location -g --request GET 'https://{{INSTANCE}}/api/jobs/?start=YYYY-MM-DD&end=YYYY-MM-DD' \
--header 'Authorization: Token {{KEY}}'
For example, to list the jobs within a more specific time rangeby using timestamps, import the following request example as raw text to your HTTP client (such as Postman):
curl --location -g --request GET 'https://{{INSTANCE}}/api/jobs/?start=YYYY-MM-DDT00:00:00Z&end=YYYY-MM-DDT00:00:00Z' \
--header 'Authorization: Token {{KEY}}'
For example, to list the jobs of a certain type, for example Fetch, import the following request example as raw text to your HTTP client (such as Postman):
curl --location -g --request GET 'https://{{INSTANCE}}/api/jobs/?type=Fetch' \
--header 'Authorization: Token {{KEY}}'
For example, to list only the jobs triggered by a specific user, import the following request example as raw text to your HTTP client (such as Postman):
curl --location -g --request GET 'https://{{INSTANCE}}/api/jobs/?user=jane@doe.com' \
--header 'Authorization: Token {{KEY}}'
For example, to list only the jobs triggered by a person rather than by the system, import the following request example as raw text to your HTTP client (such as Postman):
curl --location -g --request GET 'https://{{INSTANCE}}/api/jobs/?triggered_by_user=true' \
--header 'Authorization: Token {{KEY}}'
Listing the fetch jobs of a specific datastream#
To list the fetch jobs of a single datastream, you can also use the
dedicated /api/datastreams/{{DATASTREAM_ID}}/jobs/ endpoint. This
endpoint returns a paginated list of the datastream’s fetch jobs,
ordered from the most recent to the oldest.
To list the fetch jobs of a datastream, follow these steps:
Create a GET request to the following endpoint:
https://{{INSTANCE}}/api/datastreams/{{DATASTREAM_ID}}/jobs/
Replace
{{DATASTREAM_ID}}with the datastream’s ID.In the HTTP request header, include the parameter
Authorizationwith one of the following values:Token {{KEY}}if you use a key generated with user credentials in Management API.Bearer {{KEY}}if you use a key generated in the Adverity user interface.
Send the request.
As a result, you obtain a paginated list of the datastream’s fetch jobs.
Import the request example as raw text to your HTTP client (such as Postman). The cURL request example is the following:
curl --location -g --request GET 'https://{{INSTANCE}}/api/datastreams/{{DATASTREAM_ID}}/jobs/' \
--header 'Authorization: Token {{KEY}}'
The response is a paginated envelope with the count, next,
previous, and results fields. Use the page and page_size
query parameters to page through the results:
curl --location -g --request GET 'https://{{INSTANCE}}/api/datastreams/{{DATASTREAM_ID}}/jobs/?page=1&page_size=50' \
--header 'Authorization: Token {{KEY}}'
Note
This endpoint returns fetch jobs only and does not accept the filter
parameters described in Filtering the jobs.
To filter by job type, user, or date range, or to list other job types
(such as Enrich or Transfer), use
GET /api/jobs/?datastream_id={{DATASTREAM_ID}} instead.
Obtaining the status of a job in progress#
To obtain a status of a job in progress, follow these steps:
Create a GET request to the following endpoint:
https://{{INSTANCE}}/api/jobs/{{JOB_ID}}/imported/
Find the value of
JOB_IDparameter in the response of the API request described in the previous section. In this response,JOB_IDparameter is named asid.In the HTTP request header, include the parameter
Authorizationwith one of the following values:Token {{KEY}}if you use a key generated with user credentials in Management API.Bearer {{KEY}}if you use a key generated in the Adverity user interface.
Send the request.
Import the request example as raw text to your HTTP client (such as Postman). The cURL request example is the following:
curl --location -g --request GET 'https://{{INSTANCE}}/api/jobs/{{JOB_ID}}/imported/' \
--header 'Authorization: Token {{KEY}}'
The response contains the following fields:
Field |
Description |
|---|---|
|
Boolean. |
|
Boolean. |
Note
Poll this endpoint until completed is true, then check
imported to determine whether data landed successfully.
Stopping jobs#
To stop a job, list the currently running jobs, and find the JOB_ID
of the job to stop. You can only stop jobs in the fetch stage.
To stop a job using JOB_ID, follow these steps:
Create a POST request to the following endpoint:
https://{{INSTANCE}}/api/jobs/{{JOB_ID}}/stop/
In the HTTP request header, include the parameter
Authorizationwith one of the following values:Token {{KEY}}if you use a key generated with user credentials in Management API.Bearer {{KEY}}if you use a key generated in the Adverity user interface.
Send the request.
Import the request example as raw text to your HTTP client (such as Postman). The cURL request example is the following:
curl --location -g --request POST 'https://{{INSTANCE}}/api/jobs/{{JOB_ID}}/stop/' \
--header 'Authorization: Token {{KEY}}'