Scheduling fetches in Management API#

This article explains how to configure scheduled fetches for your datastreams with the Management API.

Introduction#

Scheduling lets you configure fetches that periodically retrieve data extracts from your datastreams.

Prerequisites#

Before you complete the procedure in this guide, perform all of the following actions:

  • Create a datastream and determine its datastream ID. For more information, see Creating datastreams.

Retrieving existing schedules#

To retrieve existing schedules, follow these steps:

  1. Create a GET request to the following endpoint:

    https://{{INSTANCE}}/api/datastreams/{{DATASTREAM_ID}}/schedules
    
  2. In the HTTP request header, include the parameter Authorization with 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.

  3. Send the request.

  4. In the response, search for schedules to find currently configured schedules.

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}}/schedules' \
--header 'Authorization: Token {{KEY}}'

Retrieving schedule and date range options#

To retrieve schedule options and date range options for a particular datastream, follow these steps:

  1. Create an OPTIONS request to the following endpoint:

    https://{{INSTANCE}}/api/datastreams/{{DATASTREAM_ID}}/
    
  2. In the HTTP request header, include the parameter Authorization with 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.

  3. 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 OPTIONS 'https://{{INSTANCE}}/api/datastreams/{{DATASTREAM_ID}}/' \
--header 'Authorization: Token {{KEY}}'

Example of the part of response with two options for fetch date range (choices) of the time_range_preset variable:

"time_range_preset": {
   "type": "choice",
   "required": false,
   "read_only": false,
   "label": "Time range preset",
   "help_text": "Select one of the time range presets.",
   "choices": [
        {
          "display_name": "Fixed Time Range",
          "value": 0
        },
        {
          "display_name": "Yesterday",
          "value": 13
        },

Configuring a schedule and date range#

After you configured an OPTIONS call to retrieve the accepted parameters for schedule options, you can edit these parameters. To configure a schedule, follow these steps:

  1. Create a PATCH request to the following endpoint:

    https://{{INSTANCE}}/api/datastreams/{{DATASTREAM_ID}}/
    
  2. In the HTTP request header, include the parameter Authorization with 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.

  3. In the HTTP request header, include the parameter Content-Type with value application/json.

  4. In the HTTP request body, include the parameter time_range_preset. Set the value of this parameter according to the options retrieved in the API call described in the previous section. This parameter specifies the date range of the fetch (for which days, weeks, and other time specific values you are requesting the data).

  5. In the HTTP request body, include the parameter and value "cron_type": "week". This parameter specifies how often the fetch is periodically scheduled. "cron_type": "week" fetches the data of a datastream once per week.

  6. 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 PATCH 'https://{{INSTANCE}}/api/datastreams/{{DATASTREAM_ID}}/' \
--header 'Authorization: Token {{KEY}}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "time_range_preset": 11,
    "cron_type": "week"
}'

Creating a new schedule#

To create a new schedule, send a PATCH request that includes all required variables for a fetch schedule. Find the necessary values using the OPTIONS request described in section Retrieving schedule options above. To create a new schedule, follow these steps:

  1. Create a PATCH request to the following endpoint:

    https://{{INSTANCE}}/api/datastreams/{{DATASTREAM_ID}}/
    
  2. In the HTTP request header, include the parameter Authorization with 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.

  3. In the HTTP request header, include the parameter Content-Type with value application/json.

  4. In the HTTP request body, include the following parameters and values (edit them as necessary):

    {
        "cron_preset": "CRON_EVERY_DAY",
        "cron_type": "day",
        "cron_interval": 1,
        "cron_start_of_day": "00:00:00",
        "cron_interval_start": 1,
        "time_range_preset": 0,
        "time_range_preset_label": "Fixed Time Range",
        "delta_type": 1,
        "delta_interval": 1,
        "delta_start_of_day": "00:00:00",
        "delta_interval_start": 1,
        "fixed_start": "2021-12-01",
        "fixed_end": "2021-12-02",
        "offset_days":
    }
    
  5. 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 PATCH 'https://{{INSTANCE}}/api/datastreams/{{DATASTREAM_ID}}/' \
--header 'Authorization: Token {{KEY}}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "cron_preset": "CRON_EVERY_DAY",
    "cron_type": "day",
    "cron_interval": 1,
    "cron_start_of_day": "00:00:00",
    "cron_interval_start": 1,
    "time_range_preset": 0,
    "time_range_preset_label": "Fixed Time Range",
    "delta_type": 1,
    "delta_interval": 1,
    "delta_start_of_day": "00:00:00",
    "delta_interval_start": 1,
    "fixed_start": "2021-12-01",
    "fixed_end": "2021-12-02",
    "offset_days":
}

