Ads API - UNAUTHORIZED_ACCESS when trying to create sandbox account


#1

Hi there,

I am starting with the Ads API but I get the “UNAUTHORIZED_ACCESS” error when trying to create sand box account. I read in some posts here that I should sing-up to have ads access.

Below is the output response

Array
(
[errors] => Array
(
[0] => Array
(
[code] => UNAUTHORIZED_ACCESS
[message] => This request is not properly authenticated
)

    )

[request] => Array
    (
        [params] => Array
            (
            )

    )

)

APP ID: 15977265. Please help.

Thanks in advance.
Sandeep.S


#2

Hi @sandeepsaripali ,

Please take a look at this post first:

Best,
Shohei


#3

Hi @jrsyo

Thanks for the response.

I worked with all ‘GET’ method end points like get account information, campaigns and line items and all other, which works perfectly and returns response data.

Even ‘PUT’ method works fine where I updated existing campaign name.

Now I am trying to create a new sand-box account using resource url
https://ads-api-sandbox.twitter.com/4/accounts
and which return response as ‘UNAUTHORIZED_ACCESS’

I was using PHP CURL method to access end points.

APP ID: 15977265 which had granted developer access.

Can you please suggest me. Thanks in advance.

Thanks,
Sandeep.S


#4

@sandeepsaripali What’s your Ads account id?


#5

Hi,

Ads account id : 18ce54t2bot


#6

@sandeepsaripali Thank you.

Just to confirm, when you make this POST API call (POST accounts), are you sending OAuth related request headers properly? (assuming you’re using a third-party OAuth library though)

I worked with all ‘GET’ method end points like get account information, campaigns and line items and all other, which works perfectly and returns response data.

You mean, requests for non-sandbox endpoint works just fine, but having this error only for sandbox endpoint, correct? If you have a chance, could you install twurl (our official tool) and see if you see the same error even with this tool? twurl helps us a lot especially for this kind of troubleshooting cases.

Best,
Shohei


#7

Thanks for the response @jrsyo

We are using one of your official PHP library Twitter-API-PHP

Yes all the GET methods and PUT methods works perfectly and returns response data.

Sand box POST methods and other POST methods (add campaign, create asynchronous analytics) in Ads Api end points does not works.

Sorry we cant use twurl, as our platform was been already developed in PHP.

Can you please help me. Thanks in advance.

Thanks,
Sandeep.S


#8

@sandeepsaripali

Sorry we cant use twurl, as our platform was been already developed in PHP.

No, we want you to test with twurl locally for instance. If that works with the same credentials you use in your production, we can exclude permission issue at least, then focus more on your code/environment side.

Sand box POST methods and other POST methods (add campaign, create asynchronous analytics) in Ads Api end points does not works.

OK, so you get UNAUTHORIZED_ACCESS error for POST (sandbox) AND POST (non-sandbox) endpoint? or a different error?

Then, can you provide us your full request parameters (e.g., POST body) that you got an error, or a code snippet?

Best,
Shohei


#9

@jrsyo Thanks

Now I used twurl and get Authorization successful.

Then tried to fetch accounts information

twurl -H “ads-api.twitter.com” “/4/accounts”
which returns accounts information successfully same as curl response.

Now I tried to create a sand-box account, where I run the command

twurl -H “ads-api-sandbox.twitter.com/” “/4/accounts”
which return null data as response.

Can you please suggest me how to create sand-box account so that I can proceed further in creating campaign and so on.

Thanks in advance.

Thanks,
Sandeep.S


#10

@sandeepsaripali

Thanks for the update.

Now I tried to create a sand-box account, where I run the command

twurl -H “ads-api-sandbox.twitter.com/” “/4/accounts”
which return null data as response.

It is fine as it’s sandbox, what you want to do is POST request, so that you can create a new sandbox account.

twurl -X POST -H "ads-api-sandbox.twitter.com" '/4/accounts'

Try this.

Best,
Shohei


#11

@jrsyo Thanks.

It works and sandbox-account created successfully. Now I will try to create campaigns and further.

In other side, it was not working through PHP CURL method. Can you suggest me in this.

Thanks in advance

Thanks,
Sandeep.S


#12

@sandeepsaripali

OK, since twurl worked for the same endpoint, that simply means the issues is something on your side…
Please double check your code. Also FYI, there’s an also twitter-php-ads-sdk you could try.

In other side, it was not working through PHP CURL method. Can you suggest me in this.

It is difficult to “guess” without knowing your actual code. But it’s highly likely around OAuth problem.

such as: https://developer.twitter.com/en/docs/ads/general/guides/getting-started#http-oauth

The API is strict with HTTP 1.1 and OAuth. Ensure that you’re encoding reserved characters appropriately within URLs and POST bodies before preparing OAuth signature base strings.

Best,
Shohei


#13

@jrsyo Thank you for the SDK reference.

I had successfully created a sandbox account and tried to use the newly generated account id for further calls, but it results ‘Account xxxx was not found’.

Can you please help me. Thanks in advance

Thanks,
Sandeep.S


#14

In your second request, you’re not making a sandbox request. See the host you’ve specified.


#15

@juanshishido Thanks.

I had corrected and pointed to sandbox request and it was working fine now.

Thanks,
Sandeep.S


#16

Hi

I had created a test campaign with line item with sand box account. Can I get sample metrics information for this line item? where I received empty response.

Thanks,
Sandeep.S


#17

@sandeepsaripali Unfortunately, it’s not possible at this moment as it’s a sandbox as you know.

Best,
Shohei


#18

@jrsyo Thanks for the response.