Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.x.com/llms.txt

Use this file to discover all available pages before exploring further.

Programmatically create, schedule, and manage ad campaigns on X. Campaigns define your budget and schedule. Line items (also called ad groups) control targeting, bidding, and the creatives that run within a campaign.
Looking for detailed endpoint documentation?
The full API reference (all endpoints, request/response examples, and parameter tables for Accounts, Campaigns, Line Items, Funding Instruments, Targeting, etc.) has moved to the dedicated Campaign Management API Reference page. Old deep links (e.g. #get-accounts-account-id-campaigns) will automatically redirect there.

Advertiser API

Programatically schedule campaigns and manage ads on X through this suite of APIs.

What Can You Promote?

  • Promoted Ads are ordinary ads purchased by advertisers who want to reach a wider group of users or to spark engagement from their existing followers.
  • Promoted Ads are clearly labeled as Promoted when an advertiser is paying for their placement on X. In every other respect, Promoted Ads act just like regular ads and can be reposted, replied to, liked and more. They have typical delivery rules and are created using POST statuses/update.
  • “Promoted-only” Tweets, created via POST accounts/:account_id/tweet, can be used in Promoted Tweets campaigns but will not serve to followers or appear on the public timeline. To retrieve a list of promoted-only tweets for a certain account, use GET accounts/:account_id/scoped_timeline.
  • Promoted Accounts are part of Who to Follow, which suggests accounts that people don’t currently follow and may find interesting. Promoted Accounts help introduce an even wider variety of accounts people may enjoy.
  • Promoted Accounts for Timeline, associate a Promoted Tweet with a Promoted Account campaign and will display in user timelines.
Promoted Trends are not available in the Ads API.

Campaigns and Ad Groups (Line Items)

Campaigns define the schedule and budget of an ad. The advertiser specifies a daily and overall budget. The campaign can be bound to a specific start and end time or run continuously until the budget is spent. The budget comes from one of the Funding Instruments of the advertising account. Campaign identifiers (:campaign_id) are the base-36 representation of the base-10 value we present in the X Ads UI. Advertising accounts are limited to a maximum of 200 active campaigns. This limit can be raised to 4,000 active campaigns manually by the advertiser’s X Account Manager upon request. A campaign is considered active until it reaches its end time or gets deleted. Paused campaigns are considered active until their designated end times. Line items spend the budget defined by a campaign. Line items pull together the per-engagement bid, the Tweet or account to promote, and the targeting rules.

Analytics

The X Ads API offers a set of analytics endpoints to track and optimize ad performance. Please see Analytics and Analytics Best Practices for more information. For the billing metric, the data may not be finalized until three days after the event. Before that point, the data should be considered speculative. The final billable number will always be less than the speculative amount. The billable number is corrected for spam and related low-quality traffic. See Timezones for other considerations regarding time.

Creating a Campaign - Step-by-Step

The following example assumes you have installed, configured, and authorized your app and user using twurl. twurl is a command-line tool in the spirit of cURL that gracefully handles X OAuth authentication. twurl is a great tool for quickly testing and debugging Ads API (and REST API) functionality. To see the full headers of the request and response, use -t to trace the call, roughly equivalent to cURL’s -v option. For this example, we will create a Promoted Ads campaign that will be targeted by keyword.
  1. Retrieve the account id.
twurl -H ads-api.x.com /9/accounts/
{
  "request": {
    "params": {
    }
  },
  "data": [
    {
      "name": "Test account for @AdsAPI",
      "timezone": "America/Los_Angeles",
      "timezone_switch_at": null,
      "id": "xxxxxx",
      "created_at": "2014-03-09T00:41:49Z",
      "salt": "f9f9d5a5f23075c618da5eb1d1a9df57",
      "updated_at": "2015-01-29T00:41:49Z",
      "approval_status": "ACCEPTED",
      "deleted": false
    }
  ],
  "data_type": "account",
  "total_count": 1,
  "next_cursor": null
}
  1. Retrieve the funding instrument id.
Hit the GET accounts/:account_id/funding_instruments API using the account id retrieved in the previous command.
twurl -H ads-api.x.com /9/accounts/xxxxxx/funding_instruments
{
  "data": [
    {
      "cancelled": true,
      "created_at": "2014-03-09T00:41:49Z",
      "credit_limit_local_micro": null,
      "currency": "USD",
      "deleted": false,
      "description": null,
      "end_time": null,
      "funded_amount_local_micro": null,
      "id": "yyyy",
      "type": null,
      "updated_at": "2014-05-29T00:41:49Z"
    }
  ],
  "data_type": "funding_instrument",
  "next_cursor": null,
  "request": {
    "params": {
      "account_id": "xxxxxx"
    }
  },
  "total_count": 1
}
  1. Create a campaign and associate it with the funding instrument.
Specify a start time and a budget for the campaign. For the purpose of this example, we will use a budget of $500 and for the daily limit, $50.
twurl -H ads-api.x.com -d "funding_instrument_id=yyyy&name=My First Campaign&total_budget_amount_local_micro=500000000&daily_budget_amount_local_micro=50000000" /9/accounts/xxxxxx/campaigns
{
  "data": {
    "created_at": "2015-02-09T00:00:00Z",
    "currency": "USD",
    "daily_budget_amount_local_micro": 50000000,
    "deleted": false,
    "end_time": null,
    "funding_instrument_id": "yyyy",
    "id": "92ph",
    "name": "My First Campaign",
    "entity_status": "PAUSED",
    "standard_delivery": true,
    "total_budget_amount_local_micro": 500000000,
    "updated_at": "2015-02-09T00:00:00Z"
  },
  "data_type": "campaign",
  "request": {
    "params": {
      "account_id": "xxxxxx",
      "daily_budget_amount_local_micro": 50000000,
      "funding_instrument_id": "yyyy",
      "name": "My First Campaign",
      "total_budget_amount_local_micro": 500000000
    }
  }
}
  1. Create a line item associated with the campaign.
Now that we have a campaign id, we can create a line item to associate with it. The line item wraps the bid price, targeting, and actual creative portion of the campaign. For this line item, we will be promoting tweets with a bid of $1.50.
twurl -H ads-api.x.com -d "campaign_id=XXXX&bid_amount_local_micro=1500000&product_type=PROMOTED_TWEETS&placements=ALL_ON_TWITTER&objective=ENGAGEMENTS&entity_status=PAUSED" /9/accounts/xxxxxxx/line_items
{
  "data_type": "line_item",
  "data": {
    "bid_type": "MAX",
    "name": "Untitled",
    "placements": [
      "ALL_ON_TWITTER"
    ],
    "bid_amount_local_micro": 1500000,
    "automatically_select_bid": false,
    "advertiser_domain": null,
    "primary_web_event_tag": null,
    "charge_by": "ENGAGEMENT",
    "product_type": "PROMOTED_TWEETS",
    "bid_unit": "ENGAGEMENT",
    "total_budget_amount_local_micro": null,
    "objective": "ENGAGEMENTS",
    "id": "azjx",
    "entity_status": "PAUSED",
    "optimization": "DEFAULT",
    "categories": [],
    "currency": "USD",
    "created_at": "2015-02-09T00:00:00Z",
    "updated_at": "2015-02-09T00:00:00Z",
    "include_sentiment": "POSITIVE_ONLY",
    "campaign_id": "92ph",
    "deleted": false
  },
  "request": {
    "params": {
      "placements": [
        "ALL_ON_TWITTER"
      ],
      "bid_amount_local_micro": 1500000,
      "product_type": "PROMOTED_TWEETS",
      "entity_status": "PAUSED",
      "account_id": "xxxxxxx",
      "campaign_id": "92ph"
    }
  }
}
  1. Create a targeting profile associated with the line item.
With the line item created, we can assign targeting criteria. We want to target the phrase keywords “grumpy cat” in the San Francisco Bay Area location. This is going to require a location id lookup and two targeting_criteria POST requests.
twurl -H ads-api.x.com "/9/targeting_criteria/locations?location_type=CITIES&q=San Francisco"
{
  "data": [
    {
      "name": "San Francisco-Oakland-San Jose CA, US",
      "targeting_type": "LOCATION",
      "targeting_value": "5122804691e5fecc"
    }
  ],
  "data_type": "targeting_criterion",
  "request": {
    "params": {
      "location_type": "CITY",
      "q": "San Francisco"
    }
  }
}
twurl -H ads-api.x.com -X POST -d "line_item_id=yyyy&targeting_type=LOCATION&targeting_value=5122804691e5fecc" /9/accounts/xxxxxx/targeting_criteria
{
  "data": {
    "created_at": "2015-02-09T00:00:15Z",
    "deleted": false,
    "id": "2u3be",
    "line_item_id": "yyyy",
    "name": "San Francisco-Oakland-San Jose CA, US",
    "targeting_type": "LOCATION",
    "targeting_value": "5122804691e5fecc",
    "updated_at": "2013-05-30T21:01:35Z"
  },
  "data_type": "targeting_criterion",
  "request": {
    "params": {
      "account_id": "xxxxxx",
      "line_item_id": "yyyy",
      "targeting_type": "LOCATION",
      "targeting_value": "5122804691e5fecc"
    }
  }
}
twurl -H ads-api.x.com -X POST -d "line_item_id=yyyy&targeting_type=PHRASE_KEYWORD&targeting_value=grumpy cat" /9/accounts/xxxxxx/targeting_criteria
{
  "data": {
    "created_at": "2015-02-09T00:00:20Z",
    "deleted": false,
    "id": "2u3bd",
    "line_item_id": "yyyy",
    "name": "grumpy cat",
    "targeting_type": "PHRASE_KEYWORD",
    "targeting_value": "grumpy cat",
    "updated_at": "2013-05-30T18:05:35Z"
  },
  "data_type": "targeting_criterion",
  "request": {
    "params": {
      "account_id": "xxxxxx",
      "line_item_id": "yyyy",
      "targeting_type": "PHRASE_KEYWORD",
      "targeting_value": "grumpy cat"
    }
  }
}
  1. Finally, un-pause the line item.
twurl -H ads-api.x.com -X PUT "/9/accounts/xxxxxx/line_items/yyyy/?entity_status=ACTIVE"
{
  "data_type": "line_item",
  "data": {
    "bid_type": "MAX",
    "name": "grumpy cat",
    "placements": [],
    "bid_amount_local_micro": 1500000,
    "automatically_select_bid": false,
    "advertiser_domain": null,
    "primary_web_event_tag": null,
    "charge_by": "ENGAGEMENT",
    "product_type": "PROMOTED_TWEETS",
    "bid_unit": "ENGAGEMENT",
    "total_budget_amount_local_micro": null,
    "objective": "ENGAGEMENTS",
    "id": "yyyy",
    "entity_status": "ACTIVE",
    "optimization": "DEFAULT",
    "categories": [],
    "currency": "USD",
    "created_at": "2015-02-09T00:00:20Z",
    "updated_at": "2015-02-09T00:00:20Z",
    "include_sentiment": "POSITIVE_ONLY",
    "campaign_id": "dy1f",
    "deleted": false
  },
  "request": {
    "params": {
      "line_item_id": "yyyy",
      "entity_status": "ACTIVE",
      "account_id": "xxxxxx"
    }
  }
}
That’s it! We now have an active, targeted, and funded Promoted Tweets in Timelines campaign which is running.

Objective Based Campaigns

Objective-based campaigns and pricing allow advertisers to pay for the actions that are aligned with their marketing objectives. To support these, set the appropriate objective on line items. The parameter used on the line item write endpoints and returned on the read endpoints, is objective. This field has the following possible values as of today:
  • APP_ENGAGEMENTS
  • APP_INSTALLS
  • FOLLOWERS
  • ENGAGEMENTS
  • REACH
  • VIDEO_VIEWS
  • PREROLL_VIEWS
  • WEBSITE_CLICKS
Objectives impact how we optimize campaigns in our auctions and how we bill on those campaigns. We enable pricing based on objective, such as CPAC for APP_ENGAGEMENTS, CPAC or CPI for APP_INSTALLS, CPLC for WEBSITE_CLICKS, CPF for FOLLOWERS, CPE for ENGAGEMENTS, and CPM for REACH. Mobile app promotion campaigns are required to contain either the APP_ENGAGEMENTS or APP_INSTALLS objective. Note: Line items with different objectives are not allowed under the same campaign.
Campaign objectiveAPI objectiveMedia in TweetsPricing model
App re-engagementsAPP_ENGAGEMENTSImage or video app download card required.CPAC
App installsAPP_INSTALLSImage or video app download card required.CPAC or CPI (set using charge_by)
ReachREACHNo restrictions.CPM
FollowersFOLLOWERSTweet not required, but recommended. There are no media restrictions on Tweets for Followers campaigns, though we recommend text-only Tweets. More informationCPF
EngagementsENGAGEMENTSNo restrictions.CPE
Video ViewsVIDEO_VIEWSVideo conversation card, video, or GIF required.CPV or cost per 3s/100% view
Pre-roll viewsPREROLL_VIEWSVideo required.CPV or cost per 3s/100% view
Website ClicksWEBSITE_CLICKSWebsite card recommended, but not required. Tweet must have either a website card or a website link (not both).CPLC

Funding Instruments

Funding Instruments are the source of campaign budget. Funding Instruments can not be created via the Ads API, they have to be already established by the advertiser’s account manager at X (for credit lines) or via ads.x.com (for credit cards) to be available. To get a list of all funding_instruments on an account, see GET accounts/:account_id/funding_instruments and GET accounts/:account_id/funding_instruments/:funding_instrument_id for the details of a specific one.

Funding Instrument Attributes

Descriptive: account_id, funding instrument id, funding instrument typedescription, and io_header(insertion order header ID). Note that a single io_header may be associated with multiple funding instruments. Funding ability: able_to_fund and reasons_not_able_to_fund. Time: created_atupdated_atstart_time, and end_time represented by a string, formatted as “%Y-%m-%dT%l:%M:%S%z”. Boolean status: pauseddeleted, and cancelled (true or false). Financial: currency (ISO-4217 format), credit_limit_local_microcredit_remaining_local_micro, and funded_amount_local_micro. The value of a currency is represented in micros. For USD, $5.50 is encoded as 5.50*1e6, or 5,500,000. To represent a “whole value”, you need to multiply the local micro by 1e6 (1_000_000) for all currencies.

Attribute Details

credit_limit_local_micro is only valid for CREDIT_CARD or CREDIT_LINE type funding instruments and represents the credit limit for that instrument. funded_amount_local_micro is only valid for INSERTION_ORDER type funding instruments and represents the allocated budget. credit_remaining_local_micro is valid for CREDIT_LINE and AGENCY_CREDIT_LINE type funding instruments. It represents the credit_limit_local_micro minus the amount already spent on that funding instrument. It does not represent the difference between funded_amount_local_micro and the amount spent. We draw a distinction between credit limit and funded amount because they represent different underlying funding methods and spending agreements we have with advertisers.

Types of Funding Instruments

Credit Cards Typically used by self-serve advertisers (without an account manager). Credit Lines These are in the form of insertion orders (IOs) and are set by account managers. Multi-Handle Credit Lines Advertisers can fund campaigns across multiple handles with this type of credit line. This feature is enabled by their X Account Manager, associating the different @handles to a specific credit line. For example, @NikeSB and @NikeFuel can both have access to the @Nike credit line. This funding instrument is available just like any other. You retrieve the data by submitting a GET request to the funding_instrument endpoint. Here is a sample response (note the CREDIT_LINE type).
GET https://ads-api.x.com/5/accounts/a0b1c3/funding_instruments

{
"request": {
  "params": {
      "account_id": "a0b1c3"
  }
},
"data": [
  {
      "start_time": "2013-05-30T04:00:00Z",
      "description": "FakeNike - Credit Line",
      "credit_limit_local_micro": 150000000000,
      "end_time": null,
      "cancelled": false,
      "id": "i1234",
      "paused": false,
      "account_id": "a0b1c3",
      "reasons_not_able_to_fund": [],
      "io_header": null,
      "currency": "USD",
      "funded_amount_local_micro": 0,
      "created_at": "2013-05-30T18:16:38Z",
      "type": "CREDIT_LINE",
      "able_to_fund": true,
      "updated_at": "2013-05-30T18:16:38Z",
      "credit_remaining_local_micro": 123661919751,
      "deleted": false,
  }
],
"data_type": "funding_instrument",
"total_count": 1,
"next_cursor": null
}
The only thing particular about this funding instrument is the type and the fact that it is available to all the accounts that were associated to it. Of course, the remaining credit is impacted by all campaigns funded by this instrument, across all accounts sharing it. The details of what accounts are associated to a specific credit line are not available via the API (nor via ads.x.com). For more information on Funding Instrument enumerations, please click here.

Targeting

Targeting is a core concept of the Ads API. Targeting is set at the line item level and options vary across placements. To set new targeting criteria you need to use POST accounts/:account_id/targeting_criteria and PUT accounts/:account_id/targeting_criteria to update them. Use GET accounts/:account_id/line_items for a list of all line items and GET  accounts/:account_id/line_items/:line_item_id to retrieve a specific line item.

Targeting options by placement

Promoted Tweets and Promoted Accounts products can be made available on a variety of placements. Promoted Trends (PTr) are not available via the API. For possible placement combinations, refer to the GET line_items/placements endpoint. Each placement has different options for targeting. Location, Platform and Gender are available for all. The other options are contextual to the type of placement.
  • X Search: Age Targeting, Devices, Events, Gender, Keyword Types (All), Language, Locations, Network Activation, Network Operators, Platform, Platform Version, Tailored Audiences, WiFi Only
  • X Timeline: Age Targeting, Devices, Events, Followers Of, Similar to Followers Of, Gender, Interest, Language, Locations, Network Activation, Network Operators, Non-exact Keyword Types, Partner Audience Types, Platform, Platform Version, Retargeting Types, Tailored Audiences, TV Targeting Types, WiFi Only
  • X Profiles & Tweet Details: Age Targeting, Devices, Events, Followers Of, Similar to Followers Of, Gender, Interest, Language, Locations, Network Activation, Network Operators, Non-exact Keyword Types, Partner Audience Types, Platform, Platform Version, Retargeting Types, Tailored Audiences, TV Targeting Types, WiFi Only

Understanding targeting types

Age Targeting: Target users based on specific age buckets. A list of age bucket enums can be found on the Enumerations page. Events: Specify an event for targeting. Only one event can be used for targeting (per line item). Use the GET targeting_criteria/events endpoint to find events available for targeting. Gender: Target males (1) or females (2). Leave null to target all. Installed App Store Categories: use this targeting type to target users based on the categories of apps they have installed or have indicated interest in. See GET targeting_criteria/app_store_categories. Interests: Target users by interest. Get the interests list from GET targeting_criteria/interests. You can target up to 100 interests. Followers Of: Target the followers of any fully promotable users for the current account (note, currently the primary account holder is the only fully-promotable user of that account). GET accounts/:account_id/promotable_users to get a list of promotable users. Similar to Followers Of: Target people with the same interests as followers of specific users. You can use up to 100 Users. Locations: Specify up to 2,000 locations to target. Get list from GET targeting_criteria/locations. There are additional requirements for ads that target certain countries. See Country Targeting and Display Requirements for more information. Keywords: Keyword targeting options are specific by type of placement. You can use up to 1000 keywords for targeting (per line item). See the Keyword Types section for options. Language Targeting: Target users who understand specific languages. Mobile Network Operator Targeting: Enables advertisers to target users based on mobile carrier, using the targeting type NETWORK_OPERATOR from GET targeting_criteria/network_operators. New Mobile Device Targeting: Reach users based on the date that they first accessed X via their device, using the targeting type NETWORK_ACTIVATION_DURATION using operator_type of LT for less than and  GTE for greater than or equal. Platforms, Platform Versions, Devices, and Wifi-Only: Allows targeting of mobile devices across a variety of vectors. Platforms is a high-level targeting type that can hit broad categories of phone. Example values are iOS and Android. Devices allow you to target users of specific mobile devices, for example the iPhone 5s, Nexus 4, or Samsung Galaxy Note. Platform versions allow you to target users of versions of specific mobile operating systems, down to the point release. Examples include iOS 7.1 and Android 4.4. Wifi-Only allows you to target only those users who are using their devices on a WiFi network; if this is not set, users using the carrier connection as well as WiFi will be targeted.
  • Users can target platforms and devices if there is no overlap. I can target Blackberry as a platform and iPad Air as a device simultaneously.
  • Users can target devices and os versions simultaneously. I can target iPad Air and iOS >= 7.0.
  • Users cannot target platforms that are broader than devices. I cannot target iOS and iPad Air.
[Tailored Audiences]/x-ads-api/audiences: Reach users through an approved ads partner to target groups of customers and connect with them on X. TV Targeting TV Show Targeting: reach people that engage with specific TV programs. This targeting criteria can be configured to continuously target while a campaign is active with the TV_SHOW targeting type. Use the GET targeting_criteria/tv_markets and GET targeting_criteria/tv_shows endpoints to determine TV shows available. Tweet Engager Retargeting Tweet engager retargeting enables advertisers to target audiences across devices who have previously been exposed to or engaged with their promoted or organic Tweets on X. With this targeting advertisers can follow up with people who saw or engaged with an advertiser’s content on X and are most likely to further engage or convert with subsequent messaging or offers. Users will be eligible for targeting within minutes of exposure or engagement and will remain eligible for up to 90 days afterwards for engagements and 30 days for exposures. Tweet Engager Targeting Types:
  • ENGAGEMENT_TYPE which accepts either IMPRESSION or ENGAGEMENT as a targeting value. This specifies whether you wish to target exposed users (IMPRESSION) or engaged users (ENGAGEMENT).
  • CAMPAIGN_ENGAGEMENT uses a campaign ID as the targeting value. Users who engaged with or were exposed to this campaign (depending on ENGAGEMENT_TYPE) are the ones who will be targeted.
  • USER_ENGAGEMENT which uses the promoted user ID as the targeting value to target users who were exposed to or engaged with an advertiser’s organic content (depending on ENGAGEMENT_TYPE). This must be the promoted user ID associated with the Ads account.
Note: ENGAGEMENT_TYPE is required in addition to at least one valid CAMPAIGN_ENGAGEMENT or USER_ENGAGEMENT value. Both tweet engager targeting types may be present and multiple campaigns may be targeted on a given line item. Video Viewer Targeting: Video viewer targeting builds on Tweet engager targeting to enable advertisers to target audiences who have previously watched part or all of a video on X. Advertisers can target organic videos, promoted videos, or both. Promoted videos are not limited to video view objective campaigns or line items. Video Viewer Targeting Types:
  • VIDEO_VIEW for users who have clicked to play the video or have viewed 3 seconds of autoplay
  • VIDEO_VIEW_PARTIAL for users who have viewed 50% of the video
  • VIDEO_VIEW_COMPLETE for users who have viewed at least 95% of the video
As with Tweet engager targeting, one or both of the following must also be present in targeting criteria for the line item when ENGAGEMENT_TYPE is used:
  • CAMPAIGN_ENGAGEMENT uses a campaign ID as the targeting value. Users who watched a video (based on ENGAGEMENT_TYPE) in this campaign are the ones who will be targeted.
  • USER_ENGAGEMENT which uses the promoted user ID as the targeting value to target users who watched a video (based on ENGAGEMENT_TYPE) in an advertiser’s organic content. This must be the promoted user ID associated with the Ads account.
Keyword Types See our support document on keyword targeting for a conceptual overview.
  • Broad (default value): match all words, independent of order. Not sensitive to capitalization, plurals or tense. Will automatically be expanded when possible (i.e. “car repair” would also match “automobile fix”). If you want to target without expansion, you need to add a + sign before the keywords, like “+boat +jet”. Using keywords without the + will default to Broad Match.
  • Unordered (deprecated): match all words, independent of order. Not sensitive to capitalization, plurals or tense.
  • Phrase: match the exact keywords string, other keywords can be present.
  • Exact: match exactly the keywords string, not any others.
  • Negative: avoid matching searches that include all of these keywords somewhere in the query, regardless of the order in which they are written, even if other words are present.
  • Negative Phrase: avoid matching searches that include this exact keywords string somewhere in the query, even if other words are present.
  • Negative Exact: avoid matching searches that exactly match these keywords and contain no other words.  
Emoji targeting Emoji targeting is supported via keyword targeting. To use emoji targeting, simply create keyword targeting for Unicode codepoints representing that emoji such as U+1F602 (xF0x9Fx98x82 in UTF-8) for the ‘face with tears of joy’ emoji (😂). Emoji which we accept can be confirmed with the twemoji list. Targeting an emoji targets all variations. For a summary of all values with required/optional and specific details for each, see PUT accounts/:account_id/targeting_criteria.

Targeting Criteria Combinations

Updated Campaign Workflow Create campaigns which target broadly with geo, gender, language, and device/platform criteria. Advertisers can then combine the broad targeting with additional targeting criteria (e.g. interests, keywords, followers, tailored audiences, TV). If no targeting criteria is specified for a line item, the line item will target all users worldwide.
“Primary” TypesOther Types
FollowersLocations
Tailored AudiencesGender
InterestsLanguages
KeywordsDevices and platforms
TVAge
Targeting criteria will be combined for your ad group such that:
  • “Primary” Targeting Types will get ‘d (i.e. put in a logical union).
  • Other Targeting Types will get AND‘d.
  • Same types will get OR‘d.
Some examples At a glance: [(Followers) ∪ (Tailored Audiences) ∪ (Interests) ∪ (Keywords)] AND (Location) AND (Gender) AND (Languages) AND (Devices and Platforms) A Geo example: Let’s say we want an ad group for our campaign to serve targeting:
  • X users in the U.S., England, and Canada (Location)
  • who are Women (Gender)
  • derived from Tailored Audiences list (“Primary”)
  • with Keywords (“Primary”)
The targeting criteria will be: [US OR GB OR CA] AND [Female] AND [Tailored AudiencesKeyword]

Additional examples

  • Select Gender and Geo but no primary: (Male) AND (US OR GB)
  • Select Gender, Geo, Interest: (Female) AND (CA) AND (Computers OR Technology OR Startups)
  • Select Gender, Geo, Interest, Tailored Audiences, Keywords: (Male) AND (GB) AND (CarsTailored Audiences for CRMautocross)

Budget Pacing

Advertisers now have more control over how fast their daily budgets are spent on your Promoted Tweet and Account campaigns. Enabling standard delivery, which is the default, ensures an even spend rate throughout the day. By turning off standard delivery, we will serve impressions and generate engagements as quickly as possible until your daily budget is exhausted, which may be quite early on in the day depending on targeting and competition. This is called accelerated delivery. Getting Started Standard delivery is the default option for all campaigns, so no action is required unless you wish to turn it off. To spend through your daily budget on a campaign as fast as possible set the standard_delivery parameter to false to set the pace to accelerated delivery (see GET accounts/:account_id/campaigns). Notes
  • “Day” is respective to X advertiser account timezone (eg. America/Los_Angeles).
  • Early results indicate that standard delivery will improve eCPE/CPF for advertisers, with more consistent coverage throughout the day.
For more additional information about budgets and pacing please see the Bidding and Auctions FAQ.

Target Bidding

Campaign management

Bid Strategy

We have introduced the concept of Bid Strategy to simplify campaign creation workflow and reduce confusion about combinations of multiple parameters. All previous (marked as legacy) combinations of parameters can be achieved by setting an equivalent goal parameter. Further information can be found in the announcement here. As example:
Campaign ObjectiveLegacyAds API v10+
App Installsbid_type= AUTO

bid_unit = APP_INSTALLS

charge_by = APP_CLICKS
goal = APP_INSTALLS

bid_strategy = AUTO
Website Clicksbid_type = TARGET (Note: bid_unit was not needed for some campaign objectives)bid_strategy = TARGET

Target Bidding

Using target bidding, you can specify a target cost you want to pay and the X Ads platform will optimize your campaign for performance while staying near or below your target cost. This feature gives you the flexibility to reach users who are especially likely to take the desired action (such as a link click, a lead or a follow) while maintaining cost control. This is a powerful feature for advertisers who desire more options for campaign setup and optimization (including bidding options). For line items with compatible campaign objectives, we’ve introduced a new pricing mechanism for bid amount that lets you specify a target cost you want to pay. Our ad platform dynamically bids on your behalf to help you drive more results, while working to keep your average cost within 20% of your specified target. The bid_strategy setting on line items may be set with a value of TARGET to enable target bidding on relevant campaign objectives, such as:
  • WEBSITE_CLICKS
  • WEBSITE_CONVERSIONS 
  • APP_INSTALLS 
  • APP_ENGAGEMENTS
  • REACH

Country Targeting and Display Requirements

Campaign management Country-specific targeting and display requirements are contained on this page. These requirements must be adhered to by all partners.

Russia

X’s Ads Policies prohibit advertisers from targeting Russia with advertisements that are not in the Russian language. When your users specifically target Russia, you must display the following warning message to your users: Ads targeting Russia must be in the Russian language.

Partner Managed Funding Instruments

The onboarding flow configures an ads.x.com account for the X account, which can be managed by the partner through the Ads API, and whose advertising spend is billed to the partner.  

Partner Initial Set-up

The process to initially set-up a new PMFI Ads API partner takes up to 3-weeks from exchange of required information. The following must be shared with your technical contacts at X, as well as the X contact managing the integration with the partner in order to get the process started:
  • The partner must share their PGP/GPG public key. A shared secret key needs to be exchanged between the Ads API partner and X. This will be used to verify data during the onboarding flow.
  • The app_id or consumer_secret for the X app that will be used for Ads API access. You can view and edit your existing X apps via the app dashboard if you are logged into your X account on developer.x.com. If you need to create a X app, you will need to have an approved developer account. X allows one app for production+sandbox and one optional app for sandbox-only access. The X app must be created on a corporate, partner-controlled X handle.  

Advertiser Onboarding Flow

The advertiser onboarding flow occurs via a web browser in the following way:
  1. The user starts the onboarding flow on the partner’s website and enters the handle they want to onboard.
  2. The partner redirects the user to a URL on ads.x.com with a signed payload. This payload contains the partner’s API app_id, the X user_id of the X handle which is to be onboarded and a callback URL and other fields documented below.
  3. The user is asked to sign into ads.x.com using the standard x.com login page.
  4. Once the user is logged in, the onboarding process is initiated. This step includes ad review, account validation and other checks.
  5. When all onboarding tasks are completed, the user is redirected to the callback URL that was provided by the Ads API partner, with a payload that indicates success or failure. This includes the 3-legged authorization process.  

Onboarding redirect payload

URL for redirect: https://ads.x.com/link\_managed\_account The redirect URL will be called with the following parameters:
NameTypeDescription
callback_urlURL encoded stringuser will be redirected to this url after the account link process completes, regardless of outcome. See the partner redirect url section for protocol details
client_app_idintegerX API client app id, used to identify the managing partner
promotable_user_idintegerX user_id of the @handle whose promotions are to be managed by the managing partner. Used to make sure it is the same as the user who logs into ads.x.com to complete the linking process
fi_descriptionURL encoded String (max 255 characters)funding instrument name. This will be displayed in the description field in the API when the funding instrument is retrieved. If a funding_instrument description is given, the existing funding_instrument will be paused, and a new managed partner funding instrument will be set up. (if one exists with the same name, nothing will happen)
timezoneString, in Area/Location formatThis will be the timezone used to determine the day to which daily budgets apply, and in which charges will be aggregated
currencyISO 4217 Currency CodeCurrency that will be used to enter bids, and in which charges will be billed
countryISO 3166-1 alpha 2 Country CodeBilling Country for the account
signatureURL encoded, base64 encoded binary code, as explained belowsignature that combines a shared secret and the other parameters to verify authenticity of the call, as well as validity of the parameters.

Callback URL payload

The base redirect URL is provided using the callback_url parameter on the account link request (see above). The parameters added by ads.x.com are:
NameTypeDescription
statusstringOK an account was created, or an existing, eligible account was found.

ACCOUNT_INELIGIBLE if partner specific constraints are not met USER_MISMATCH the X account used to sign into ads.x.com was different from the promotable_user_id on the account link request INCOMPLETE_SERVING_BILLING_INFO timezone, currency or country were not specified INVALID_COUNTRY an invalid country value was given INVALID_CURRENCY an invalid currency value was given INVALID_TIMEZONE an invalid timezone value was given
account_idURL encoded stringX ads account id of the linked account
funding_instrument_idURL encoded stringID of the active partner managed funding instrument
signatureURL encoded, base64 encoded binary code, as explained belowBase64 encoded HMAC-SHA1 signature that combines a shared secret and the other parameters to verify authenticity of the call, as well as validity of the parameters. To make sure the callback url is only valid for the X user_id that the account link process was intended for, the X user_id is to be appended to the shared secret (using &) when signing the request.
To make sure the callback URL is only valid for the X user_id that the account link process was intended for, the X user_id is to be appended to the shared secret (using &) when signing the request.  

Signing the request and callback URLs

In order to ensure that the requests to /link_managed_account and the callback url are valid, the requests need to be signed at the source and verified by the recipient before the recipient takes action on them. Signing the request with a secret that is shared between X and the managing partner ensures that each party only accepts requests sent by the authorized counterpart. The signature generation algorithm is similar to the one used in OAuth. Create a signature base string as follows:
  • Convert the HTTP Method to uppercase and set the base string equal to this value.
  • Append the ‘&’ character to the base string.
  • Percent encode the URL (without parameters) and append it to the base string.
  • Append the ‘&’ character to the base string.
  • Append the percent encoded query string, which is built as follows:
  • Percent encode every key and value that will be signed.
  • Sort the list of parameters alphabetically by key.
  • For each key/value pair (and with primary_promotable_user_id for the partner redirect url):
  • Append the percent encoded key to the query string.
  • Append the ‘=’ character to the base string.
  • Append the percent encoded value to the query string.
  • Separate the percent encoded key=value pairs with the ‘&’ character.
  • Use the HMAC-SHA1 algorithm, using the previously exchanged shared secret, as the key, and the base string as the value to generate the signature.
  • Base64 encode the output of Step 2, drop the trailing newline character percent encode the signature generated in Step 3 and add it to the url in a signature parameter  

Signing examples

Signing a link account request Url to sign, assuming a GET request: https://ads.x.com/link\_managed\_account?callback\_url=https%3A%2F%2Fmanagingpartner.com%2Flink\_account\_callback&client\_app\_id=12345&fi\_description=some%20name&promotable\_user\_id=1 This url has the following parameters: callback_url = https://managingpartner.com/link\_account_callback client_app_id = 12345 fi_description = some name promotable_user_id = 1 The base string consisting of http method and url without parameters, steps a - d, looks like: GET https://ads.x.com/link\_managed\_account The query string, produced by the substeps of e, looks like: callback_url=https://managingpartner.com/link\_account\_callback&client\_app\_id=12345&fi\_description=some name&promotable_user_id=1 Note that the key-value pairs are sorted by key name. The percent encoded query string looks like: callback_url%3Dhttps%253A%252F%252Fmanagingpartner.com%252Flink_account_callback%26client_app_id%3D12345%26fi_description%3Dsome%2520name%26promotable_user_id%3D1 The complete base string, combining steps a - d and e: GET https://ads.x.com/link\_managed\_account&callback\_url%3Dhttps%253A%252F%252Fmanagingpartner.com%252Flink\_account\_callback%26client\_app\_id%3D12345%26fi\_description%3Dsome%2520name%26promotable\_user\_id%3D1 Using the hmac-sha1 algorithm we will sign this with the word “secret” as the key. The result is Base64 encoded, and presented without the final “\n” (steps 2 and 3): KBxQMMSpKRrtg9aw3qxK4fTXvUc= This signature is then added (percent encoded) to the end of the original url in the signature parameter (step 4): https://ads.x.com/link\_managed\_account?callback\_url=https%3A%2F%2Fmanagingpartner.com%2Flink\_account\_callback&client\_app\_id=12345&fi\_description=some%20name&promotable\_user\_id=1&signature=KBxQMMSpKRrtg9aw3qxK4fTXvUc%3D Signing a partner redirect url (account link request callback) The URL to sign, assuming a GET request: https://managingpartner.com/link\_account\_callback?status=OK&account\_id=ABC&funding\_instrument_id=DEF This url has the following parameters: account_id = ABC, funding_instrument_id = DEF and status = OK The base string consisting of http method and url without parameters, steps a - d, looks like: GET https%3A%2F%2Fmanagingpartner.com%2Flink_account_callback&“ The query string, produced by the substeps of e, looks like: account_id=ABC&funding_instrument_id=DEF&status=OK The percent encoded query string looks like: account_id%3DABC%26funding_instrument_id%3DDEF%26status%3DOK The complete base string, combining steps a - d and e: GET https%3A%2F%2Fmanagingpartner.com%2Flink_account_callback&account_id%3DABC%26funding_instrument_id%3DDEF%26status%3DOK Using the hmac-sha1 algorithm we will sign this with the word “secret” and the X user id for which the original link request was made, 1 (promotable_user_id = 1 from above) as the key, “secret&1”. The result is Base64 encoded, and presented without the final “\n” (steps 2 and 3): jDSHDkHJIFXpPLVxtA3a9d4bPjM= This signature is then added (percent encoded) to the end of the original url in the signature parameter (step 4): https://managingpartner.com/link\_account\_callback?&status=OK&account\_id=ABC&funding\_instrument_id=DEF&signature=jDSHDkHJIFXpPLVxtA3a9d4bPjM%3D

Shared Key use / renewal

The signing algorithm should have the ability to repeat itself with multiple keys. This will allow multiple shared keys to be used, and enables cycling shared keys on a periodic basis.  

partner_managed_funding_instrument creation

If the fi_description parameter is given, and no existing partner_managed_funding_instrument with the same name exists in the account, a new partner_managed_funding_instrument will be created, and all existing partner_managed_funding_instruments will be paused. If a partner_managed_funding_instrument with the same name exists, no new one will be created.  

Repeated on-boarding flow calls / token refresh

The on-boarding flow can be repeated in case the API access token was lost. The on-boarding flow implementation will require the user is logged in. If the user matches the promotable_user_id, and the associated ads account is found, and everything looks good, the user will be redirected back to the callback url, and the partner can initiate the OAuth flow to obtain an access token.  

Non-redirectable error flow

If the account link url is invoked with invalid parameters, the user will be shown a page similar to the one shown in the OAuth flow when invalid or expired parameters are given.  

Ongoing updates to the PMFI

Once the advertiser has been onboarded, the funding instrument can be managed using the PUT accounts/:account_id/funding_instruments/:funding_instrument_id endpoint by only the partner who manages it.

Placements

There are several places where X ads can be displayed. This is set at the line item using the placements parameter. The possible values are:
  • ALL_ON_TWITTER
  • PUBLISHER_NETWORK
  • TWITTER_PROFILE
  • TWITTER_SEARCH
  • TWITTER_TIMELINE
  • SPOTLIGHT
  • TREND
The line item’s product_type and objective determine which placements are allowed. The GET line_items/placements endpoint can be used to retrieve the valid placement options for each product type. Additionally, the following table lists the valid placement and objective combinations.
ObjectiveALL_ON_TWITTERTWITTER_PROFILETWITTER_SEARCHTWITTER_TIMELINE
APP_ENGAGEMENTS
APP_INSTALLS
REACH
FOLLOWERS
ENGAGEMENTS
VIDEO_VIEWS
PREROLL_VIEWS
WEBSITE_CLICKS
Note: It is not possible to specify only TWITTER_PROFILE placement. Note: TWITTER_SEARCH requires keyword targeting. Note: The REACH objective must include TWITTER_TIMELINE placement. It can have either ALL_ON_TWITTER, any combination of placements that include TWITTER_TIMELINE, or TWITTER_TIMELINE on its own.

Ad groups FAQ

This document is meant to be a collection of commonly asked questions about Ad Groups in X’s Ads API.

What is an Ad Group?

Ad groups, known as line items in the Ads API, exist under campaigns and are used for targeting and bidding against a set of X users. Advertisers promote Tweets or media (e.g., videos that are promoted as In-stream ads) by associating them with a line item.

How do we create an Ad Group?

Ad Groups are created by calling POST accounts/:account_id/line_items multiple times for the same campaign ID, and keeping (possibly completely different) targeting and Tweets associated with those line items. There is a limit of 100 line items per campaign and a limit of 200 active campaigns for a single ads account. Across all campaigns, there is a limit of and 8,000 active line items per ads account.

Why should we add support for Ad Groups?

Ad Groups are intended to make it easier for advertisers to organize, optimize and manage their campaigns. The advantage of Ad Groups is to compare and control different strategies across bid, budget, creative, and targeting. Upon associating multiple Promoted Tweets to a single line item, the auction would select the best Tweet from that group and then select the best Tweet for that campaign from all of the line items. If you have multiple Ad Groups with single Tweets, it would effectively select the Tweet that would likely perform better from that Ad Group. Using Ad Groups enables an advertiser to split up targeting and bidding into a much greater number of possible combinations, and in general allows splitting up targeting into logical groups. Ads API tools in particular could be built around fine tuned optimization rules with Ad Groups that would be more difficult to do via manual edits due to the larger scale of line item and creative combinations.

How does the line item budget relate to campaign budget in an Ad Groups campaign?

The total_budget_amount_local_micro for a line item cannot exceed the total budget for its parent campaign. Similarly, the line item’s bid_amount_local_micro value should not exceed daily_budget_amount_local_micro or total_budget_amount_local_micro of the parent campaign. Setting these values incorrectly may put the overall campaign into a paused and unservable state. Note that the total campaign budget can be less than the sum of the budgets of its child line items, and distribution of budget between line items is partially up to the Ads API tool to effectively optimize and change as daily performance of targeting (line item) could differ significantly day to day due to X’s realtime nature.

Do Ad Groups perform better than single line items?

The performance of a campaign depends upon many factors and effectively a Tweet is the final deciding factor of performance. A Line Item will be treated as a factor of whether or not a Tweet is even in the running to be served to a user. Line items that target the same sets of users are considered to have overlap of users. It is considered a best practice to reduce this overlap of targeting between line items so that the highest performing sets of users can be clearly identified.

Guides

Video Views Preroll Objective

The following guide outlines the steps required to set up a PREROLL_VIEWS campaign on the Ads API. Broadly speaking these campaigns are split into two types, Curated Categories and Content Categories (referred to as Standard Categories on the Ads UI).  

Endpoints Required

Steps

Upload the video

Uploading the video involves 2 steps:

Upload the video media

First, using the Chunked media upload endpoint, you will upload the video to X for processing. You must pass the media_category=amplify_video on the initial INIT using this endpoint. You’ll upload the video in chunks. Once the STATUS returns a state of succeeded you may continue with the next steps. More on the uploading of media using the chunked endpoint can be found in our Promoted Video Overview.

Add the video to the ads account

Once the state returned using the STATUS command is succeeded, you’ll use the media_key returned from that endpoint to add the video to the advertiser’s media library, using the POST accounts/:account_id/media_library endpoint.
POST https://ads-api.x.com/8/55w3kv/media\_library?media\_key=3_931236738554519552

{
 "request": {
   "params": {
     "account_id": "55w3kv",
     "media\_key": "3\_931236738554519552"
   }
 },
 "data": {
   "tweeted": false,
   "name": null,
   "file_name": null,
   "media\_url": "https://video.twimg.com/amplify\_video/1059840836186165250/vid/568x320/Gr2l1fB1X7xotKwC.mp4?tag=8",
   "media\_category": "AMPLIFY\_VIDEO",
   "media\_key": "3\_931236738554519552",
   "created_at": "2017-11-16T19:05:14Z",
   "media\_status": "TRANSCODE\_COMPLETED",
   "media_id": 931236738554519552,
   "media_type": "VIDEO",
   "updated_at": "2017-11-16T19:05:23Z",
   "deleted": false
 }
}

Setup the campaign

Campaign Creation

Create the campaign and line item/ad group. Line items should be created with an objective of VIDEO_VIEWS_PREROLL, and a product_type of MEDIA. The categories parameter must also be set to the appropriate advertiser business categories.
POST https://ads-api.x.com/8/accounts/55w3kv/campaigns?name=test-curated-categories-api&funding\_instrument\_id=103hp9&start\_time=2021-02-10&entity\_status=PAUSED&daily\_budget\_amount\_local\_micro=55000000

{
  "request": {
    "params": {
      "name": "test-curated-categories-api",
      "start_time": "2021-02-10T00:00:00Z",
      "daily\_budget\_amount\_local\_micro": 55000000,
      "funding\_instrument\_id": "103hp9",
      "entity_status": "PAUSED",
      "account_id": "55w3kv"
    }
  },
  "data": {
    "name": "test-curated-categories-api",
    "start_time": "2021-02-10T00:00:00Z",
    "reasons\_not\_servable": \[
      "EXPIRED",
      "PAUSED\_BY\_ADVERTISER",
      "FUNDING_PROBLEM"
    \],
    "servable": false,
    "purchase\_order\_number": null,
    "effective_status": "PAUSED",
    "daily\_budget\_amount\_local\_micro": 55000000,
    "end_time": null,
    "funding\_instrument\_id": "103hp9",
    "duration\_in\_days": null,
    "standard_delivery": true,
    "total\_budget\_amount\_local\_micro": null,
    "id": "f2rp3",
    "entity_status": "PAUSED",
    "frequency_cap": null,
    "currency": "USD",
    "created_at": "2021-02-08T23:55:38Z",
    "updated_at": "2021-02-08T23:55:38Z",
    "deleted": false
  }
}

Line Item Creation

Line items must have the categories parameter set to the appropriate set of IAB categories, retrieved via the GET content_categories endpoint. These content categories each correspond to one or more IAB categories. In order to use these values, partners must select an appropriate content category and use the entire set of iab_categories returned in the response, to set the categories parameter on the line items endpoint. Any partial application of the iab_categories will result in the entire group being set on the line item. For example,
GET https://ads-api.x.com/8/advertiser\_business\_categories

{
  "request": {
    "params": {}
  },
  "next_cursor": null,
  "data": \[
    {
      "id": "1jl",
      "name": "Consumer Packaged Goods",
      "iab_categories": \[
        "IAB9-26",
        "IAB9-18",
        "IAB9-29",
        "IAB9-1",
        "IAB9-8",
        "IAB9-22",
        "IAB6",
        "IAB9-5",
        "IAB9-12",
        "IAB9-11",
        "IAB9-23",
        "IAB9-14",
        "IAB4",
        "IAB9-25",
        "IAB9-17",
        "IAB23",
        "IAB9-24",
        "IAB9-13",
        "IAB16",
        "IAB9-4",
        "IAB9-9",
        "IAB9-20",
        "IAB22",
        "IAB9-28",
        "IAB9-27",
        "IAB9-16",
        "IAB9-31",
        "IAB9-3",
        "IAB9-19",
        "IAB10",
        "IAB9-2",
        "IAB9-6",
        "IAB9-21",
        "IAB9-10",
        "IAB9-15"
      \]
    },
    {
      "id": "1jm",
      "name": "Health & Pharma",
      "iab_categories": \[
        "IAB7"
      \]
    },
    {
      "id": "1jn",
      "name": "Alcohol",
      "iab_categories": \[
        "IAB8-5",
        "IAB8-18"
      \]
    },
    {
      "id": "1jo",
      "name": "Dining",
      "iab_categories": \[
        "IAB8-10",
        "IAB8-8",
        "IAB8-7",
        "IAB8-15",
        "IAB8-3",
        "IAB8-4",
        "IAB8-1",
        "IAB8-16",
        "IAB8-12",
        "IAB8-13",
        "IAB8-17",
        "IAB8-11",
        "IAB8-6",
        "IAB8-9",
        "IAB8-2",
        "IAB8-14"
      \]
    },
    {
      "id": "1jp",
      "name": "Financial Services",
      "iab_categories": \[
        "IAB3",
        "IAB13",
        "IAB21"
      \]
    },
    {
      "id": "1jq",
      "name": "Retail",
      "iab_categories": \[
        "IAB18"
      \]
    },
    {
      "id": "1jr",
      "name": "Travel",
      "iab_categories": \[
        "IAB20"
      \]
    },
    {
      "id": "1js",
      "name": "Gaming",
      "iab_categories": \[
        "IAB9-30"
      \]
    },
    {
      "id": "1jt",
      "name": "Technology",
      "iab_categories": \[
        "IAB19-22",
        "IAB19-13",
        "IAB19-4",
        "IAB19-33",
        "IAB19-26",
        "IAB19-3",
        "IAB19-16",
        "IAB19-9",
        "IAB19-32",
        "IAB19-25",
        "IAB19-30",
        "IAB19-36",
        "IAB19-21",
        "IAB5",
        "IAB19-12",
        "IAB19-28",
        "IAB19-17",
        "IAB19-8",
        "IAB19-7",
        "IAB19-24",
        "IAB15",
        "IAB19-11",
        "IAB19-31",
        "IAB19-20",
        "IAB19-15",
        "IAB19-1",
        "IAB19-35",
        "IAB19-29",
        "IAB19-34",
        "IAB19-23",
        "IAB19-2",
        "IAB19-5",
        "IAB19-14",
        "IAB19-27",
        "IAB19-10",
        "IAB19-19"
      \]
    },
    {
      "id": "1ju",
      "name": "Telecommunication",
      "iab_categories": \[
        "IAB19-6",
        "IAB19-18"
      \]
    },
    {
      "id": "1jv",
      "name": "Auto",
      "iab_categories": \[
        "IAB2"
      \]
    },
    {
      "id": "1jw",
      "name": "Media & Entertainment",
      "iab_categories": \[
        "IAB14-8",
        "IAB14-4",
        "IAB1-5",
        "IAB14-7",
        "IAB1-7",
        "IAB17",
        "IAB14-3",
        "IAB1-1",
        "IAB12",
        "IAB1-6",
        "IAB25-1",
        "IAB1-2",
        "IAB14-2",
        "IAB14-6",
        "IAB1-3",
        "IAB1-4",
        "IAB14-5"
      \]
    },
    {
      "id": "1jx",
      "name": "Politics",
      "iab_categories": \[
        "IAB11-4"
      \]
    },
    {
      "id": "1jy",
      "name": "Gambling",
      "iab_categories": \[
        "IAB9-7"
      \]
    },
    {
      "id": "1jz",
      "name": "Dating",
      "iab_categories": \[
        "IAB14-1"
      \]
    },
    {
      "id": "1k0",
      "name": "Non-Profit",
      "iab_categories": \[
        "IAB11-1",
        "IAB11-2",
        "IAB11-3",
        "IAB11-5"
      \]
    }
  \]
}
Now, in order to set the categories parameter to “Science & Education”, the entire set of iab_categories i.e., "IAB5", "IAB15" must be set for the line item, like so:
POST https://ads-api.x.com/8/accounts/55w3kv/line\_items?campaign\_id=f2rp3&bid\_amount\_local\_micro=5500000&name=curated-category-line-item&product\_type=MEDIA&placements=ALL\_ON\_TWITTER&objective=PREROLL_VIEWS&categories=IAB3,IAB13,IAB21

{
  "request": {
    "params": {
      "name": "curated-category-line-item",
      "placements": \[
        "ALL\_ON\_TWITTER"
      \],
      "bid\_amount\_local_micro": 5500000,
      "product_type": "MEDIA",
      "objective": "PREROLL_VIEWS",
      "account_id": "55w3kv",
      "categories": \[
        "IAB3",
        "IAB13",
        "IAB21"
      \],
      "campaign_id": "f2rp3"
    }
  },
  "data": {
    "bid_type": "MAX",
    "advertiser\_user\_id": 312226591,
    "name": "curated-category-line-item",
    "placements": \[
      "ALL\_ON\_TWITTER"
    \],
    "start_time": null,
    "bid\_amount\_local_micro": 5500000,
    "automatically\_select\_bid": false,
    "advertiser_domain": null,
    "target\_cpa\_local_micro": null,
    "raw_categories": \[
      "x",
      "5l",
      "9z"
    \],
    "primary\_web\_event_tag": null,
    "charge\_by": "VIEW\_3S_100PCT",
    "product\_type": "PROMOTED\_TWEETS",
    "end_time": null,
    "duration\_in\_days": null,
    "bid\_unit": "VIEW\_3S_100PCT",
    "total\_budget\_amount\_local\_micro": null,
    "objective": "PREROLL_VIEWS",
    "id": "iqwka",
    "entity_status": "ACTIVE",
    "automatic\_tweet\_promotion": null,
    "optimization": "DEFAULT",
    "frequency_cap": null,
    "android\_app\_store_identifier": null,
    "categories": \[
      "IAB3",
      "IAB13",
      "IAB21"
    \],
    "currency": "USD",
    "created_at": "2021-02-09T00:00:46Z",
    "tracking_tags": \[\],
    "ios\_app\_store_identifier": null,
    "amplify_config": {
      "auto_promote": true,
      "is_open": true
    },
    "updated_at": "2021-02-09T00:00:46Z",
    "campaign_id": "f2rp3",
    "creative_source": "MANUAL",
    "deleted": false
  }
}

Publisher Selection

An advertiser may choose to target either a Content Category or a Curated Category, with additional details described below.  Note:  Line items may target either Curated or Content  Categories but not both. 

Curated Categories

Curated Categories allow advertisers to target a preset group of publishers and can be retrieved using the  GET curated_categories endpoint. These categories are country specific, and therefore require that the line item target the appropriate country based on the country_code of the category. In order to use one of these categories, the following steps are required in the specific order listed:
  1. The line item needs to target the appropriate country based on the country_code of the Curated Category
  2. The POST line_item_curated_categories endpoint must be used to associate the line item with a specific curated_category_id. 
Note: Associating a line item with a curated category will also limit the number of publishers that can be denylisted to 5. The full list of user_id used to denylist specific publishers can be retrieved from the GET publishers endpoint. Additionally, a given line item may target no more than one Curated Category at a time. The following example illustrates how to associate a curated category id: b0xt which is only available in the US, with the line item created in the previous step. First, the line item’s targeting criteria is set to the the value 96683cc9126741d
GET https://ads-api.x.com/8/targeting\_criteria/locations?country\_code=US&location_type=COUNTRIES

{
  "data": \[
    {
      "name": "United States",
      "country_code": "US",
      "location_type": "COUNTRIES",
      "targeting_value": "96683cc9126741d1",
      "targeting_type": "LOCATION"
    }
  \],
  "request": {
    "params": {
      "location_type": "COUNTRIES",
      "country_code": "US"
    }
  },
  "next_cursor": null
}

POST https://ads-api.x.com/8/batch/accounts/55w3kv/targeting_criteria
\[
  {
    "operation_type": "Create",
    "params": {
      "line\_item\_id": "iqwka",
      "targeting_type": "LOCATION",
      "targeting_value": "96683cc9126741d1",
      "operator_type": "EQ"
    }
  }
\]

{
  "data": \[
    {
      "line\_item\_id": "iqwka",
      "name": "United States",
      "raw_negated": false,
      "raw\_targeting\_value": "2",
      "id": "rv9hmc",
      "raw\_targeting\_type": "GEO",
      "raw\_operator\_type": "EQUAL_TO",
      "location_type": "COUNTRIES",
      "operator_type": "EQ",
      "created_at": "2021-02-09T00:06:28Z",
      "targeting_value": "96683cc9126741d1",
      "updated_at": "2021-02-09T00:06:28Z",
      "deleted": false,
      "targeting_type": "LOCATION"
    }
  \],
  "request": \[
    {
      "params": {
        "line\_item\_id": "iqwka",
        "account_id": "55w3kv",
        "operator_type": "EQ",
        "targeting_value": "96683cc9126741d1",
        "targeting_type": "LOCATION"
      },
      "operation_type": "Create"
    }
  \]
}

POST https://ads-api.x.com/8/accounts/55w3kv/line\_item\_curated\_categories?line\_item\_id=iqwka&curated\_category_id=9ddrgesiap6o

{
  "request": {
    "params": {
      "curated\_category\_id": "9ddrgesiap6o",
      "line\_item\_id": "iqwka",
      "account_id": "55w3kv"
    }
  },
  "data": {
    "line\_item\_id": "iqwka",
    "curated\_category\_id": "9ddrgesiap6o",
    "id": "xq",
    "created_at": "2021-03-30T17:26:42Z",
    "updated_at": "2021-03-30T17:26:42Z",
    "deleted": false
  }
}

Content Categories

Content categories, also referred to as Standard Categories can be retrieved from the GET curated_categories endpoint. These categories can then be targeted by the line item using the batch targeting criteria endpoints. The following example illustrates how to select a particular content category, id: sr which maps to “News & Current Events” and apply it to the line item.
Note: The entire set of iab_categories in the GET curated_categories response must be targeted via the targeting criteria endpoint. Failing to do so will result in a validation error. 
GET https://ads-api.x.com/8/content_categories
{
      "name": "News & Current Events",
      "id": "sr",
      "iab_categories": \[
        "IAB12",
        "IAB14"
      \],
      "publishers\_in\_last\_thirty\_days": 124,
      "videos\_monetized\_in\_last\_thirty_days": 5429
    }
}

