Twitter Audience API - add users

oauth

#1

Hi,

I’m trying to use the tailored audiences REST api according to the documentation here:
https://developer.twitter.com/en/docs/ads/audiences/api-reference/audience

Problem is: I keep getting an error: UNAUTHORIZED_ACCESS: This request is not properly authenticated.

The problem is with the complex body that is required for this API request, because I succeed in sending a simple request with a simple body (like creating a tailored audience).

My question: how should I pass a POST body that is an array with nested objects? How do I use it to create a signature? The signature need keys for each body element, but what is the key when the body is just an array, like in the documentation?

Could you maybe provide a twurl example?

Thank you!
Ido


#2

Hey @superquery,

Can you please provide the exact request and response bodies of the request using twurl, along with the actual versus expected output?

We’d recommend using twurl here since it will handle the authentication portion for you, to ensure there’s no issues with the oAuth setup itself.

Thanks!


#3

Hi,

This is the twurl I’ve used. I expected to get a success response, but got an empty response instead:

 twurl -X POST -H "https://ads-api.twitter.com" "/4/accounts/<account_id>/tailored_audiences/<audience_id>/users" --trace --data "[
  {
    "operation_type": "Update",
    "params": {
      "effective_at": "2018-05-15T00:00:00Z",
      "expires_at": "2019-01-01T07:00:00Z",
      "users": [
        {
          "email": [
            "4798b8bbdcf6f2a52e527f46a3d7a7c9aefb541afda03af79c74809ecc6376f3"
          ],
          "phone_number": [
            "34d56c7159a7eea941f359653029410f813f65a1d2d13ecc5ccbdd5a8cb755cf",
            "815d1329cc82c1bb915dbe9d5ad489ff5c6b8322370f95d03e4cca4fcf4590af"
          ]
        },
        {
          "email": [
            "5bf13d5ad4200407c5bc8b9bb578e425d05ef936fd488e3799a9d0806669223c"
          ],
          "phone_number": [
            "34d56c7159a7eea941f359653029410f813f65a1d2d13ecc5ccbdd5a8cb755cf",
            "00e7b76c9739dec57f4c4a20ec021a20ffcf26bd00f519b17ea00f0ed6048f85"
          ]
        }
      ]
    }
  }]"

#4

Hi,

So I was able to resolve my two issues:

  1. To make the twurl work, you need at a content type heeader, like so:
twurl --header 'Content-Type: application/json' -X POST -H "https://ads-api.twitter.com" "/4/accounts/18ce54qb1nd/tailored_audiences/2vezg/users" --trace --data '[<array_content>]'
  1. When sending an array in the body, it should not be included at all in the signature generation process.

#5

Glad to hear you were able to resolve the issue. You’re correct on both counts. Let us know if there’s any other questions.

Thanks!


#6

Hi,

I had the same initial error, and after following the fixes @superquery posted, I ended up with the following twurl command:

twurl --header 'Content-Type: application/json' -X POST -H "https://ads-api.twitter.com" "/4/accounts/18ce53wvcf8/tailored_audiences/2v8fm/users" --trace --data '[
    {
        "operation_type": "Update",
        "params": {
            "users": [
                {
                    "email": [
                        "75f4499b59200d38f057e967e297590ab2ebaad09283ddcb3e66ffb1f1a9f395"
                    ]
                }
            ]
        }
    }
]'

Sadly, this then gives me an error of:

{"errors":[{"code":87,"message":"Client is not permitted to perform this action."}]}

This error code seems to mean that I’m hitting the wrong endpoint as according to this page.

Authentication doesn’t seem to be the problem here, since this twurl command seems to go through successfully and returns the expected response:

twurl -X GET -H "https://ads-api.twitter.com" "/4/accounts/18ce53wvcf8/tailored_audiences/2v8fm" --trace

I’d be very grateful for any help!


#7

It looks like your client app ID doesn’t have the necessary permissions to access that endpoint. I’d recommend reaching out to your Twitter rep to get access.

Hope that helps!


#8

I was trying to fetch fields like clicks, impressions, Spend/Cost etc. for each audience id from Twitter API. I tried several endpoints but not able to get the required data.Is this possible to fetch these fields at audience level