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.