Creating an Image Direct Card with the Twitter Ads API, Twurl, and PyCharm


Required Parameters:

  • account_id
  • first_cta
  • first_cta_welcome_message_id
  • second_cta
  • second_cta_welcome_message_id
  • third_cta
  • third_cta_welcome_message_id
  • fourth_cta
  • fourth_cta_welcome_message_id
  • name
  • recipient_user_id
  • image_media_key

Request

twurl -X POST -H ads-api.twitter.com "/3/accounts/18ce54jkujt/cards/image_direct_message?name=one cta image dm card&first_cta=CTA 1&first_cta_welcome_message_id=975846176053489668&second_cta=CTA 2&second_cta_welcome_message_
id=975846179819917318&third_cta=CTA 3&third_cta_welcome_message_id=975846178599337989&fourth_cta=CTA 4&fourth_cta_welcome_message_id=975846177261400070&recipient_user_id=878264826199502848&image_media_key=3_975852910922772480"


Response

{
  "data": {
    "second_cta_welcome_message_id": "975846179819917318",
    "name": "four cta image dm card",
    "first_cta": "CTA 1",
    "first_cta_welcome_message_id": "975846176053489668",
    "image_display_height": "628",
    "image": "https://pbs.twimg.com/media/DYrtDVyVMAACeKy.jpg",
    "fourth_cta_welcome_message_id": "975846177261400070",
    "recipient_user_id": "878264826199502848",
    "preview_url": null,
    "fourth_cta": "CTA 4",
    "id": "5hhb9",
    "second_cta": "CTA 2",
    "account_id": "18ce54jkujt",
    "third_cta_welcome_message_id": "975846178599337989",
    "created_at": "2018-03-19T22:07:16Z",
    "third_cta": "CTA 3",
    "image_display_width": "1202",
    "card_uri": "card://975856255540649986",
    "updated_at": "2018-03-19T22:07:16Z",
    "deleted": false,
    "card_type": "IMAGE_DIRECT_MESSAGE"
  },
  "request": {
    "params": {
      "second_cta_welcome_message_id": "975846179819917318",
      "name": "four cta image dm card",
      "first_cta": "CTA 1",
      "first_cta_welcome_message_id": "975846176053489668",
      "image_display_height": "628",
      "image": "https://pbs.twimg.com/media/DYrtDVyVMAACeKy.jpg",
      "fourth_cta_welcome_message_id": "975846177261400070",
      "recipient_user_id": "878264826199502848",
      "fourth_cta": "CTA 4",
      "image_media_key": "3_975852910922772480",
      "second_cta": "CTA 2",
      "account_id": "18ce54jkujt",
      "third_cta_welcome_message_id": "975846178599337989",
      "third_cta": "CTA 3",
      "image_display_width": "1202",
      "card_type": "IMAGE_DIRECT_MESSAGE"
    }
  }
}


Add the DM Card to a Tweet

Request

twurl -X POST -H ads-api.twitter.com "/3/accounts/18ce54jkujt/tweet?text=Image Direct Message Card w/ Four CTAs&card_uri=card://975856255540649986&as_user_id=878264826199502848&trim_user=true"


Response

