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.

Manage all types of promotable content (Tweets, media, cards, polls, etc.) for your X advertising campaigns.
  • Full API Reference — Complete reference for all creative endpoints and objects
  • Guides — Media Library, Scheduled Tweets, Identifying Cards/Media, Carousels, etc.

Overview

Creatives are any entity that can be promoted in a campaign. Posts can include text, images, GIFs, videos, or cards. Cards can include images or videos. Image, GIF, or video creatives are uploaded using either the POST media/upload — a simple upload endpoint that only supports images — or the POST media/upload (chunked) endpoints. These can be added to cards:
  • POST accounts/:account_id/cards Tweets:
  • POST accounts/:account_id/tweets - To add cards to Tweets, use the card_uri parameter. Scheduled Tweets:
  • POST accounts/:account_id/scheduled_tweets
For additional details on cards, please see the Cards page. The Promoted Video page provides details on associating videos with cards or Tweets.

Cards

The Ads API supports several card types that can be used in Tweets, which can then be promoted in campaigns. Note: once Tweeted, card details are publicly visible. This may include information about the user who owns the card.

Image

The following image specifications apply to assets used in Cards. Images must be 3MB or less and have an a width of at least 800px. In addition, we support the following width:height aspect ratios.
  • Website: 1:1 and 1.91:1
  • Image App Download: 1:1 and 1.91:1
  • Poll: 1.91:1
  • Image Conversation: 1.91:1
  • Image Direct Message: 1.91:1
We support the following image formats: .bmp, .jpeg, and .png.

Video

The following video specifications apply to assets used in Cards. We support the following width:height aspect ratios.
  • Video Website: 16:9 and 1:1
  • Video App Download: 16:9 and 1:1
  • Poll: 16:9
  • Video Conversation: 16:9
  • Video Direct Message: 16:9
This document provides a brief overview of the process for uploading and promoting video through the Ads API. The Ads API supports Promoted Video in Tweets and in the following cards: First, upload the video using the POST media/upload (chunked) endpoint. Using the media_id, associate the video with an ads account using the POST accounts/:account_id/videos endpoint. The video’s id, sometimes referred to as the media_key, will be used in subsequent requests. This is a string that begins with an int, is followed by an underscore, and ends with a long value. As an example, see: 13_875943225764098048. To create a Tweet, use the POST accounts/:account_id/tweet endpoint along with the video’s id. In this step, you can also provide a video title, description, and call-to-action (CTA). These values are user-facing. Video App Download and Video Conversation cards support the ability to add a poster images. Upload an image to use in these cards using the POST media/upload endpoint. Create the card using one of the following endpoints: using the video’s id and, optionally, the image’s media_id (for the poster image). Finally, create the Tweet using the POST accounts/:account_id/tweet endpoint. Cards are attached to Tweets using the card_uri parameter.

General Information

For detailed guidance on video uploading through the API, please see the Video Upload Guide. Videos can also be promoted as pre-roll assets. See the Video Views Pre-roll Objective Guide for a detailed explanation.
  • (As of 2015-10-22) When uploading videos to be used in promoted content, the media_category parameter must be set with a value of amplify_video for all INIT command requests to the POST media/upload (chunked) endpoint. Using this new param ensures that the video is asynchronously pre-processed and prepared for use in promoted content. The STATUS command can be used to check completion of asynchronous processing after video upload.
  • The maximum promoted video length currently allowed is 10 mins with a file size of 500MB or less.
  • Uploaded video should be either mp4 or mov.
  • Uploaded video generally processes quickly, but processing times can vary depending on video length and file size.
  • Uploaded poster images should be in png or jpg format. There are no aspect ratio or size requirements, but the poster image will be adjusted to fit the video player.

Guides

Scheduled Tweets

Introduction

Scheduled Tweets allow an advertiser or user to create a Tweet that can be scheduled to go live at a later date. In addition to being able create and manage these Tweets, the API allows the ability to associate these Tweets with a line item, to be promoted once the Tweet goes live. This allows advertisers to stage create native Tweets and plan their campaign creatives in advance of any key initiatives. For example, staging a Tweet creative to live immediately upon a new product announcement. The full set of functionality provided by the Scheduled Tweets API endpoints are listed below:
  • Create, modify and view newly scheduled Tweets
  • Associate a Scheduled Tweet with a line item
  • Query and manage existing scheduled Tweets
  • Once a Scheduled Tweet goes live, retrieve the live Tweet id

API Endpoints

The entire set of endpoints related to the above functionality is listed below:

Scheduled Tweet Management

Scheduled Promoted Tweets

Scheduled Tweet View

Due to the nature of Scheduled Tweets being separate entities from “live” Tweets, there are two different sets of validations run on any creates or edits to these Tweets. The first set of validation rules are run during the Scheduled Tweet creation step, specifically:

Scheduled Tweet Create:

  • Validate that the authenticated user has access to create organic Tweets for a given @handle Promoted-Only Tweet create privileges requires authenticated user to be an account user with Tweet composer permissions
  • Validate that there are no more than 30 Tweets that are scheduled to be created within a 15 minute window of the scheduled_at time. A SCHEDULED_TWEET_LIMIT_EXCEEDED error message indicates that too many Scheduled Tweets have been scheduled within the same future, 15 minute time frame.  Advertisers will need to remove an existing Scheduled Tweet or move the scheduled_at time earlier or later.

Scheduled Tweet goes “live”:

  • These validation rules are run at the scheduled_at time and are identical to those applied on regular Tweet creation in the API. For example, a Scheduled Tweet will not go live and the scheduled_status will be set to FAILED if the Scheduled Tweet contains both an image and a gif

Workflow

