Add Audience

Adds one of the following:

  • Audience

    1. Set the type parameter to Single.

    2. Define the conditions under which a viewer qualifies for this audience through the match_type parameter and the following parameters:

      country_codes | devices | dma_codes | ip_networks | zip_codes

  • Superaudience

    1. Set the type parameter to Multiple.
    2. Set the sub_audiences parameter to the set of audiences that will be associated with this superaudience.
    3. Determine the conditions under which a viewer qualifies for this superaudience through the match_type parameter.

Request

Request syntax:

POST /audiences

Request body parameters:

Pass the following request body parameters:

NameData TypeDescription
country_codesList of string valuesAudience only Identifies the set of countries associated with this audience. Specify each country by its two character country code (ISO 3166). View a list of country codes.
desc RequiredStringDefines the name of the audience or superaudience.
devicesList of string valuesAudience only Identifies the set of devices associated with this audience. Specify a name or description for each desired device. Each value in this List will be compared against the value defined for the repl.cbdevice playback URL parameter.
dma_codesList of string valuesAudience only Identifies the set of designated market areas (DMA) associated with this audience. Specify the ID for each desired United States DMA. Request Nielsen DMA data.
external_idStringDefines the external ID associated with this audience or superaudience.
ip_networksList of string valuesAudience only Identifies the set of IP addresses or subnets associated with this audience. Specify each desired IP address or subnet.
match_typeStringDetermines the set of criteria that will be required to qualify a viewer for this audience or superaudience. Valid values are: ALLANYNONE Learn more.
sub_audiencesList of string valuesSuperaudience only Defines the set of audiences associated with this superaudience. Specify the system-defined ID for each desired audience. Learn more.
typeStringDetermines whether this configuration is an audience or a superaudience. Valid values are: SingleMultiple Learn more.
zip_codesList of string valuesAudience only Identifies the set of United States zip codes associated with this audience. Specify each desired 5 digit zip code.

Response

A successful request returns a 201 Created response that contains the following properties:

NameData TypeDescription
@idStringIndicates the relative path to an endpoint that returns this audience or superaudience.
@typeStringReturns Audience.
country_codesList of string valuesAudience only Indicates the set of countries associated with this audience. Each value identifies a country by its two character country code (ISO 3166). View a list of country codes.
createdStringIndicates the timestamp (UTC) at which the audience or superaudience was created. Syntax (ISO 8601): YYYY-MM-DDThh:mm:ss.sssZ
descStringIndicates the name of the audience or superaudience.
devicesList of string valuesAudience only Indicates the set of devices associated with this audience. Each value identifies a device by its name or description. Each value in this List will be compared against the value defined for the repl.cbdevice playback URL parameter.
dma_codesList of string valuesAudience only Indicates the set of designated market areas (DMA) associated with this audience. Each value identifies a United States DMS by its ID. Request Nielsen DMA data.
external_idStringIndicates the external ID associated with this audience or superaudience.
idStringIdentifies this audience or superaudience by its system-defined ID.
ip_networksList of string valuesAudience only Indicates the set of IP addresses or subnets associated with this audience. Each value identifies either an IP address or IP network.
match_typeStringDetermines the set of criteria that will be required to qualify a viewer for this audience or superaudience. Valid values are: ALLANYNONE Learn more.
ownerStringIndicates the system-defined ID for the user that owns this audience or superaudience.
sub_audiencesList of string valuesSuperaudience only Indicates the set of audiences associated with this superaudience. Each value identifies an audience by its system-defined ID. Learn more.
typeStringIndicates whether this configuration is an audience or a superaudience. Valid values are: SingleMultiple Learn more.
zip_codesList of string valuesAudience only Indicates the set of United States zip codes associated with this audience. Each value identifies a zip code.

Sample Request/Response

Call the add_audience module (Python 3) to create an audience. This module imports names from the api_auth module.

import json, requests
from api_auth import APICredentials, APIParams

class Audience:
    def __init__(self):
        self.host = "https://services.uplynk.com"

    def run(self):
        """
        Create a audience.
        """
        self._create_audience()

    def _create_audience(self):
        url = "{}{}".format(self.host, "/api/v4/audiences")

        payload = {
            'desc': 'My New audience', # Replace with the audience's name.
            'country_codes': ['US', 'CA', 'MX'], # Replace with the desired country codes.
            'external_id': 'NorthAmerica', # Replace with the audience's external ID.
            'match_type': 'ANY' # Determines when a viewer qualifies for this audience.
        }

        headers = {'Content-Type': 'application/json'}

        response = requests.post(
            url, params=APIParams(APICredentials()).get_params({}), data=json.dumps(payload), headers=headers
        )

        print(response.json())

Audience().run()

Response:

{
	'@id': '/api/v4/audiences/abc11672b78c4d03bf4756ec3ea46a22',
	'@type': 'Audience',
	'created': '2021-06-30T22:32:09.362Z',
	'id': 'cc1c1672b78c4d03bf4756ec3ea46a45',
	'owner': 'abc123def456ghi789jkl012mno345pq',
	'match_type': 'ANY',
	'external_id': 'NorthAmerica',
	'country_codes': ['CA', 'MX', 'US'],
	'dma_codes': [],
	'desc': 'My New audience',
	'devices': [],
	'ip_networks': [],
	'zip_codes': [],
	'sub_audiences': [],
	'type': 'Single'
}