Zernio
APIFor you
Zernio
APIFor you
Platforms

X Ads

Overview

Build

Create a campaignPromote a post

Target

TargetingTailored Audiences

Measure

AnalyticsX Pixel

Operate

Manage ads

Reference

Limits & errors
Dashboard
OverviewPlatformsAPI ReferenceResources
X Ads

Targeting

Target X ads by location, interest, Tailored Audience, age, gender and language, and search X's targeting values.


The targeting fields go on POST /v1/ads/create and land on the line item as X targeting criteria.

Targeting fields

FieldX targetingValues from
countriesLocationISO country codes
regions, metros, cities, zipsLocation{ "key": "..." } from targeting search, dimension=geo
interestsInterest{ "id": "..." } from targeting search, dimension=interest
audienceInclude, audienceExcludeCustom audienceThe X custom audience id of a Tailored Audience
ageMin, ageMaxAgeRounded out to the narrowest X age range that covers them
genderGendermale or female; all sends no gender criterion
languagesLanguageLanguage codes such as en; a region suffix (en_GB) is dropped

The geo keys and interest ids are X's own targeting values, so a key from another platform does not work.

incomeTier, customLocations and behaviors are rejected. X removed behavior targeting from its Ads API.

Age ranges

X targets one age range from a fixed list. A range starts at 13, 18, 21, 25, 35 or 50, and ends at 24, 34, 49 or 54, or runs open-ended.

Zernio picks the narrowest one that covers ageMin and ageMax. So ageMin: 20, ageMax: 40 targets 18 to 49.

Find targeting values

GET /v1/ads/targeting/search with the xads accountId searches X's own catalog (Search ad targeting). It takes dimension=geo or dimension=interest.

On geo, geoType is country, region, metro_area, city or zip, and countryCode narrows the results to one country.

const { data: search } = await zernio.adtargeting.searchAdTargeting({
  query: { accountId: '66b2e19d8c3f5a7e9d0b1c2d', q: 'Austin', dimension: 'geo', geoType: 'city', countryCode: 'US' }
});

const keys = search.results.map((result) => ({ key: result.id }));

Response (200):

{
  "results": [
    { "id": "3b77caf94bfc81fe", "name": "Austin", "type": "city", "countryCode": "US" }
  ]
}

A geo result's id is the X targeting value: send it as key. A country result's id is the ISO code that countries takes.

An interest result carries the interest id, with its parent categories in path.

If it fails

ErrorCauseFix
400 with code invalid_field_value, param: "targeting.languages"A language X cannot targetUse one of the codes the message lists.
400 with param: "dimension"A search dimension other than geo or interestSearch geo or interest.
400 on incomeTier, customLocations or behaviorsX has no slot for themRemove the field.
501 with code feature_not_availabletargeting sent to PUT /v1/ads/{adId}Create a new ad with the new targeting.

Related

  • Search ad targeting: every parameter of the search.
  • Create a campaign: the request these fields go on.
  • Tailored Audiences: build the audiences audienceInclude targets.
  • Limits & Errors: targeting X does not support.
Was this page helpful?

Promote a post

Promote a post you already published on X as an ad, keeping its engagement and media.

Tailored Audiences

Create a Tailored Audience on an X Ads account and upload its members by email.

On this page

Targeting fieldsAge rangesFind targeting valuesIf it failsRelated