Create a new Scheduled Tweet A new Scheduled Tweet can be created using the POST accounts/:account_id/scheduled_tweets endpoint. This endpoint has the following required parameters, scheduled_at time along with the Tweet text if no media entities are included in the Tweet. In addition, this endpoint provides a few additional options that allow you to create a scheduled Tweet on behalf of another @handle via the as_user_id param along with the ability to add a card (card_uri) and any media (media_ids). Note, a Tweet can only contain entities of the same type, i.e., either Video, Gif or Image. The nullcast param controls whether the Tweet is a “Promoted-Only” Tweet or not. All newly created Scheduled Tweets are “Promoted-Only” (nullcast=true) by default. If nullcast=false then an Organic Scheduled Tweet is created Once a Scheduled Tweet is successfully created, the response will contain an id field, which refers to the unique identifier of the Scheduled Tweet itself. In addition to this field, another field called tweet_id is also returned. This field is null initially, however once the Tweet goes live this field is populated with the ID of the “live” Tweet.
twurl -H 'ads-api.x.com' -X POST "/6/accounts/:account_id/scheduled_tweets" -d 'scheduled_at=2017-12-24T23:59:00Z&text=Happy Holidays!'
This will create the following Scheduled Tweet:
{
  "request": {
    "params": {
      "text": "Happy Holidays!",
      "scheduled_at": "2017-12-24T23:59:00Z"
    }
  },
  "data": {
    "completed_at": null,
    "id_str": "917507899668099072",
    "text": "Happy Holidays!",
    "user_id": "3271358660",
    "scheduled_status": "SCHEDULED",
    "id": 917507899668099100,
    "nullcast": true,
    "created_at": "2017-10-09T21:51:44Z",
    "scheduled_at": "2017-12-24T23:59:00Z",
    "card_uri": null,
    "updated_at": "2017-10-09T21:51:44Z",
    "tweet_id": null,
    "media_keys": []
  }
}
Once this Scheduled Tweet goes live, the tweet_id field will be populated with the “live” Tweet’s ID. View a Scheduled Tweet The GET accounts/:account_id/tweet_previews endpoint can then be used with the Scheduled Tweet id from the previous step to generate a preview of the Tweet. The API response will contain an iframe URL that is ready to be used to render a preview for the Scheduled Tweet. The relevant CSS and images will be served directly via X.
twurl -H ads-api.x.com -X GET "/6/accounts/18ce54bgxky/tweet_previews?tweet_type=SCHEDULED&tweet_ids=917507899668099072
{
  "request": {
    "params": {
      "tweet_type": "SCHEDULED",
      "tweet_ids": [
        "917507899668099072"
      ],
      "account_id": "18ce54bgxky"
    }
  },
  "data": [
    {
      "tweet_id": "1126633863155871744",
      "preview": "<\iframe class='tweet-preview' src='https://ton.smf1.x.com/ads-manager/tweet-preview/index.html?data=H4sIAAAAAAAAAK1WTW%2FjNhD9Kyyv9dqSZdmOgALJbhJsCyxaIDkUWBUEJY0lNhSpklRSN%2FV%2F71CyZbm297S%2BWJxPzpt5I71T9wbgaELeaW6AOygYxyN9rlryhW9JcEPmUbKIkuiG%2FBjgj8yD8IZOqChoEobz5TKK1ssojOP1KlwtFl7BrDMY4oIW%2FTatlMzB3z7JZ940W%2FJZS1Hwrf0Btc60Kve3oMmGSwsTWgjbSL7tXJjhqgSafA0mYfzHhIJywgmwNHmnFbeV4yU%2Bf0WN3daZlvtDa8Gw2htrdRCZXrlDU92aHIPStA2CKOekMrD5KaWVc02SztIZps%2Bh0rIAg27TXNcpJQYk2ii90VLqt7R3ht%2B4cQoMeVClUIAPd03Th01nvDfx0ClmoJFYk0aouGst82gqROaKskf03KCr7LLvXnXN02K3QTHFaziovYdH0seL5qswitfLZTBq6FGIRfSe9Lm1FTfkY%2BX%2FFcpPAlNRC7eufdFSY1%2BxASh84oo8YitzYXM9IZ%2FuaNcQ1HjMbQc61l0VXDmYlsJVbTYVGq0KwPCi2cf5tQFFnjR2zyDU6YycwX%2Fr3oRzvfKpwTaSZ8NfQUoU%2FUsetanxAV79VElhHbm1oIrSiILcvvgquqSN0Q7y8Uz2TQdjWa5bhZP8IUShEeh8IvIxkVB7SY%2FyKctaIL%2B0kgQrMp8n0SKJ10eWxZ4t%2FBXHUzg4idu6nOnNxsIQ1Yka2D9aDc0sQTNQPJP%2B2sgqvPUrGLERozL68ToNLRELvBj4VuZaOSOy1mmsdAi2dxaWOeyhlRzVl6TYozMnhHIjJLCM5y%2BlwaweHOn96afg%2FuHhnl60ETUvgR1HpJsQntkptrcuO0bOOhuLg1NBPfyH6Swrpw2W9O24rBu8kwH8DuEdns9Kv1hLc5rsxBaTLcN1HIdhHIVRuFov5wtMXH748vO2%2BP0jUzjFXE7%2FbMa3%2BFZl3z1ZxhWyjv2fwlfy9NaY6LhO0lm4WC3WcRSvlqO4UqiXYT7C%2B7vwcT7SWlFAxg3LtMHNfH2ODnZ4kIPVPRo9jnN1r5eDNup%2BIy2y5GxuDrQqYMNb6dje9or44HOyQYTnWs%2FXXoD7%2Ba8WrGO4hwZuK%2B2Qt%2F32tAPhB%2B4xt238qjVQtpIbuuvIP6wbjfAIhStncO3eZ0f9keMHmYHuo%2BCwFoJ%2BDfktdEF0JPfebbxgct30b%2BdhY%2B51u%2FGm2U2IR7rW%2FbJU%2FdcBfpEchHjwoO52%2FwENmVvErwgAAA%3D%3D'>"
    }
  ]
}
A sample view of the newly created Scheduled Tweet is shown above Associate a Scheduled Tweet with a line item While Scheduled Tweets can be used to create Organic Tweets, we also allow partners to create a “Promoted-Only” (nullcast=true) Tweet either one of which can be associated with a line item. In order to facilitate this, we provide a POST accounts/:account_id/scheduled_promoted_tweets endpoint as well. This endpoint only allows a single Promoted Scheduled Tweet to be associated with a line item in a single API call. In order to associate multiple Scheduled Tweets to the same line item, multiple API calls are necessary. Please note that it is not possible to modify an existing Scheduled Promoted Tweet.
twurl -H 'ads-api.x.com' -X POST "/6/accounts/:account_id/scheduled_promoted_tweets" -d 'line_item_id=a44qc&scheduled_tweet_id=917507899668099072'
{
  "data": {
    "line_item_id": "a44qc",
    "id": "26576",
    "created_at": "2017-10-09T22:24:16Z",
    "updated_at": "2017-10-09T22:24:16Z",
    "scheduled_tweet_id": "917507899668099072",
    "tweet_id": null,
    "deleted": false
  },
  "request": {
    "params": {
      "line_item_id": "a44qc",
      "scheduled_tweet_id": 917507899668099100,
      "account_id": "aaaaa"
    }
  }
}
This endpoint only creates an association between a given Scheduled Tweet and a line item. Once the campaign/line item flight dates are current, the line item with automatically start serving the corresponding “live” Tweet. While we do validate during this step that the Scheduled Tweet is in the SCHEDULED state, and that the given Scheduled Tweet is valid for the given objective, no other validations are run. Any remaining validation rules that apply to the line item and Scheduled Tweet are run when the Tweet goes “live” In order to ensure that there are no issues with campaign serving it is recommend that the Scheduled Tweet be scheduled_at a time prior to the campaign/line item flight dates. For example, let’s say the Scheduled Tweet is set to go live after the campaign start date (and that there is only a single Tweet associated with a single line item), then the campaign will be ACTIVE, however given that the Scheduled Tweet is not live yet, there will be no creatives available for serving. Scheduled Tweet Management The remaining sets of endpoints allow API consumers to manage all their Scheduled Tweets and Scheduled Promoted Tweets. These APIs can be used to either return a list of all Scheduled Tweets optionally filtered by a given state as well as lookup a given Scheduled Tweet by its id.

