Creating a signature with JSON paramters

Hi,

I’m trying to trigger a tailored audience request.

I was able to create an empty tailored audience but I’m unable to successfully call the ‘tailored audience users’ in order to push users into this empty audience.
I went over the documentation in the following URL and can’t find what am I doing wrong

https://developer.twitter.com/en/docs/ads/audiences/api-reference/audience
I’m getting the following error:

"code":"UNAUTHORIZED_ACCESS",
"message":"This request is not properly authenticated"

I suspect the issue is with creating the OAuth signature for the call.
Since both the ‘params’ and ‘users’ parameters are of type JSON I’m not sure if I should include them in the signature base string and if yes how exactly?
Thanks

Hello, @Vajrakaya, and welcome!
It sounds like the issue is with the POST accounts/:account_id/tailored_audiences/:tailored_audience_id/users endpoint. Since the TA create request is successful, I imagine the issue might be with not encoding reserved characters. Please see the following post:


Please let us know if, after making the adjustments listed in that post, you’re able to update the audience with users.
Thanks!

Hey @Vajrakaya ,
Did you set Content-Type: application/json request header for the POST request? I guess that’s the missing piece here.

Hi @Ananya, @Spriha.
The header is indeed set with ‘Content-Type: application/json’.
I also checked the encoding and I can’t find any problem with it.

This is the request body for example:

[
  {
    "operation_type": "Update",
    "params": {
      "effective_at": "2018-05-15T00:00:00Z",
      "expires_at": "2019-01-01T07:00:00Z",
      "users": [
        {
          "email": [
            "4798b8bbdcf6f2a52e527f46a3d7a7c9aefb541afda03af79c74809ecc6376f3"
          ],
          "phone_number": [
            "34d56c7159a7eea941f359653029410f813f65a1d2d13ecc5ccbdd5a8cb755cf"
          ]
        },
    
        {
          "email": [
            "5bf13d5ad4200407c5bc8b9bb578e425d05ef936fd488e3799a9d0806669223c"
          ],
          "phone_number": [
            "34d56c7159a7eea941f359653029410f813f65a1d2d13ecc5ccbdd5a8cb755cf"
          ]
        }
      ]
    }
  }
]

And this is my encoded signature base string (without keys)

POST
&https%3A%2F%2Fads-api.twitter.com%2F6%2Faccounts%2F<ACCOUNT_ID>%2Ftailored_audiences%2F<AUDIENCE_ID>%2Fusers
&oauth_consumer_key%3D<CONSUMER_KEY>
%26oauth_nonce%3D8cf42dd97343adf7715dcc09781927d4
%26oauth_signature_method%3DHMAC-SHA1
%26oauth_timestamp%3D1567672959
%26oauth_token%3D<OAUTH_TOKEN>
%26oauth_version%3D1.0
%26operation_type%3DUpdate
%26params%3D%7B%22effective_at%22%3A%222018-05-15T00%3A00%3A00Z%22%2C%22expires_at%22%3A%222019-01-01T07%3A00%3A00Z%22%2C%22users%22%3A%5B%7B%22email%22%3A%5B%224798b8bbdcf6f2a52e527f46a3d7a7c9aefb541afda03af79c74809ecc6376f3%22%5D%2C%22phone_number%22%3A%5B%2234d56c7159a7eea941f359653029410f813f65a1d2d13ecc5ccbdd5a8cb755cf%22%5D%7D%2C%7B%22email%22%3A%5B%225bf13d5ad4200407c5bc8b9bb578e425d05ef936fd488e3799a9d0806669223c%22%5D%2C%22phone_number%22%3A%5B%2234d56c7159a7eea941f359653029410f813f65a1d2d13ecc5ccbdd5a8cb755cf%22%5D%7D%5D%7D
%26users%3D%5B%7B%22email%22%3A%5B%224798b8bbdcf6f2a52e527f46a3d7a7c9aefb541afda03af79c74809ecc6376f3%22%5D%2C%22phone_number%22%3A%5B%2234d56c7159a7eea941f359653029410f813f65a1d2d13ecc5ccbdd5a8cb755cf%22%5D%7D%2C%7B%22email%22%3A%5B%225bf13d5ad4200407c5bc8b9bb578e425d05ef936fd488e3799a9d0806669223c%22%5D%2C%22phone_number%22%3A%5B%2234d56c7159a7eea941f359653029410f813f65a1d2d13ecc5ccbdd5a8cb755cf%22%5D%7D%5D

Shouldn’t this work? I’m still getting the same error…
Thank you,

Sagi

@Vajrakaya since you’re trying to send a JSON body data not a form encoded, it should not be included in the base string as per OAuth spec.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.