Sandbox API - Create account not working


#1

I am trying to use the sandbox environment to create an account. I am using this url – https://ads-api-sandbox.twitter.com/1/accounts and passing a name param. I am using the same client secret, token etc that we use for our production account. But I get this error –

{
“errors”: [
{
“code”: “UNAUTHORIZED_ACCESS”,
“message”: “This request is not properly authenticated”
}
],
“request”: {
“params”: {}
}
}

Has anyone created an account via SANDBOX API recently?


#4

Hi @TeamUpatel,

Thanks for reaching out. This response indicates that there is an issue with how OAuth is being used in the request. Note that the Ads API requires OAuth 1.0A and HTTPS. What OAuth library are you using? Let’s work together to resolve the authentication issue first. Could you please paste in the request you’re using?

Thank you,
Juan


#5

Hi @juanshishido, below is the curl request i used. I generated that request using twitter oauth signature generator –

curl --request ‘POST’ ‘https://ads-api-sandbox.twitter.com/1/accounts/’ --header ‘Authorization: OAuth oauth_consumer_key="{consumer_key}", oauth_nonce=“2eada2d8d8f3f4e88fcbd15509faa590”, oauth_signature=“FYLtbHuWDVm%2BvGZCACWb83J%2F%2Flg%3D”, oauth_signature_method=“HMAC-SHA1”, oauth_timestamp=“1468540904”, oauth_token="{oauth_token}", oauth_version=“1.0”’ -d ‘{“name”: “adconion sandbox test account”}’ --verbose

Here is the error i see –

  • Connection #0 to host ads-api-sandbox.twitter.com left intact
    {“errors”:[{“code”:“UNAUTHORIZED_ACCESS”,“message”:“This request is not properly authenticated”}],“request”:{“params”:{}}}

#6

the data has to be passed as querystring=value. It you pass it as JSON, you’ll see the error above.

Here is a working query:

curl --request 'POST' 'https://ads-api-sandbox.twitter.com/1/accounts/' --data 'name=sandbox_account' \
--header 'Authorization: OAuth oauth_consumer_key="{consumer_key_value}", oauth_nonce="{nonce_value}", \
oauth_signature="{oauth_signature_value}", oauth_signature_method="HMAC-SHA1",
oauth_timestamp="1468880095", oauth_token="{token_value}", oauth_version="1.0"' --verbose`

And part of the result that shows that it works fine:

< HTTP/1.1 200 OK
< content-disposition: attachment; filename=json.json
< content-length: 338
< content-type: application/json;charset=utf-8
< date: Mon, 18 Jul 2016 22:15:07 GMT
< server: tsa_a
< set-cookie: guest_id=v1%3A146888010738839623; Domain=.twitter.com; Path=/; Expires=Wed, 18-Jul-2018     22:15:07 UTC
< strict-transport-security: max-age=631138519
< x-access-level: read-write
< x-api-version: 1.0
< x-connection-hash: 70112d3f11846a9a9e8e26ff35b9b8ee
< x-content-type-options: nosniff
< x-frame-options: SAMEORIGIN
< x-rate-limit-limit: 300
< x-rate-limit-remaining: 299
< x-rate-limit-reset: 1468880167
< x-response-time: 386
< x-runtime: 0.375436
< x-transaction: 005843ea00b40159
< x-tsa-request-body-time: 0
< x-xss-protection: 1; mode=block
<
Connection #0 to host ads-api-sandbox.twitter.com left intact
{"data_type":"account","data":        
{"name":"sandbox_account","timezone":"America\/Los_Angeles",
"timezone_switch_at":null,"id":"gq12f9","created_at":"2016-07-18T22:15:07Z","salt":"cf510daa05835fbb8d1370cc82e15889",
"updated_at":"2016-07-18T22:15:07Z","approval_status":"ACCEPTED",
"deleted":false},"request":{"params":{"name":"sandbox_account"}}}`

#7

Thanks, @chris_august7!

As was mentioned, the name should be passed in as -d 'name=NAME'.

This will not work and will result in UNAUTHORIZED_ACCESS error: -d '{"name": "NAME"}'.

@TeamUpatel: Are you able to successfully add a sandbox account now?


#8

Yes that worked. Could create a test account.Thanks!


#9

#10

Great to hear. Thanks!