What happens when a Scheduled Tweet goes live?

Once a given Scheduled Tweet is about to go live, or in other words at the scheduled_at time, the following updates are made:
  • The “live” Tweet is created however this may have a latency of upto 1 second
  • The tweet_id is added to the following entities:
  • Scheduled Tweet
  • Promoted Scheduled Tweet
  • A new Promoted Tweet entity is created

Best Practices

The following best practices are recommended when creating or promoting Scheduled Tweets:
  • Ensure that the Tweet is valid when creating the Scheduled Tweet (for example, a Tweet can only have either an Image, Video or Gif and not any combination of the three)
  • Ensure that the campaign flight dates (i.e., the start_time and end_time) align with the scheduled_at time for the Scheduled Tweet
  • Scheduled Tweets should not be scheduled for more than one year in the future (365 days)
  • Tweet preview is currently not supported for Scheduled Tweets (this is ability to preview Scheduled Tweets prior to creation)

Media Library

Introduction

The Media Library endpoints provide the ability to manage images, GIFs, and videos for X Ads accounts. Media assets in the library can be used in Tweets and to create cards. They can also be reused in multiple creatives, eliminating the need to upload the same asset multiple times.

API Endpoints

Adding to the Library

Adding media to the library is a two-step process. First, upload the asset using either the POST media/upload endpoint or the POST media/upload (chunked) set of endpoints. (See the Chunked media upload guide for details on our multi-part upload process.)
twurl -X POST -H upload.x.com "/1.1/media/upload.json?additional_owners=756201191646691328" --file latte.jpeg --file-field "media"
{
   "media_id":966947208837742592,
   "media_id_string":"966947208837742592",
   "size":74194,
   "expires_after_secs":86400,
   "image":{
      "image_type":"image/jpeg",
      "w":800,
      "h":418
   }
}
Next, using the media ID, add the media to the ads account’s library using the POST accounts/:account_id/media_library endpoint.
twurl -X POST -H ads-api.x.com "/9/accounts/18ce54d4x5t/media_library?file_name=latte.jpeg&media_category=TWEET_IMAGE&media_key=966947208837742592&name=Latte"
{
   "request":{
      "params":{
         "name":"Latte",
         "file_name":"latte.jpeg",
         "media_category":"TWEET_IMAGE",
         "account_id":"18ce54d4x5t",
         "media_key":966947208837742592
      }
   },
   "data":{
      "tweeted":false,
      "name":"Latte",
      "file_name":"latte.jpeg",
      "media_url":"https://pbs.twimg.com/media/DWtJXQNUQAAdPZj.jpg",
      "media_category":"TWEET_IMAGE",
      "media_key":"3_966947208837742592",
      "created_at":"2018-02-23T08:05:54Z",
      "media_status":"TRANSCODE_COMPLETED",
      "media_key":"966947208837742592",
      "media_type":"IMAGE",
      "updated_at":"2018-02-23T08:06:17Z",
      "deleted":false
   }
}
Note: Tweeting images, GIFs, or videos directly after the upload also adds media to the library.