POST https://ads-api.x.com/8/batch/accounts/55w3kv/targeting_criteria
\[
  {
    "operation_type": "Create",
    "params": {
      "line\_item\_id": "iqwls",
      "targeting\_type": "IAB\_CATEGORY",
      "targeting_value": "IAB12",
      "operator_type": "EQ"
    }
  },
  {
    "operation_type": "Create",
    "params": {
      "line\_item\_id": "iqwls",
      "targeting\_type": "IAB\_CATEGORY",
      "targeting_value": "IAB14",
      "operator_type": "EQ"
    }
  }
\]

{
  "data": \[
    {
      "line\_item\_id": "iqwls",
      "name": "News",
      "raw_negated": false,
      "raw\_targeting\_value": "5h",
      "id": "saib9p",
      "raw\_targeting\_type": "IAB_CATEGORY",
      "raw\_operator\_type": "EQUAL_TO",
      "operator_type": "EQ",
      "created_at": "2021-03-30T17:35:50Z",
      "targeting_value": "IAB12",
      "updated_at": "2021-03-30T17:35:50Z",
      "deleted": false,
      "targeting\_type": "IAB\_CATEGORY"
    },
    {
      "line\_item\_id": "iqwls",
      "name": "Society",
      "raw_negated": false,
      "raw\_targeting\_value": "5y",
      "id": "saib9q",
      "raw\_targeting\_type": "IAB_CATEGORY",
      "raw\_operator\_type": "EQUAL_TO",
      "operator_type": "EQ",
      "created_at": "2021-03-30T17:35:50Z",
      "targeting_value": "IAB14",
      "updated_at": "2021-03-30T17:35:50Z",
      "deleted": false,
      "targeting\_type": "IAB\_CATEGORY"
    }
  \],
  "request": \[
    {
      "params": {
        "line\_item\_id": "iqwls",
        "account_id": "55w3kv",
        "operator_type": "EQ",
        "targeting_value": "IAB12",
        "targeting\_type": "IAB\_CATEGORY"
      },
      "operation_type": "Create"
    },
    {
      "params": {
        "line\_item\_id": "iqwls",
        "account_id": "55w3kv",
        "operator_type": "EQ",
        "targeting_value": "IAB14",
        "targeting\_type": "IAB\_CATEGORY"
      },
      "operation_type": "Create"
    }
  \]
}
Associate the account media (video) with the line item
Use the POST accounts/:account_id/media_creatives endpoint to associate the video with an ad group.
POST https://ads-api.x.com/8/accounts/55w3kv/media_creatives
line\_item\_id=4bii5&account\_media\_id=knb

