Zernio
Zernio
PlatformsMeta Ads

Build

CampaignsAd SetsCreativesCreative LibraryPreviews

Target

TargetingCustom Audiences

Ad types

Boost a PostCreative TestingConversion CampaignsCatalog AdsMessaging & Call AdsClick-to-WhatsApp AdsLead Gen FormsReach & Frequency

Measure

InsightsMeta PixelsConversions APIAd URL Tracking Tags

Operate

Duplicate & LifecycleAccount & Ops ReadsAd LibraryAd CommentsMedia & Limits
Dashboard
llms.txtOpenAPI
OverviewPlatformsAPI ReferenceResources
Meta Ads

Targeting

Target Meta ads by country, city, region, ZIP, age, gender and interests, and resolve Meta's opaque location and interest ids with GET /v1/ads/targeting/search.


Target by country, city, region, ZIP, metro, age, gender, interests and behaviours with flat fields on POST /v1/ads/create. Cities, regions and interests are opaque Meta ids: resolve them with GET /v1/ads/targeting/search first. POST /v1/ads/boost, POST /v1/ads/messaging and reach estimates take the same fields inside a targeting object.

Targeting fields

FieldTypeMeaning
ageMin, ageMaxnumber13 to 65.
genderstringall (default), male or female.
countriesstring[]ISO 3166-1 alpha-2 codes. Defaults to ["US"] when no other geo field is present.
citiesobject[]{ key, radius?, distance_unit? }. key comes from the search below; radius and distance_unit (kilometer or mile) go together. Meta enforces a minimum radius of about 17 km (10 miles); a smaller one resolves to an empty audience and the ad fails at launch.
regionsobject[]{ key } from a search with geoType=region.
zipsobject[]{ key } from a search with geoType=zip, for example US:94304.
metrosobject[]{ key } from a search with geoType=metro_area, for example DMA:807.
customLocationsobject[]{ latitude, longitude, radius, distanceUnit } for a point-radius catchment tighter than a city radius.
interestsobject[]{ id, name } from a search with dimension=interest.
behaviorsobject[]{ id, name } from a search with dimension=behavior.
languagesstring[]A bare code (en) targets every regional variant; a region-qualified code (en_GB) targets one.
placementsobjectManual placements; omit for Meta's automatic placements. Values are in the reference.
savedTargetingIdstringA saved_targeting audience whose spec is the base; inline fields merge on top.
rawTargetingobjectA Meta-native targeting spec (geo_locations, flexible_spec, excluded_custom_audiences), for fields the flat surface does not expose.

On POST /v1/ads/create these sit at the top level. On POST /v1/ads/boost they live inside targeting, and cities there spell the unit distanceUnit. Do not combine cities with the countries that contain them: Meta returns a "locations overlap" error because the city is already inside the country. Drop the country, or scope countries to a different one.

Look up city and region keys

Call GET /v1/ads/targeting/search with accountId, q, dimension=geo and geoType, then pass the returned id as key. countryCode disambiguates names that exist in several countries. The older GET /v1/ads/interests is a deprecated alias of the interest search.

import Zernio from '@zernio/node';

const zernio = new Zernio();

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

const cityKey = search.results[0].id;

Response (200):

{
  "results": [
    {
      "id": "2759794",
      "name": "Amsterdam",
      "type": "city",
      "path": ["Netherlands", "North Holland", "Amsterdam"],
      "audienceSize": null
    }
  ]
}

Then use the key on the create request, replacing countries. EU targeting also needs the DSA beneficiary and payer, unless the ad account has defaults set:

{
  "budgetType": "lifetime",
  "endDate": "2027-03-31T23:59:00Z",
  "cities": [{ "key": "2759794", "radius": 25, "distance_unit": "kilometer" }],
  "dsaBeneficiary": "Acme BV",
  "dsaPayor": "Acme BV"
}

geoType accepts all, country, region, city (the default), subcity, neighborhood, place, zip, metro_area and geo_market. dimension also resolves interest, behavior, income, and the Meta-only workPosition, workEmployer and workIndustry.

Estimate reach

POST /v1/ads/targeting/reach-estimate with accountId, adAccountId and a spec (the same fields as above, nested) returns Meta's delivery_estimate as { available, lower, upper, estimateReady } before you create anything. estimateReady: false means Meta is still computing it; retry shortly.

If it fails

A 400 with type: "platform_error" on create is Meta rejecting the geo combination:

{
  "error": "Invalid parameter: Your cities and countries overlap",
  "type": "platform_error",
  "platform": "meta",
  "platformError": { "code": 100 }
}

Remove the country that already contains the city. A 404 on the search means the account's platform does not support the requested dimension.

Related

  • Campaigns: the create request these fields go on.
  • Audiences: customer lists, lookalikes and saved targeting.
  • Reference: the placements values and special ad categories.
  • Search targeting options and Estimate audience reach: every parameter.
Was this page helpful?

Previews

Render a Meta ad, or a creative that does not exist yet, as Meta renders it, with GET /v1/ads/{adId}/preview and POST /v1/ads/preview.

Custom Audiences

Create Meta customer list, website, lookalike, engagement and saved targeting audiences with POST /v1/ads/audiences, and fill a customer list with hashed uploads.

On this page

Targeting fieldsLook up city and region keysEstimate reachIf it failsRelated