Request Parameters

All Media Library POST requests require a media identifier. This value is returned during the upload step. When using the media_id, as in the example above, a media_category must also be specified. There are four possible category values: AMPLIFY_VIDEO, TWEET_GIF, TWEET_IMAGE, and TWEET_VIDEO. Optionally, name and file_name values can be set for objects in the Media Library. These attributes help users distinguish between media variants in the library. For videos, it’s also possible to set a title and a description. They values are intended to be passed as the video_title and video_description request parameters with the POST accounts/:account_id/tweet endpoint. In the Tweet, this text appears under the video.

Attributes

The Media Library, formally introduces the concept of the media_key. This is the unique identifier for objects in the library. Media keys are string values in the following format: 13_875943225764098048. These are fully supported in all of our card endpoints. In addition, the Media Library response includes the media_id, represented as a string. This is included for resources that do not currently accept a media key: Tweets*, Tweet preview*, and Scheduled Tweets. We are working toward supporting media keys everywhere. The aspect_ratio attribute is returned for GIFs and videos. This can be used to filter media for use in cards that only accept particular aspect ratios. *These endpoints support the video_id parameter, which is a media key.

Usage

In this section, the following image will be used in a Tweet and to create a website card.
twurl -H ads-api.x.com "/9/accounts/18ce54d4x5t/media_library/3_966947208837742592"
{
   "request":{
      "params":{
         "account_id":"18ce54d4x5t",
         "media_key":"3_966947208837742592"
      }
   },
   "data":{
      "tweeted":false,
      "name":"Latte",
      "file_name":"latte.jpeg",
      "media_url":"https://pbs.twimg.com/media/DWtJXQNUQAAdPZj.jpg",
      "media_category":"TWEET_IMAGE",
      "media_key":"3_966947208837742592",
      "created_at":"2018-02-23T08:05:54Z",
      "media_status":"TRANSCODE_COMPLETED",
      "media_key":"966947208837742592",
      "media_type":"IMAGE",
      "updated_at":"2018-02-23T08:06:17Z",
      "deleted":false
   }
}
Tweet We can create the Tweet by referencing the images using media_keys.
twurl -X POST -H ads-api.x.com "/9/accounts/18ce54d4x5t/tweet?text=coffee&media_keys=966947208837742592&as_user_id=756201191646691328&trim_user=true"
{
   "data":{
      "created_at":"Fri Feb 23 08:20:05 +0000 2018",
      "id":966950781302665218,
      "id_str":"966950781302665218",
      "text":"coffee https://t.co/T772Hx5GNT",
      "truncated":false,
      "entities":{
         "hashtags":[

         ],
         "symbols":[

         ],
         "user_mentions":[

         ],
         "urls":[

         ],
         "media":[
            {
               "id":966947208837742592,
               "id_str":"966947208837742592",
               "indices":[
                  7,
                  30
               ],
               "media_url":"http://pbs.twimg.com/media/DWtJXQNUQAAdPZj.jpg",
               "media_url_https":"https://pbs.twimg.com/media/DWtJXQNUQAAdPZj.jpg",
               "url":"https://t.co/T772Hx5GNT",
               "display_url":"pic.x.com/T772Hx5GNT",
               "expanded_url":"https://x.com/apimctestface/status/966950781302665218/photo/1",
               "type":"photo",
               "sizes":{
                  "thumb":{
                     "w":150,
                     "h":150,
                     "resize":"crop"
                  },
                  "large":{
                     "w":800,
                     "h":418,
                     "resize":"fit"
                  },
                  "medium":{
                     "w":800,
                     "h":418,
                     "resize":"fit"
                  },
                  "small":{
                     "w":680,
                     "h":355,
                     "resize":"fit"
                  }
               }
            }
         ]
      },
      "source":"Ads API Internal Test App",
      "in_reply_to_status_id":null,
      "in_reply_to_status_id_str":null,
      "in_reply_to_user_id":null,
      "in_reply_to_user_id_str":null,
      "in_reply_to_screen_name":null,
      "user":{
         "id":756201191646691328,
         "id_str":"756201191646691328"
      },
      "geo":null,
      "coordinates":null,
      "place":null,
      "contributors":[
         2417045708
      ],
      "retweet_count":0,
      "favorite_count":0,
      "favorited":false,
      "retweeted":false,
      "possibly_sensitive":false,
      "scopes":{
         "followers":false
      },
      "lang":"en"
   },
   "request":{
      "params":{
         "as_user_id":756201191646691328,
         "text":"coffee",
         "account_id":"18ce54d4x5t",
         "media_keys":[
            966947208837742592
         ],
         "trim_user":true
      }
   }
}
Website Card All of our cards endpoints support media keys. We will create the website card by referencing the image’s media_key.
twurl -X POST -H ads-api.x.com "/11/accounts/18ce54d4x5t/cards"
{
  "name": "components create cards",
  "components": [
    {
      "type": "MEDIA",
      "media_key": "3_1323490622599176192"
    },
    {
      "type": "BUTTON",
      "label": {
        "type": "ENUM",
        "value": "INSTALL"
      },
      "destination": {
        "type": "APP",
        "country_code": "US",
        "googleplay_app_id": "com.twitter.android"
      }
    }
  ]
}
We then associate this card with a Tweet using its card_uri.

Identifying Cards

Introduction