{
 "data":{
   "account\_media\_id":"74g",
   "approval_status":"ACCEPTED",
   "created_at":"2016-02-11T22:23:23Z",
   "deleted":false,
   "id":"qeq",
   "landing_url":null,
   "line\_item\_id":"4bii5",
   "serving_status":"ACTIVE",
   "updated_at":"2016-02-11T22:23:23Z"
 },
 "request":{
   "params":{
     "line\_item\_id":"4bii5",
     "account\_media\_id":"knb"
   }
 }
}

Set the CTA and destination URL

It is important to note that unlike most other campaigns on X, the VIDEO_VIEWS_PREROLL objective does not utilize Promoted Tweets or Cards. Instead, the video creative is associated with your ad group (line item) and the CTA information is associated with a preroll_call_to_action entity. The POST accounts/:account_id/preroll_call_to_action endpoint allows you to control the button CTA and the destination URL.
POST https://ads-api.x.com/8/accounts/55w3kv/preroll\_call\_to_action
line\_item\_id=4bii5&call\_to\_action=VISIT\_SITE&call\_to\_action\_url=https%3A%2F%2Fx.com%2FAdsAPI

{
 "data":{
   "id":"aaa111",
   "line\_item\_id":"4bii5",
   "call\_to\_action":"WATCH_NOW",
   "call\_to\_action_url":"https://x.com/AdsAPI",
   "created_at":"2016-02-11T22:23:23Z",
   "updated_at":"2016-02-11T22:23:23Z",
   "deleted":false
 },
 "request":{
   "params":{
     "line\_item\_id":"4bii5",
     "call\_to\_action":"VISIT_SITE",
     "call\_to\_action_url":"https://x.com/AdsAPI"
   }
 }
}