Creating multiple schedules#

Similarly to the procedure described in the previous section, send a PATCH request that includes all required variables for multiple fetch schedules. Find the necessary values using the OPTIONS request described in section Retrieving schedule options above. To create multiple schedules, follow these steps:

  1. Create a PATCH request to the following endpoint:

    https://{{INSTANCE}}/api/datastreams/{{DATASTREAM_ID}}/
    
  2. In the HTTP request header, include the parameter Authorization with 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.

  3. In the HTTP request header, include the parameter Content-Type with value application/json.

  4. In the HTTP request body, include the following parameters and values (edit them as necessary):

    {
        "cron_preset": "CRON_EVERY_DAY",
        "cron_type": "day",
        "cron_interval": 1,
        "cron_start_of_day": "00:00:00",
        "cron_interval_start": 1,
        "time_range_preset": 0,
        "time_range_preset_label": "Fixed Time Range",
        "delta_type": 1,
        "delta_interval": 1,
        "delta_start_of_day": "00:00:00",
        "delta_interval_start": 1,
        "fixed_start": "2021-12-01",
        "fixed_end": "2021-12-02",
        "offset_days":
    },
    {
        "cron_preset": "CRON_EVERY_WEEK",
        "cron_type": "week",
        "cron_interval": 1,
        "cron_start_of_day": "00:00:00",
        "cron_interval_start": 1,
        "time_range_preset": 0,
        "time_range_preset_label": "Fixed Time Range",
        "delta_type": 1,
        "delta_interval": 1,
        "delta_start_of_day": "00:00:00",
        "delta_interval_start": 1,
        "fixed_start": "2021-12-01",
        "fixed_end": "2021-12-02",
        "offset_days": 0
    }
    
  5. 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 PATCH 'https://{{INSTANCE}}/api/datastreams/{{DATASTREAM_ID}}/' \
--header 'Authorization: Token {{KEY}}' \
--header 'Content-Type: application/json' \
--data-raw '{"schedules": [
{
    "cron_preset": "CRON_EVERY_DAY",
    "cron_type": "day",
    "cron_interval": 1,
    "cron_start_of_day": "00:00:00",
    "cron_interval_start": 1,
    "time_range_preset": 0,
    "time_range_preset_label": "Fixed Time Range",
    "delta_type": 1,
    "delta_interval": 1,
    "delta_start_of_day": "00:00:00",
    "delta_interval_start": 1,
    "fixed_start": "2021-12-01",
    "fixed_end": "2021-12-02",
    "offset_days": 0
},
{
    "cron_preset": "CRON_EVERY_WEEK",
    "cron_type": "week",
    "cron_interval": 1,
    "cron_start_of_day": "00:00:00",
    "cron_interval_start": 1,
    "time_range_preset": 0,
    "time_range_preset_label": "Fixed Time Range",
    "delta_type": 1,
    "delta_interval": 1,
    "delta_start_of_day": "00:00:00",
    "delta_interval_start": 1,
    "fixed_start": "2021-12-01",
    "fixed_end": "2021-12-02",
    "offset_days": 0
}
]
}'