Cards are customizable ad formats that use media and that can be associated with a website, an app, or with calls to action to drive certain user engagements, such as starting a Direct Message. They can be appended to Tweets, Scheduled Tweets, or Draft Tweets. Cards may be referenced in Tweet objects in one of two ways: by the card’s card_uri or by its preview_url. Example values for each are presented below.
card_uripreview_url
card://1043282691834048513https://cards.x.com/cards/18ce54d4x5t/68w3s
Note: As of Ads API version 3, only the card_uri is generated and returned in the cards response for newly created cards. Note: As of Ads API version 5, the preview_url in the cards response is no longer returned. The type of reference in the Tweet object response will depend on the way the Tweet was created. In other words, if the Tweet was created using the card_uri request parameter, the card URI value will appear in the response. If the preview_url was included as part of the Tweet text, on the other hand, the preview URL will appear in the response.

Identifying Tweets with card_uri

For Tweets created using the card’s URI value, find the reference to the card in the card_uri response attribute. The example response below uses the GET accounts/:account_id/tweets endpoint.
$ twurl -H ads-api.x.com "/9/accounts/18ce54d4x5t/tweets?trim_user=true&tweet_type=PUBLISHED&tweet_ids=1043551275923591168"
{
  "request": {
    "params": {
      "tweet_ids": [
        "1043551275923591168"
      ],
      "tweet_type": "PUBLISHED",
      "trim_user": true,
      "account_id": "18ce54d4x5t"
    }
  },
  "next_cursor": null,
  "data": [
    {
      "coordinates": null,
      "retweeted": false,
      "source": "Ads API Internal Test App",
      "entities": {
        "hashtags": [],
        "symbols": [],
        "user_mentions": [],
        "urls": []
      },
      "display_text_range": [
        0,
        15
      ],
      "favorite_count": 0,
      "in_reply_to_status_id_str": null,
      "geo": null,
      "id_str": "1043551275923591168",
      "scopes": {
        "followers": false
      },
      "in_reply_to_user_id": null,
      "truncated": false,
      "retweet_count": 0,
      "scheduled_status": null,
      "id": 1043551275923591168,
      "in_reply_to_status_id": null,
      "nullcast": true,
      "created_at": "Sat Sep 22 17:23:07 +0000 2018",
      "place": null,
      "scheduled_at": null,
      "tweet_type": "PUBLISHED",
      "favorited": false,
      "card_uri": "card://1043282691834048513",
      "full_text": "Tracking a card",
      "lang": "en",
      "contributors": [
        2417045708
      ],
      "in_reply_to_screen_name": null,
      "in_reply_to_user_id_str": null,
      "user": {
        "id": 756201191646691328,
        "id_str": "756201191646691328"
      },
      "tweet_id": "1043551275923591168"
    }
  ]
}
If using the Standard API, use include_card_uri=true in the request. Regardless of which endpoint is used, the card_uri response attribute will only be rendered if the Tweet was created using a card URI. For scheduled and draft Tweet objects, the response will always include the card_uri response attribute.

Identifying Tweets with preview_url

For Tweets created by including the preview URL as part of the Tweet’s text, the URL can be found in entities[“urls”][i][“expanded_url”] (the text field includes a shortened t.co URL), where i is an array index (a Tweet can contain multiple URLs). For scheduled and draft Tweet objects, the preview URL will always appear in the text field.

Fetching cards

To retrieve additional information about a specific card, we provide two endpoints: GET accounts/:account_id/cards/all and GET accounts/:account_id/cards/all/:card_id. The former allows a card to be fetched by card_uri and the latter by the card’s ID. The card’s ID is found at the end of the preview_url. In the example above, the ID is 68w3s.

Identifying Media

Introduction

Media—images, GIFs, and videos—can be added to Tweets and cards. In addition, videos can be used as pre-roll assets and images can be promoted on the X Audience Platform. This section describes how to find media references across these entities. There are two types of media identifiers: IDs and keys. Example values for each are presented below.
Media IDMedia key
102982557953180797113_1029825579531807971
The media key is the ID plus a numeric prefix and an underscore.

Images

The following table shows the identifier types currently available in each image-related resource’s response as well as the corresponding attribute name(s).
ResourceIdentifierAttribute(s)
Image cardsNone
TweetBothentities["media"]["id_str"] entities["media"]["media_key"]
Scheduled TweetBothmedia_ids and media_keys
Draft TweetBothmedia_ids and media_keys
Account MediaNone
Media LibraryBothmedia_id and media_key
Image cards and Account Media images do not include a reference any media identifier. Tweets only include media IDs. Scheduled and Draft Tweets include both the media ID and media key. The Media Library returns both, too. For Tweets, the id and id_str fields in the object within the entities[“media”] array correspond to the media ID. In cases where a Tweet includes multiple images, the references to each media entity can only found in extended_entities[“media”]. In addition to references to identifiers, it’s often important to have access to the image’s URL.
ResourceAttribute(s)Format
Image cardsimage.jpg
Tweet*entities["media"][0]["media_url"] or extended_entities["media"][i]["media_url"].jpg
Scheduled TweetNone
Draft TweetNone
Account Mediamedia_url.jpg
Media Librarymedia_url.jpg
* This URL locations depend on whether the Tweet contains a single image or multiple images. All image cards include an image response attribute that contains the X image URL. (For image app download cards, the name is wide_app_image.) For Tweets, the media URL location depends on both the type of media and the endpoint being used. For Tweets with a single image, the URL can be found in entities[“media”][0][“media_url”]. This is true for both the Ads API and the Standard API. When Tweets contain multiple images, however, the URLs can only be found extended_entities[“media”][i][“media_url”]. This is only available in the Standard API.

Videos