Set targeting criteria

The targetting criterion utilized for pre-roll video ads is only avaialble using our batch targeting criteria endpoint POST batch/accounts/:account_id/targeting_criteria. Use CONTENT_PUBLISHER_USER as negated targeting to exclude the ad from being paired with a set of users. Provide the X user_id  or publisher_user_id for the handles to exclude. The GET publishers endpoint can be used to retrieve the list of user_id to exclude for Content Categories. The publisher_user_id returned in the GET curated_categories response can be used to retrieve a similar exclusion list for Curated Categories. Note: A maximum of 5 publisher_user_id can be excluded for Curated Categories and 50 user_id for Content Categories.
POST https://ads-api.x.com/8/batch/accounts/55w3kv/targeting_criteria
\[
  {
    "operation_type": "Create",
    "params": {
      "line\_item\_id": "iqwls",
      "targeting\_type": "CONTENT\_PUBLISHER_ID",
      "targeting_value": "1917731",
      "operator_type": "NE"
    }
  }
\]

{
  "data": \[
    {
      "line\_item\_id": "iqwka",
      "name": "realsaltlake",
      "raw_negated": true,
      "raw\_targeting\_value": "aajwo",
      "id": "sajk32",
      "raw\_targeting\_type": "CONTENT_PUBLISHER",
      "raw\_operator\_type": "EQUAL_TO",
      "operator_type": "NE",
      "created_at": "2021-03-30T18:02:32Z",
      "targeting_value": 17288520,
      "updated_at": "2021-03-30T18:02:32Z",
      "deleted": false,
      "targeting\_type": "CONTENT\_PUBLISHER_USER"
    }
  \],
  "request": \[
    {
      "params": {
        "line\_item\_id": "iqwka",
        "account_id": "55w3kv",
        "operator_type": "NE",
        "targeting_value": "17288520",
        "targeting\_type": "CONTENT\_PUBLISHER_USER"
      },
      "operation_type": "Create"
    }
  \]
}

