Assigning destinations to datastreams in Management API
This article explains how to assign destinations to datastreams with the Management API.
Prerequisites
-
Create and configure a datastream. For more information, see Creating datastreams in Management API.
-
Set up a destination. For more information, see Creating and deleting destinations in Management API.
Limitations
Only the following destination types can be assigned to a datastream using the Management API:
-
AzureBlobTarget
-
BigQueryTarget
-
DeltalakeTarget
-
DatabricksSQLTarget
-
FileTarget
-
Google Sheets
-
LinkedIn Matched Audiences
-
Snowflake
-
SqlTarget
Management API calls that relate to the assignment of a destination to a datastream can only be used for these destinations.
Listing available destination types
To list available destination types, follow these steps:
-
Create a GET request to the following endpoint:
https://{{INSTANCE}}/api/target-types/
-
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.
-
-
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/target-types/' \
--header 'Authorization: Token {{KEY}}'
Listing available destinations of a specific destination type
Use the API call below to find information about available destination types. To list the available destinations of a specific destination type, follow these steps:
-
Create a GET request to the following endpoint:
https://{{INSTANCE}}/api/target-types/{{TARGET_TYPE_ID}}/targets/
The value for the parameter
TARGET_TYPE_ID
is the destination type ID that you obtained in the response to the API call described in Listing available destination types. -
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.
-
-
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/target-types/{{TARGET_TYPE_ID}}/targets/' \
--header 'Authorization: Token {{KEY}}'
Listing datastreams that have a specific destination assigned
To list the datastreams that have a specific destination already assigned, follow these steps:
-
Create a GET request to the following endpoint:
https://{{INSTANCE}}/api/target-types/{{TARGET_TYPE_ID}}/targets/{{TARGET_ID}}/mappings/
The value for the parameter
TARGET_ID
is the destination ID that you obtained in the response to the API call described in Listing available destinations of a specific destination type. -
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.
-
-
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/target-types/{{TARGET_TYPE_ID}}/targets/{{TARGET_ID}}/mappings/' \
--header 'Authorization: Token {{KEY}}'
Retrieving available options to configure the destination's assignment
Different destination types may have different configuration options available when assigning the destination to a datastream. In this request's response, you can also find the IDs and names of all datastreams to which you can assign the destination.
To retrieve available options for assignment of the specific destination to a datastream, follow these steps:
-
Create an OPTIONS request to the following endpoint:
https://{{INSTANCE}}/api/target-types/{{TARGET_TYPE_ID}}/targets/{{TARGET_ID}}/mappings/
-
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.
-
-
Send the request.
curl --location -g --request OPTIONS 'https://{{INSTANCE}}/api/target-types/{{TARGET_TYPE_ID}}/targets/{{TARGET_ID}}/mappings/' \
--header 'Authorization: Token {{KEY}}'
Assigning a specific destination to a datastream
To assign a specific destination to a datastream, follow these steps:
-
Create a POST request to the following endpoint:
https://{{INSTANCE}}/api/target-types/{{TARGET_TYPE_ID}}/targets/{{TARGET_ID}}/mappings/
-
In the HTTP request header, include the parameter
Content-Type
with valueapplication/json
. -
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.
-
-
In the HTTP request body, include the following parameters with their respective values:
{ "datastream": {{DATASTREAM_ID}}, "table_name": "TABLE_MAPPING_NAME" }
The value for the parameter
DATASTREAM_ID
is the ID of the datastream you choose from the list that you obtained using the API call in Listing datastreams to which a specific destination can be assigned.As the value for the parameter
TABLE_MAPPING_NAME
, create a new name for the assignment of a destination or choose an existing name to add the datastream to an existing assignment. -
Send the request.
curl --location --request POST 'https://{{INSTANCE}}/api/target-types/{{TARGET_TYPE_ID}}/targets/{{TARGET_ID}}/mappings/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Token {{KEY}}' \
--data-raw '{"datastream": {{DATASTREAM_ID}},
"table_name": "TABLE_MAPPING_NAME"}'
Editing the assignment of destinations to a datastream and enabling the destination
This API call enables you to change the mapping ID, target destination, datastream ID, or mapping table name (assignment name). You can also enable or disable this destination for the datastream. To edit the assignment of a destination to a datastream, follow these steps:
-
Create a PUT request to the following endpoint:
https://{{INSTANCE}}/api/target-types/{{TARGET_TYPE_ID}}/targets/{{TARGET_ID}}/mappings/{{MAPPING_ID}}/
-
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.
-
-
In the HTTP request header, include the parameter
Content-Type
with valueapplication/json
. -
In the HTTP request body, include the following parameters with their respective values:
{ "id": {{MAPPING_ID}}, "target": {{TARGET_ID}}, "datastream": {{DATASTREAM_ID}}, "table_name": "TABLE_MAPPING_NAME", "enabled": "True" }
-
To edit the assignment, change one or more of these values. You must always include the first four parameters. If you only want to change some of the values, leave the other values unchanged.
-
Send the request.
curl --location --request PUT 'https://{{INSTANCE}}/api/target-types/{{TARGET_TYPE_ID}}/targets/{{TARGET_ID}}/mappings/{{MAPPING_ID}}/' \
--header 'Authorization: Token {{KEY}} \
--header 'Content-Type: application/json' \
--data-raw '{"id": {{MAPPING_ID}},
"target": {{TARGET_ID}},
"datastream": {{DATASTREAM_ID}},
"table_name": "TABLE_MAPPING_NAME,
"enabled": "True"}'
Enabling all destinations assigned to a datastream
To enable all destinations that have been assigned to a datastream, follow these steps:
This is a specific example of configuring a datastream. For more information, see Configuring and editing datastreams in Management API.
-
Create a PATCH request to the following endpoint:
https://{{INSTANCE}}/api/datastream-types/{{DATASTREAM_TYPE}}/datastreams/{{DATASTREAM_ID}}/
Replace
{{DATASTREAM_ID}}
with the datastream's ID. -
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.
-
-
In the HTTP request header, include the parameter
Content-Type
with valueapplication/json
. -
In the HTTP request body, update the value of the
datatype
configuration option toLive
. -
Send the request.
curl --location --request PATCH 'https://{{INSTANCE}}/api/datastream-types/{{DATASTREAM_TYPE}}/datastreams/{{DATASTREAM_ID}}/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Token {{KEY}}' \
--data-raw '{"datatype": "Live"}'
Deleting the assignment of destinations to a datastream
To delete the assignment of a destination to a datastream, follow these steps:
-
Create a DELETE request to the following endpoint:
https://{{INSTANCE}}/api/target-types/{{TARGET_TYPE_ID}}/targets/{{TARGET_ID}}/mappings/{{MAPPING_ID}}/
-
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.
-
-
In the HTTP request header, include the parameter
Content-Type
with valueapplication/json
. -
In the HTTP request body, include the following parameters with their respective values:
{ "datastream": {{DATASTREAM_ID}}, "table_name": "TABLE_MAPPING_NAME" }
-
Send the request.
curl --location --request DELETE 'https://{{INSTANCE}}/api/target-types/{{TARGET_TYPE_ID}}/targets/{{TARGET_ID}}/mappings/{{MAPPING_ID}}/' \
--header 'Authorization: Token {{KEY}}' \
--header 'Content-Type: application/json' \
--data-raw '{
"datastream": {{DATASTREAM_ID}},
"table_name": "TABLE_MAPPING_NAME"
}'