The following table shows the identifier types currently available in each video-related resource’s response as well as the corresponding attribute name(s).
ResourceIdentifierAttribute(s)
Video cardsMay be eithervideo_content_id
Video poll cardsNone
TweetBothentities["media"]["id_str"] entities["media"]["media_key"]
Scheduled TweetBothmedia_ids and media_keys
Draft TweetBothmedia_ids and media_keys
Account MediaMedia keyvideo_id
Media LibraryBothmedia_id and media_key
While video cards (with the exception of poll cards with video) include a video_content_id response attribute, there is inconsistency in the type of value returned. In some cases, it’s a media ID; in others, it’s a media key. Information about how to access the video’s URL is shown below.
ResourceAttribute(s)Format
Video cardsvideo_url and video_hls_url.vmap .m3u8
Tweet with videoextended_entities["media"][i]["video_info"]["variants"][j]["url"].mp4
Scheduled TweetNone
Draft TweetNone
Account MediaNone
Media Librarymedia_url.mp4
Video cards include video_url and video_hls_url response attributes with .vmap and .m3u8 URLs, respectively.

Media Library

It’s sometimes necessary to retrieve additional information about a media asset. One use case, for video cards, is retrieving the mp4 URL instead of the vmap one. This is available in the Media Library. For details on the available information, see our Media Library Guide. Most assets belonging to the ads account’s FULL promotable user can be found in the library. There are some exceptions, though. Fetching media As stated above, image cards do not contain references to either media IDs or media keys. As a result, it’s not possible to fetch their assets through the Media Library. This is also true for Account Media images. Video cards require that the video asset be part of the Media Library (or the Videos resource before it) prior to creating it. As a result, these assets will always be retrievable in the Media Library. This is also true for Account Media PREROLL assets. Finally, media in Tweets are always guaranteed to be in the Media Library. The following table summarizes which assets are retrievable in the Media Library, taking into account whether the resource response includes an identifier to use in the lookup.
ResourceIn the Media Library
Image cardsNo
Video cardsYes*
Tweets (any media)**Yes
Scheduled TweetsYes
Draft TweetsYes
Account media imagesNo
Account media videos (PREROLL)Yes
* For cards where the video_content_id is a media key. When the value is a media ID, the asset still exists in the Media Library, but retrieving it involves appending a numeric prefix and underscore to it. ** Tweets only return media IDs. While the asset is guaranteed to exist in the Media Library, fetching it involves appending a numeric prefix and underscore to it. Interactions with Account Media There are two cases where media assets added to the library are automatically added to the Account Media resource.
  • When an AMPLIFY_VIDEO asset is added to the Media Library, it is automatically added as an Account Media asset as a PREROLL creative type.
  • When images that have specific dimensions (see “Creative Types” in our enumerations page) are added to the Media Library, they are automatically added as Account Media assets. The creative type (e.g., INTERSTITIAL) depends on the image dimensions.

Tweets

Introduction

The X Ads API supports three types of Tweets: published, scheduled, and draft.

Nullcasted Tweets

Tweets may either be nullcasted (a.k.a. “Promoted-only”) or organic. Nullcasted Tweets, once published, do not appear in the user’s public timeline, though they are public. Organic Tweets, on the other hand, are served to the user’s followers and do appear in the user’s public timeline. Creating Tweets Each of the three Tweet create endpoints supports a Boolean nullcast parameter that gives the API user the option to create nullcasted or organic Tweets. Nullcasted Tweets can be created by the user or by anyone who has permission to create Tweets on the user’s behalf. Organic Tweets can only be created by the full promotable user. Updating Tweets It is possible to update the nullcast property for scheduled and draft Tweets. For scheduled Tweets, edits can be made until the Tweet’s scheduled_at time. Draft Tweets can be edited indefinitely. Once published, though, it’s not possible to change a Tweet from nullcasted to organic or vice versa.

Promoting Tweets

Only published and scheduled Tweets may be promoted. These can either be nullcasted or organic; there’s no restriction. An advertiser may promote their own Tweets or another user’s Tweets as long as they’ve obtained permission to do so. (See: Promoting another user’s Tweets for more information.) Multiple Tweets can be promoted in a single campaign. Similarly, a single Tweet may be promoted in one or more campaigns. To promote published Tweets, use the POST accounts/:account_id/promoted_tweets endpoint. This associates published Tweets with a line item. To promote scheduled Tweets, use the POST accounts/:account_id/scheduled_promoted_tweets endpoint.

Tweet IDs

Published, scheduled, and draft Tweet IDs are numeric—they are 64-bit unsigned integers. For example, the following published Tweet’s ID is 1166476031668015104. When published or scheduled Tweets are promoted, a corresponding promoted Tweet entity is created. These entities have their own IDs, which are alpha-numeric and are represented as base-36-encoded values. For example, promoting the published Tweet above—that is, associating it a line item 6c62d—returns the following API response.
$ twurl -X POST -H ads-api.x.com "/9/accounts/18ce54d4x5t/promoted_tweets?line_item_id=6c62d&tweet_ids=1166476031668015104"
{
  "request": {
    "params": {
      "tweet_ids": [
        1166476031668015104
      ],
      "line_item_id": "6c62d",
      "account_id": "18ce54d4x5t"
    }
  },
  "data": [
    {
      "line_item_id": "6c62d",
      "id": "3qwlq6",
      "entity_status": "ACTIVE",
      "created_at": "2019-09-12T21:39:10Z",
      "updated_at": "2019-09-12T21:39:10Z",
      "approval_status": "ACCEPTED",
      "tweet_id": "1166476031668015104",
      "deleted": false
    }
  ],
  "total_count": 1
}
In addition to the Tweet ID and the line item ID, which were passed into the create request, the response includes an id field with a value of 3qw1q6, which is the promoted Tweet ID.

Carousels

Introduction