Launch campaign

When you’re ready to launch your campaign, simply un-pause using PUT accounts/:account_id/campaigns/:id. PUT https://ads-api.x.com/8/accounts/55w3kv/campaigns/f2rp3? entity_status=ACTIVE
{
  "request": {
    "params": {
      "campaign_id": "f2rp3",
      "account_id": "55w3kv"
    }
  },
  "data": {
    "name": "test-curated-categories-api",
    "start_time": "2021-02-10T00:00:00Z",
    "reasons\_not\_servable": \[
    \],
    "servable": false,
    "purchase\_order\_number": null,
    "effective_status": "ACTIVE",
    "daily\_budget\_amount\_local\_micro": 55000000,
    "end_time": null,
    "funding\_instrument\_id": "103hp9",
    "duration\_in\_days": null,
    "standard_delivery": true,
    "total\_budget\_amount\_local\_micro": null,
    "id": "f2rp3",
    "entity_status": "ACTIVE",
    "frequency_cap": null,
    "currency": "USD",
    "created_at": "2021-02-08T23:55:38Z",
    "updated_at": "2021-02-08T23:55:38Z",
    "deleted": false
  }
}

Analytics

Analytics for VIDEO_VIEWS_PREROLL campaigns are available using our stats endpoints.

Keyword Targeting in Timelines

Keyword targeting is fundamental to our Promoted Tweets products, giving campaigns better reach. Keyword targeting in timeline enables platforms to target X users based on keywords in their recent Tweets. For example, if an advertiser is targeting the unordered keyword combination “plan + trip”, and a user Tweets, “I’m starting to plan my trip to Cabo, any suggestions?” while the campaign is running, that user may soon afterward see the advertiser’s Promoted Tweet.

How does it work?

TL;DR: from an API standpoint, this change is quite simple: you can now target keywords on Promoted Tweets in Timeline. Just set the targeting_type to unordered_keywords or phrase_keywords for line items.

Quick Start Guide


Full API Reference

For the complete list of endpoints with request/response examples and attribute tables, see the Campaign Management API Reference page.