{
  "data": {
    "created_at": "Mon Mar 19 22:07:34 +0000 2018",
    "id": 975856332883537900,
    "id_str": "975856332883537920",
    "text": "Image Direct Message Card w/ Four CTAs",
    "truncated": false,
    "entities": {
      "hashtags": [],
      "symbols": [],
      "user_mentions": [],
      "urls": []
    },
    "source": "<a href=\"https://twitter.com/SamSchmir\" rel=\"nofollow\">Ads API Client</a>",
    "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": 878264826199502800,
      "id_str": "878264826199502848"
    },
    "geo": null,
    "coordinates": null,
    "place": null,
    "contributors": null,
    "retweet_count": 0,
    "favorite_count": 0,
    "favorited": false,
    "retweeted": false,
    "possibly_sensitive": false,
    "scopes": {
      "followers": false
    },
    "card": {
      "name": "2586390716:image_direct_message",
      "url": "card://975856255540649986",
      "card_type_url": "http://card-type-url-is-deprecated.invalid",
      "binding_values": {
        "cta2": {
          "type": "STRING",
          "string_value": "CTA 2"
        },
        "cta1": {
          "type": "STRING",
          "string_value": "CTA 1"
        },
        "cta4_wm_id": {
          "type": "STRING",
          "string_value": "975846177261400070"
        },
        "cta3_wm_id": {
          "type": "STRING",
          "string_value": "975846178599337989"
        },
        "cta3": {
          "type": "STRING",
          "string_value": "CTA 3"
        },
        "card_id": {
          "type": "STRING",
          "string_value": "0"
        },
        "cta2_wm_id": {
          "type": "STRING",
          "string_value": "975846179819917318"
        },
        "cta1_wm_id": {
          "type": "STRING",
          "string_value": "975846176053489668"
        },
        "cta4": {
          "type": "STRING",
          "string_value": "CTA 4"
        },
        "recipient": {
          "type": "USER",
          "user_value": {
            "id_str": "878264826199502848",
            "path": []
          }
        },
        "image_small": {
          "type": "IMAGE",
          "image_value": {
            "url": "https://pbs.twimg.com/media/DYrtDVyVMAACeKy.jpg",
            "width": 1202,
            "height": 628,
            "alt": null
          }
        },
        "image": {
          "type": "IMAGE",
          "image_value": {
            "url": "https://pbs.twimg.com/media/DYrtDVyVMAACeKy.jpg",
            "width": 1202,
            "height": 628,
            "alt": null
          }
        },
        "image_large": {
          "type": "IMAGE",
          "image_value": {
            "url": "https://pbs.twimg.com/media/DYrtDVyVMAACeKy.jpg",
            "width": 1202,
            "height": 628,
            "alt": null
          }
        },
        "image_x_large": {
          "type": "IMAGE",
          "image_value": {
            "url": "https://pbs.twimg.com/media/DYrtDVyVMAACeKy.jpg",
            "width": 1202,
            "height": 628,
            "alt": null
          }
        },
        "image_color": {
          "type": "IMAGE_COLOR",
          "image_color_value": {
            "palette": [
              {
                "percentage": 45.2,
                "rgb": {
                  "red": 255,
                  "green": 245,
                  "blue": 111
                }
              },
              {
                "percentage": 41.52,
                "rgb": {
                  "red": 247,
                  "green": 171,
                  "blue": 173
                }
              },
              {
                "percentage": 2.8,
                "rgb": {
                  "red": 170,
                  "green": 161,
                  "blue": 97
                }
              },
              {
                "percentage": 2.5,
                "rgb": {
                  "red": 128,
                  "green": 100,
                  "blue": 142
                }
              },
              {
                "percentage": 1.96,
                "rgb": {
                  "red": 191,
                  "green": 194,
                  "blue": 187
                }
              }
            ]
          }
        },
        "card_url": {
          "type": "STRING",
          "string_value": "https://twitter.com",
          "scribe_key": "card_url"
        }
      },
      "users": {
        "878264826199502848": {
          "id": 878264826199502800,
          "id_str": "878264826199502848",
          "name": "DMs Playground",
          "screen_name": "DMsPlayground",
          "location": "East Coast, USA",
          "url": null,
          "description": "",
          "protected": false,
          "followers_count": 1,
          "friends_count": 0,
          "listed_count": 0,
          "created_at": "Fri Jun 23 14:53:46 +0000 2017",
          "favourites_count": 0,
          "utc_offset": -25200,
          "time_zone": "Pacific Time (US & Canada)",
          "geo_enabled": false,
          "verified": false,
          "statuses_count": 4,
          "lang": "en",
          "contributors_enabled": false,
          "is_translator": false,
          "is_translation_enabled": false,
          "profile_background_color": "F5F8FA",
          "profile_background_image_url": null,
          "profile_background_image_url_https": null,
          "profile_background_tile": false,
          "profile_image_url": "http://pbs.twimg.com/profile_images/955114267203833856/QAKctPM__normal.jpg",
          "profile_image_url_https": "https://pbs.twimg.com/profile_images/955114267203833856/QAKctPM__normal.jpg",
          "profile_link_color": "1DA1F2",
          "profile_sidebar_border_color": "C0DEED",
          "profile_sidebar_fill_color": "DDEEF6",
          "profile_text_color": "333333",
          "profile_use_background_image": true,
          "has_extended_profile": false,
          "default_profile": true,
          "default_profile_image": false,
          "following": false,
          "follow_request_sent": false,
          "notifications": false,
          "translator_type": "none"
        }
      },
      "card_platform": {
        "platform": {
          "device": {
            "name": "AdsApi",
            "version": "13"
          },
          "audience": {
            "name": "production",
            "bucket": null
          }
        }
      }
    },
    "lang": "en"
  },
  "request": {
    "params": {
      "as_user_id": 878264826199502800,
      "text": "Image Direct Message Card w/ Four CTAs",
      "account_id": "18ce54jkujt",
      "trim_user": true,
      "card_uri": "card://975856255540649986"
    }
  }
}