The X Ads API supports creating and retrieving video carousels and image carousels. The carousel is a card type that can contain between 2 and 6 media assets. The carousel card can direct a user to a website or encourage them to install a mobile app. For more information about carousels, their benefits, best practices, and FAQs, see our Carousel Ads on X page. A carousel, like any other card type, can be used in Tweets and those Tweets can then be promoted. The workflow is the same as what you’re already used to:
  1. Upload media
  2. Create the card
  3. Create the Tweet
  4. Promote the Tweet
The only difference is with how the card is created. While other card create requests accept query parameters, carousel card create requests only accept JSON POST bodies.

Endpoints

The Ads API supports creating and retrieving carousels. To create a carousel—any kind—use the POST accounts/:account_id/cards endpoint. To retrieve carousels, use the GET accounts/:account_id/cards endpoint.

JSON POST Body

Carousels are created using two components. The first specifies the media assets that will be used. The second specifies information about either the website or the app. Specifically, a carousel card is created by using the following components, in order:
  • One SWIPEABLE_MEDIAcomponent, which accepts an array of media keys
  • One of the following:
  • A DETAILS component to specify website information
  • A BUTTON component to specify app information
The SWIPEABLE_MEDIA component must include a media_keys array where you can specify between 2 and 6 images or videos. The order in which the media keys are passed in determine the order in which they will be rendered.
{
  "type": "SWIPEABLE_MEDIA",
  "media_keys": [
    "13_1089771253848666112",
    "13_1191948012077092867"
  ]
}
As a reminder, you can obtain media keys by making a request to the GET accounts/:account_id/media_library endpoint. The composition of the second component object depends on whether you wish to direct a user to a website or encourage them to install an app. The table below summarizes the two options. (Note: all of the listed keys are required.)
WebsiteApp
Specify the component type"type": "DETAILS""type": "BUTTON"
Title/Label"title": "X""label": { "type": "ENUM", "value": "INSTALL" }
Destination"destination": { "type": "WEBSITE", "url": "https://www.x.com" }"destination": { "type": "APP", ... }
Putting this together, an example website carousel JSON POST body is shown below.
{
  "name": "website carousel",
  "components": [
    {
      "type": "SWIPEABLE_MEDIA",
      "media_keys": [
        "13_1089771253848666112",
        "13_1191948012077092867"
      ]
    },
    {
      "type": "DETAILS",
      "title": "X",
      "destination": {
        "type": "WEBSITE",
        "url": "https://www.x.com"
      }
    }
  ]
}
App destination objects within BUTTON components require a country code and at least one app identifier. They optionally accept deep links. For a description of these fields, see the reference documentation. Putting this together, an example app carousel JSON POST body is shown below.
{
  "name": "app carousel",
  "components": [
    {
      "type": "SWIPEABLE_MEDIA",
      "media_keys": [
        "13_1089771253848666112",
        "13_1191948012077092867"
      ]
    },
    {
      "type": "BUTTON",
      "label": {
        "type": "ENUM",
        "value": "INSTALL"
      },
      "destination": {
        "type": "APP",
        "country_code": "US",
        "googleplay_app_id": "com.twitter.android",
        "iphone_app_id": "333903271"
      }
    }
  ]
}

Example

