Targeting
Targetings are used to represent the targeting settings of campaigns, ad sets and ads. Targetings are used to define targeting criteria such as socio-demographic criteria, geographic criteria, device criteria, retargeting criteria, etc.
The Targeting Model
The targeting model of n_2 describes targetings of campaigns, ad sets and ads independently of the platform they belong to. This allows you to manage targetings of campaigns, ad sets and ads in a platform-agnostic way.
Properties
- Name
targetingKind
- Type
- string
- Description
The kind of the targeting. This is used to distinguish between different kinds of targetings.
See the targeting kinds section for a list of all possible values.
- Name
<CustomTargetingFields>
- Type
- any
- Description
Custom fields that are specific to the targeting kind. See the targeting kinds section for more information.
Example Object
{
"targetingKind": "ZipcodeGeoTargeting",
"zipcodes": [
{ "countryCode": "DE", "value": "72074" },
{ "countryCode": "DE", "value": "72072" }
]
}
Retrieving all targetings
Retrieval of targetings is usually done via the campaign, ad set and ad endpoints by setting the childResources
query parameter to include the value Targeting
.
However, you can also retrieve targetings of single resources directly as described in the following.
This endpoint allows you to retrieve targetings of a campaign, ad set or ad.
Path parameters
- Name
platform
- Type
- string
- Description
The platform of the corresponding resource. See the platforms page for a list of all possible values.
- Name
resource
- Type
- string
- Description
The type of the resource the targeting belongs to. Possible values are
campaigns
,adsets
andads
.
- Name
resourceId
- Type
- string
- Description
The ID of the resource the targeting belongs to.
Request
curl -G https://api.n2api.io/v1/GoogleAds/campaigns/1234567/targetings \
-H "Authorization: Bearer {token}"
Response
{
"targetings": [
{
"targetingKind": "ZipcodeGeoTargeting",
"zipcodes": [
{ "countryCode": "DE", "value": "72074" },
{ "countryCode": "DE", "value": "72072" }
]
},
{
"targetingKind": "GenderTargeting",
"genders": [
"non-binary"
]
}
]
}
Creating / updating a targeting
This endpoint allows you to update targetings of a campaign, ad set or ad. If the targeting does not exist yet, it will be created.
Path parameters
- Name
platform
- Type
- string
- Description
The platform of the corresponding resource. See the platforms page for a list of all possible values.
- Name
resource
- Type
- string
- Description
The type of the resource the targeting belongs to. Possible values are
campaigns
,adsets
andads
.
- Name
resourceId
- Type
- string
- Description
The ID of the resource the targeting belongs to.
Request body
- Name
targetings
- Type
- list<Targeting>
- Description
The targetings to create or update. See the targetings model section for more information on the structure of a targeting. All fields of a targeting are mandatory unless otherwise specified.
Request
curl https://api.n2api.io/v1/GoogleAds/campaigns/1234567 \
-X PUT \
-H "Authorization: Bearer {token}" \
-d '{
"targetings": [
{
"targetingKind": "ZipcodeGeoTargeting",
"zipcodes": [
{ "countryCode": "DE", "value": "72074" },
{ "countryCode": "DE", "value": "72072" }
]
}
]
}'
Response
{
"targetings": [
{
"targetingKind": "ZipcodeGeoTargeting",
"zipcodes": [
{ "countryCode": "DE", "value": "72074" },
{ "countryCode": "DE", "value": "72072" }
]
}
]
}
Notice that the response contains all targetings of the campaign, ad set or ad, not just the ones that were updated.
Delete a targeting
This endpoint allows you to delete a targeting of a campaign, ad set or ad.
Notice that some targetings are required by the platform and cannot be deleted. See the targeting kinds section for more information.
Path parameters
- Name
platform
- Type
- string
- Description
The platform of the corresponding resource. See the platforms page for a list of all possible values.
- Name
resource
- Type
- string
- Description
The type of the resource the targeting belongs to. Possible values are
campaigns
,adsets
andads
.
- Name
resourceId
- Type
- string
- Description
The ID of the resource the targeting belongs to.
- Name
targetingKind
- Type
- string
- Description
The type of the targeting to delete. See the targeting kinds section for a list of all possible values.
Request
curl https://api.n2api.io/v1/GoogleAds/campaigns/1234567/targetings/ZipcodeGeoTargeting \
-X DELETE \
-H "Authorization: Bearer {token}"
Response
{
"deletions": 1,
}
Targeting kinds
Retrieving targeting kinds
This endpoint allows you to retrieve all targeting kinds that are supported by n_2. Along with the targeting kind, the endpoint also returns the corresponding mandatory fields.
Query parameters
The following query parameters are optional. If they are not specified, all targeting kinds are returned.
- Name
platforms
- Type
- list<string>
- Description
The platforms to filter by. See the platforms page for a list of all possible values.
- Name
resources
- Type
- list<string>
- Description
The resources to filter by. Possible values are
campaigns
,adsets
andads
.
Request
curl https://api.n2api.io/v1/targetings \
-X GET \
-H "Authorization: Bearer {token}" \
-d '{
"platform": "GoogleAds",
"resource": "adsets",
}'
Example Response
[
{
"targetingKind": "ZipcodeGeoTargeting",
"fields": [
{
"name": "zipcodes",
"type": "list<{
countryCode: string,
value: string,
}>",
"description": "The zipcodes in which to run the ad."
}
]
},
{
...
}
]