Add users to tailored audience endpoint

tailored-audiences
ads
api
twitterads

#1

Hello,

We are trying to use https://ads-api.twitter.com/4/accounts/xxx/tailored_audiences/yyy/users for adding users to the tailored audience created.

var Twit = require('twit');

 var twit = new Twit({
   consumer_key: '11111111111',
   consumer_secret: '22222222222222',
   access_token: '33333333333333333',
   access_token_secret: '444444444444444444444'
 });
 
 let uri = 'https://ads-api.twitter.com/4/accounts/xxxx/tailored_audiences/yyyyyyyy/users';
 
 var data = [
   {
    "operation_type": "Update",
    "params": {
      // "effective_at": "2018-12-15T00:00:00Z",
      // "expires_at": "2019-01-01T07:00:00Z",
      "users": [
        { "email": ["297a106d2f675322f2adc7736e0918a1649a69db4fcc536ce6253e503708bc21"] },
        { "email": ["444ae71e4b6e46aabcca5809171f9738b3f1b91920a1c0d0492a1fedaa8d4e37"] },
        { "email": ["3959d62f120d16d4995e5234153fec924b20248ec6be3b731a1e38e3ce142056"] },
        { "email": ["f0aede543d674696b35ab5cd81656a890e1707853d1f5f628fbf7788079c4288"] },
        { "email": ["e146896acce55f1bd204a4027e63e90ccda59a025daf4c401a7b4efc7068ef97"] },
        { "email": ["92518842f7d568637572f875296905ff0346c61e8e565dfd251e6c20dec03fed"] },
        { "email": ["ae8fc40e9143454804976a29a21ed4456eaaca2323db48f61e2b4da9bf33d6cc"] },
        { "email": ["f1ceb1a898bb23ffa6a41453e6cf6dc79839297252377448976f84d942c2f58a"] },
        { "email": ["2bf0c365f2ed5aaf569d06e9fb6c00c162de1d365dbb543d05ecf7aa385d4e7d"] },
        { "email": ["757c9c3c6753ed0915dafda39b8855f0ea16e9dfe65747ed965d864996dfa8fe"] }
]
    }
  }
];
 twit.post(uri, data, function (err, data) {
   console.log(err, data);
});

We are getting error as undefined and data as empty string(’’).

Could u please lets us know are we missing?


#2

There is an issue with the twit npm package, By using request package I can add users to the endpoint.

var request = require("request");

var oauth = {
  consumer_key: '11111111111',
  consumer_secret: '22222222222',
  token: '33333333333333',
  token_secret: '4444444444444444444'
}

request.post({
  url: "https://ads-api.twitter.com/4/accounts/xxxxxxxxxx/tailored_audiences/yyyyyyyyy/users",
  json: [{
    "operation_type": "Update",
    "params": {
      "users": [
        {
          "email": ["297a106d2f675322f2adc7736e0918a1649a69db4fcc536ce6253e503708bc21"]
        },
        {
          "email": ["444ae71e4b6e46aabcca5809171f9738b3f1b91920a1c0d0492a1fedaa8d4e37"]
        },
        {
          "email": ["3959d62f120d16d4995e5234153fec924b20248ec6be3b731a1e38e3ce142056"]
        }
      ]
    }
  }],
  oauth: oauth
}, function(e, r, body) {
  console.log(e, body);
});

The above code works without error.


#3

Hi @Way2Target_Ads ,

Thanks for sharing this.

FYI, I’m not so familiar with twit but it looks like this npm package doesn’t seem to support Ads API well as Ads API uses a different Host name ads-api.twitter.com than our public Twitter API (e.g., api.twitter.com).

Also, if you look at the code:

there’s a condition that converts POST body into URL path and this will be triggered for your request because that endpoint path is not in JSONPAYLOAD_PATHS array for sure:

This might be an issue. Anyway, glad you got it worked with request package.

Best,
Shohei


#4

Thanks for the explanation.