How to get the campaign id (or line item id) of the one in which the specific tweet is promoted?


#1

How to get the campaign id of the one in which the specific tweet is promoted?

・ What I have tried?

Step1. Get the tweet id like the following.
twurl -H “https://ads-api.twitter.com” “/2/accounts/18ce54iditw/scoped_timeline?scoped_to=none” | jq '.data[] | select(.text==“テストカード https://t.co/QdOT7ZEVGX”).id_str ’

Step2. Get the mapping of tweet_id and id .

twurl -H “https://ads-api.twitter.com” “/2/accounts/18ce54iditw/promoted_tweets?with_total_count=true” | jq ‘.data[] | [.tweet_id, .id]’

Step3. I failed to find the id of the specific promoted tweet within the mapping get in Step2.


#2

Could anyone help me?


#3

Hi, @wenping.wang. Once you know the Tweet (long value) you’re interested in, you can use the GET accounts/:account_id/promoted_tweets endpoint, as you suggested, along with jq's select operator (see the docs). (Note: you may need to page through the promoted_tweets results.)

$ twurl -H ads-api.twitter.com "/2/accounts/18ce54d4x5t/promoted_tweets" | jq '.data[] | select(.tweet_id=="870732345061457920")'
{
  "line_item_id": "93evz",
  "id": "1dsn1m",
  "entity_status": "ACTIVE",
  "created_at": "2017-06-15T15:05:37Z",
  "updated_at": "2017-06-15T15:05:38Z",
  "approval_status": "ACCEPTED",
  "tweet_id": "870732345061457920",
  "deleted": false
}
{
  "line_item_id": "9vek8",
  "id": "1hl0jz",
  "entity_status": "ACTIVE",
  "created_at": "2017-09-08T04:39:35Z",
  "updated_at": "2017-09-08T04:39:36Z",
  "approval_status": "ACCEPTED",
  "tweet_id": "870732345061457920",
  "deleted": false
}

Then, you can use the GET accounts/:account_id/line_items endpoint with the line_item_ids parameter, using jq to select just the campaign IDs:

$ twurl -H ads-api.twitter.com "/2/accounts/18ce54d4x5t/line_items?line_item_ids=93evz,9vek8" | jq '.data[] | .campaign_id'
"8qo09"
"9fymv"

Please let us know if this is what you’re looking for.

Thanks!


#4

Thanks for the reply.

As I have described in Step3,
I can not find the Tweet ID (887477102915670017) in the response of Step2.

The command I used in Step2.

twurl -H "https://ads-api.twitter.com" "/2/accounts/18ce54iditw/scoped_timeline?scoped_to=none" | jq '.data[] | select(.text=="テストカード     https://t.co/QdOT7ZEVGX") | [.id_str, .text] '
[
  "887477102915670017",
  "テストカード     https://t.co/QdOT7ZEVGX"
]

The command I used in Step3.

twurl -H "https://ads-api.twitter.com" "/2/accounts/18ce54iditw/promoted_tweets?count=1000" | jq '.data[] | .tweet_id'

"882850608893485057"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"912903918258139138"
"912903918258139138"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"916103098380124161"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"907512428568576000"
"907512428568576000"
"907512428568576000"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"918286053382823936"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"903052236086886400"
"907512428568576000"
"907506741675302917"
"907484813006848001"
"907159329396072450"
"920085164822224896"
"920085164822224896"
"920085164822224896"
"920085164822224896"
"920164699601174529"


#5

Thanks for these additional details, @wenping.wang.

The issue is that the line item (and campaign) this Tweet (887477102915670017) is associated with is in draft ("entity_status": "DRAFT").

To view promoted_tweets under draft line items, use the draft_only parameter (more info here):

# promoted Tweet
$ twurl -H ads-api.twitter.com "/2/accounts/18ce54iditw/promoted_tweets?draft_only=true" | jq '.data[] | select(.tweet_id=="887477102915670017")'
{
  "line_item_id": "9g9pz",
  "id": "1flj3u",
  "entity_status": "ACTIVE",
  "created_at": "2017-07-24T09:18:28Z",
  "updated_at": "2017-08-21T06:30:40Z",
  "approval_status": "ACCEPTED",
  "tweet_id": "887477102915670017",
  "deleted": false
}
# line item in draft
$ twurl -H ads-api.twitter.com "/2/accounts/18ce54iditw/line_items/9g9pz"
{
  "request": {
    "params": {
      "line_item_id": "9g9pz",
      "account_id": "18ce54iditw"
    }
  },
  "data": {
    "bid_type": "MAX",
    "advertiser_user_id": 870127656477483008,
    "name": "Untitled",
    "placements": [
      "TWITTER_PROFILE",
      "TWITTER_TIMELINE"
    ],
    "start_time": null,
    "bid_amount_local_micro": 227000000,
    "automatically_select_bid": false,
    "advertiser_domain": null,
    "target_cpa_local_micro": null,
    "primary_web_event_tag": null,
    "charge_by": "ENGAGEMENT",
    "product_type": "PROMOTED_TWEETS",
    "end_time": null,
    "bid_unit": "ENGAGEMENT",
    "total_budget_amount_local_micro": null,
    "objective": "TWEET_ENGAGEMENTS",
    "id": "9g9pz",
    "entity_status": "DRAFT",
    "account_id": "18ce54iditw",
    "optimization": "DEFAULT",
    "categories": [],
    "currency": "JPY",
    "created_at": "2017-07-18T02:27:34Z",
    "tracking_tags": [],
    "updated_at": "2017-07-18T02:27:34Z",
    "include_sentiment": "ALL",
    "campaign_id": "91r1v",
    "creative_source": "MANUAL",
    "deleted": false
  }
}

Hope this helps.

We’re considering ways to make this easier to use. We’ll provide updates here.

Thanks!