Problem Excluding Tailored Audience Via Batch Endpoint

tailored-audiences
api

#1

I’m trying to create a targeting criteria to exclude a tailored audience. However, each request comes back as a normal inclusion of the tailored audience.

$ twurl -H ads-api.twitter.com --header "Content-Type: application/json" -X POST -d '[{"operation_type":"Create","params":{"line_item_id":"au35p","targeting_type":"TAILORED_AUDIENCE","targeting_value":"28us8","operator_type":"NE"}}]' "/2/batch/accounts/18ce54jsgq3/targeting_criteria"

Is this the correct way to submit this request, or is there a bug in the endpoint?


#2

Thanks, @jpwinans. At a quick glance, this seems to be related to this thread. Please confirm.


#3

That’s the thread that led me to the format for the request above. So it’s similar, but I’m not following the exact same path. Mine simply doesn’t work on first attempt. I’m also using v2, but I confirmed it doesn’t work in v1 either.


#4

Thanks for the information.

Mine simply doesn’t work on first attempt.

The targeting is not being created then? Please provide the response you’re seeing from the above request.


#5

It is being created, it’s just created as an inclusion, rather than an exclusion. Here’s the response in Ruby hash form:

       :data => [
        [0] {
                           :line_item_id => "au39o",
                                   :name => "Custom audience targeting",
                                     :id => "h9dunb",
            :tailored_audience_expansion => false,
                          :operator_type => "EQ",
                             :created_at => "2018-01-09T19:01:34Z",
                        :targeting_value => "28us8",
                             :updated_at => "2018-01-09T19:01:34Z",
                 :tailored_audience_type => "CRM",
                                :deleted => false,
                         :targeting_type => "TAILORED_AUDIENCE"
        }
    ],
    :request => [
        [0] {
                    :params => {
                   :line_item_id => "au39o",
                 :targeting_type => "TAILORED_AUDIENCE",
                :targeting_value => "28us8",
                     :account_id => "18ce54jsgq3"
            },
            :operation_type => "Create"
        }
    ]
}```

#6

That is strange. I’ve just added targeting for a tailored audience exclusion and it created successfully and how I expect:

$ twurl -H ads-api.twitter.com -X POST -A "Content-Type: application/json" -d '[{"operation_type":"Create","params":{"line_item_id":"8v7j9","targeting_type":"TAILORED_AUDIENCE","targeting_value":"2gz4y", "operator_type":"NE"}}]' "/2/batch/accounts/18ce54d4x5t/targeting_criteria"
{
  "data": [
    {
      "line_item_id": "8v7j9",
      "name": "Custom audience targeting",
      "id": "h9e2tv",
      "tailored_audience_expansion": false,
      "operator_type": "NE",
      "created_at": "2018-01-09T20:43:45Z",
      "targeting_value": "2gz4y",
      "updated_at": "2018-01-09T20:43:45Z",
      "tailored_audience_type": "EXCLUDED_CRM",
      "deleted": false,
      "targeting_type": "TAILORED_AUDIENCE"
    }
  ],
  "request": [
    {
      "params": {
        "line_item_id": "8v7j9",
        "account_id": "18ce54d4x5t",
        "operator_type": "NE",
        "targeting_value": "2gz4y",
        "targeting_type": "TAILORED_AUDIENCE"
      },
      "operation_type": "Create"
    }
  ]
}

Are you using an SDK for this? Any additional information that you think may help?


#7

I am using the Ruby SDK. I’ve tried creating two ways.

First:

targeting_criteria = TwitterAds::TargetingCriteria.new(@account)
targeting_criteria.line_item_id = line_item.id
targeting_criteria.targeting_type = 'TAILORED_AUDIENCE'
targeting_criteria.targeting_value = audience_id
targeting_criteria.tailored_audience_type = 'EXCLUDED_CRM'

TwitterAds::TargetingCriteria.batch_save(@account, [targeting_criteria])

This results in the following params in batch_save method of batch.rb:

headers = { 'Content-Type' => 'application/json' }
resource = "/2/batch/accounts/18ce54jsgq3/targeting_criteria"
json_body = [{"params"=>{:line_item_id=>"auczt", :targeting_type=>"TAILORED_AUDIENCE", :targeting_value=>"28us8", :tailored_audience_type=>"EXCLUDED_CRM"}, "operation_type"=>"Create"}]
response = TwitterAds::Request.new(account.client,
                                           :post,
                                           resource,
                                           headers: headers,
                                           body: json_body.to_json).perform

Results in this response:

{:data=>[{:line_item_id=>"auczt", :name=>"Custom audience targeting", :id=>"h9ucbg", :tailored_audience_expansion=>false, :operator_type=>"EQ", :created_at=>"2018-01-10T14:58:32Z", :targeting_value=>"28us8", :updated_at=>"2018-01-10T14:58:32Z", :tailored_audience_type=>"CRM", :deleted=>false, :targeting_type=>"TAILORED_AUDIENCE"}], :request=>[{:params=>{:line_item_id=>"auczt", :targeting_type=>"TAILORED_AUDIENCE", :targeting_value=>"28us8", :account_id=>"18ce54jsgq3"}, :operation_type=>"Create"}]}

Seeing that that didn’t work, I tried creating the following request by hand:

json_body = [{"params"=>{:line_item_id=>"audb9", :targeting_type=>"TAILORED_AUDIENCE", :targeting_value=>"28us8", :operation_type=>"NE"}, "operation_type"=>"Create"}]
headers = { 'Content-Type' => 'application/json' }
response = TwitterAds::Request.new(account.client,
                            :post,
                            "/2/batch/accounts/18ce54jsgq3/targeting_criteria",
                            headers: headers,
                            body: json_body.to_json).perform

Which results in response:

{:data=>[{:line_item_id=>"audb9", :name=>"Custom audience targeting", :id=>"h9uphn", :tailored_audience_expansion=>false, :operator_type=>"EQ", :created_at=>"2018-01-10T15:17:08Z", :targeting_value=>"28us8", :updated_at=>"2018-01-10T15:17:08Z", :tailored_audience_type=>"CRM", :deleted=>false, :targeting_type=>"TAILORED_AUDIENCE"}], :request=>[{:params=>{:line_item_id=>"audb9", :targeting_type=>"TAILORED_AUDIENCE", :targeting_value=>"28us8", :account_id=>"18ce54jsgq3"}, :operation_type=>"Create"}]}

I suppose I could drill into the TwitterAds::Request call, but my expectation was that it was sending the request body as it appeared in json_body above. Very confusing.