# Targeting

Target a Microsoft Ads search campaign by country; its keywords decide which searches it shows on.

import { Tab, Tabs } from 'fumadocs-ui/components/tabs';

A search campaign shows on searches that match its keywords, in the countries it targets.

## Targeting fields

Send the countries as ISO 3166-1 alpha-2 codes in `countries` (or `targeting.countries`). They are required on every create.

<Tabs items={['Node.js', 'Python', 'curl']}>
<Tab value="Node.js">
```typescript
const { data: created } = await zernio.adcampaigns.createStandaloneAd({
  body: {
    accountId: '66b2e19d8c3f5a7e9d0b1c2d',
    adAccountId: '189372438',
    name: 'Planner launch EU',
    goal: 'traffic',
    status: 'PAUSED',
    budgetAmount: 5,
    budgetType: 'daily',
    headline: 'Plan Your Week in Minutes',
    body: 'Tasks, docs and meetings in one place. Free for teams of 5.',
    linkUrl: 'https://example.com/planner',
    targeting: { countries: ['ES', 'FR', 'DE'] },
    keywords: ['team planner']
  }
});
```
</Tab>
<Tab value="Python">
```python
created = client.ad_campaigns.create_standalone_ad(
    account_id="66b2e19d8c3f5a7e9d0b1c2d",
    ad_account_id="189372438",
    name="Planner launch EU",
    goal="traffic",
    status="PAUSED",
    budget_amount=5,
    budget_type="daily",
    headline="Plan Your Week in Minutes",
    body="Tasks, docs and meetings in one place. Free for teams of 5.",
    link_url="https://example.com/planner",
    targeting={"countries": ["ES", "FR", "DE"]},
    keywords=["team planner"],
)
```
</Tab>
<Tab value="curl">
```bash
curl -X POST "https://zernio.com/api/v1/ads/create" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "accountId": "66b2e19d8c3f5a7e9d0b1c2d",
    "adAccountId": "189372438",
    "name": "Planner launch EU",
    "goal": "traffic",
    "status": "PAUSED",
    "budgetAmount": 5,
    "budgetType": "daily",
    "headline": "Plan Your Week in Minutes",
    "body": "Tasks, docs and meetings in one place. Free for teams of 5.",
    "linkUrl": "https://example.com/planner",
    "targeting": { "countries": ["ES", "FR", "DE"] },
    "keywords": ["team planner"]
  }'
```
</Tab>
</Tabs>

The response is the created ad, as in [Create ads](/platforms/microsoft-ads/create-ads#create-a-campaign). Zernio maps each country to its Microsoft location and adds it to the campaign.

## How it behaves

- Countries are the only targeting Microsoft Ads takes through Zernio. Regions, cities, age, gender, interests and audiences are not available.
- Targeting is set at create; a later `targeting` update is not available.

## If it fails

| Error | Cause | Fix |
|-------|-------|-----|
| `422` with `param: "targeting.countries"` | No countries sent | Send at least one country. |
| `400` with code `invalid_field_value` | A targeting field other than countries | Remove it: only countries apply. |

## Related

- [Create ads](/platforms/microsoft-ads/create-ads): the rest of the create request.
- [Create standalone ad](/ad-campaigns/create-standalone-ad): every field of the request.
- [Limits & errors](/platforms/microsoft-ads/reference): what Microsoft Ads does not support yet.