This section demonstrates how to create a video website carousel card and how to use it in a Tweet. As mentioned above, the workflow is the same as what you’re already used to: upload media, create the card, create the Tweet. The only difference is how the card is created. Media To start, either upload new media assets or use existing ones. For details on how to upload new media assets and add them to the Media Library, see our Media Library Guide. Once your media assets are in the Media Library, fetch them using the GET accounts/:account_id/media_library endpoint. Use the media_type request parameter to scope the results to a particular media type.
$ twurl -H ads-api.x.com "/10/accounts/18ce54d4x5t/media_library?media_type=VIDEO"
{
  "request": {
    "params": {
      "account_id": "18ce54d4x5t",
      "media_type": "VIDEO"
    }
  },
  "next_cursor": null,
  "data": [
    {
      "tweeted": true,
      "duration": 5283,
      "name": "Sunrise",
      "file_name": "sunrise.mp4",
      "description": null,
      "media_url": "https://video.twimg.com/amplify_video/1089771253848666112/vid/1280x720/tyL-pUBP7GgkS9bl.mp4?tag=9",
      "poster_media_key": "3_1089771253848666112",
      "media_key": "13_1089771253848666112",
      "created_at": "2019-01-28T06:24:48Z",
      "media_status": "TRANSCODE_COMPLETED",
      "poster_media_url": "https://pbs.twimg.com/amplify_video_thumb/1089771253848666112/img/WOYvToSRZFXUSDzd.jpg",
      "title": null,
      "media_type": "VIDEO",
      "aspect_ratio": "16:9",
      "updated_at": "2019-08-23T19:05:33Z",
      "deleted": false
    },
    {
      "tweeted": true,
      "duration": 15248,
      "name": "snow",
      "file_name": "snow.mp4",
      "description": "Two, three, and to the four",
      "media_url": "https://video.twimg.com/amplify_video/1191948012077092867/vid/1280x720/2cOvadcctqqea6Hx.mp4?tag=13",
      "poster_media_key": "3_1191948012077092867",
      "media_key": "13_1191948012077092867",
      "created_at": "2019-11-06T05:18:46Z",
      "media_status": "TRANSCODE_COMPLETED",
      "poster_media_url": "https://pbs.twimg.com/amplify_video_thumb/1191948012077092867/img/IUbhTRd62SEeIVTf.jpg",
      "title": "One",
      "media_type": "VIDEO",
      "aspect_ratio": "16:9",
      "updated_at": "2020-03-27T22:23:18Z",
      "deleted": false
    }
  ]
}
Carousel Creation Use the POST accounts/:account_id/cards endpoint to create your carousel. Use the media keys from the previous request. Remember, the order in which the media keys are passed in determine the order in which they are rendered.
$ twurl -A "Content-Type: application/json" -X POST -H ads-api.x.com "/10/accounts/18ce54d4x5t/cards" -d '{"name":"website carousel","components":[{"type": "SWIPEABLE_MEDIA","media_keys":["13_1089771253848666112","13_1191948012077092867"]},{"type": "DETAILS","title": "X","destination":{"type":"WEBSITE", "url":"https://www.x.com"}}]}'
{
  "request": {
    "params": {
      "account_id": "18ce54d4x5t"
    }
  },
  "data": {
    "name": "website carousel",
    "components": [
      {
        "type": "SWIPEABLE_MEDIA",
        "media_keys": [
          "13_1089771253848666112",
          "13_1191948012077092867"
        ]
      },
      {
        "type": "DETAILS",
        "title": "X",
        "destination": {
          "type": "WEBSITE",
          "url": "https://www.x.com/",
          "tco_url": "https://t.co/dyTMHWKWZb"
        }
      }
    ],
    "id": "ars7m",
    "created_at": "2020-11-11T07:51:47Z",
    "card_uri": "card://1326432421105995776",
    "updated_at": "2020-11-11T07:51:47Z",
    "deleted": false,
    "card_type": "UNIFIED"
  }
}
Notice that like with other cards, the carousel card response includes a card_uri, which will be used when creating a Tweet. Tweet Use the POST accounts/:account_id/tweet endpoint to create your Tweet. Use the card_uri from the previous request. (Response truncated for readability.)
$ twurl -H ads-api.x.com "/9/accounts/18ce54d4x5t/tweet_previews?tweet_type=PUBLISHED&tweet_ids=1326434098324385792"
{
  "data": {
    "created_at": "Wed Nov 11 07:58:27 +0000 2020",
    "id": 1326434098324385792,
    "id_str": "1326434098324385792",
    "text": "Swipe",
    "truncated": false,
    "entities": {
      "hashtags": [],
      "symbols": [],
      "user_mentions": [],
      "urls": []
    },
    "source": "Ads API Internal Test App",
    "in_reply_to_status_id": null,
    "in_reply_to_status_id_str": null,
    "in_reply_to_user_id": null,
    "in_reply_to_user_id_str": null,
    "in_reply_to_screen_name": null,
    "user": {
      "id": 756201191646691300,
      "id_str": "756201191646691328",
      ...
    },
    "geo": null,
    "coordinates": null,
    "place": null,
    "contributors": [
      2417045708
    ],
    "retweet_count": 0,
    "favorite_count": 0,
    "favorited": false,
    "retweeted": false,
    "possibly_sensitive": false,
    "scopes": {
      "followers": false
    },
    "lang": "en"
  },
  "request": {
    "params": {
      "text": "Swipe",
      "as_user_id": 756201191646691300,
      "card_uri": "card://1326432421105995776",
      "account_id": "18ce54d4x5t"
    }
  }
}
Tweet Previews Use the GET accounts/:account_id/tweet_previews endpoint to see your Tweet.

creative-metadata-tagging

Introduction

This guide is for creative partners, agencies and creative developers to tag assets used within X campaigns to better understand individual asset value and performance. Note: Media assets must only be tagged by the partner or developer creating the media asset. If the user of the media asset did not create the media asset, do not implement metadata tagging. Creative Metadata Tagging provides attribution of images and videos created by Creative Partners wherever the asset is uploaded to X, or whomever the entity that is uploading the asset. To create the connection between the creative asset and the creative partner, the XMP standard is used.

Tagging Creative Assets

The following table shows the identifier types currently available in each image-related resource’s response as well as the corresponding attribute name(s). A tagging tool is needed to tag creative assets. ExifTool, a platform-independent Perl library plus a command-line application for reading, writing, and editing meta information, is recommended. See all supported file types. Follow the provided instructions to install ExifTool. There are also software packages offered by Homebrew to further simplify the installation by providing the exiftool install command for macOS and Linux. Confirm your tool is properly installed by entering exiftool -ver in the command line to return the tool’s version number. Learn more about ExifTool command parameters in ExifTool documentation. Creative partners can assign metadata tags on new or existing creative assets with their X app_id to the contributor XMP tag, and date tag. The creative assets will follow the existing size restrictions when Uploading Media Note: X’s use of the contributor XMP tag ensures metadata captures values for campaigns on X exclusively. exiftool -contributor="<YOUR APP ID>" -creative_file.jpg exiftool -date="<date>" -creative_file.jpg The app_id  can be found in the Developer Console under Projects & Apps. Example: 16489123 The following example adds app_id as the contributor tag and date as the date tag for an image:
app_id:858382169
date:2022-03-13
creative_file: eiffel_tower.jpg
exiftool -contributor=858382169 eiffel_tower.jpg
   1 image files updated
exiftool -date=2022-03-13 eiffel_tower.jpg
  1 image files updated
Verify that your image has been properly tagged:  exiftool -xmp:all -G1 <filename> Example: exiftool -xmp:all -G1 eiffel_tower.jpg
[XMP]        XMP Toolkit            : Image::ExifTool 12.30
[XMP]        Contributor            : 858382169
[XMP]        Date                   : 2022:03:13

Questions?

If you would like to confirm that your tagging and attribution is successful, please provide sample assets that have been tagged to adsapi-program@x.com for a X representative to review.

Full API Reference

For the complete technical reference (all endpoints, parameters, and examples for Cards, Tweets, Media Library, Draft Tweets, Polls, Preroll, Conversation Cards, etc.), see the Creatives API Reference page.