Modify campaign via API


#1

Hello,

I have Application ID with permission for Twitter Ads API and able to get data for my campaigns.

However, when I try to perform an update request like changing the campaign status or bid, I’m getting the error:

{u’message’: u’The client application making this request does not have access to this API’, u’code’: u’UNAUTHORIZED_CLIENT_APPLICATION’}

Please assist.

Regards,
Elad


#2

Hi @eladzaa,

Would you be able to provide us with the full request/response you’re getting when you successfully fetch campaign data, as well as an example request/response for the error you mention? That should provide us with the information we need to help you troubleshoot.


#3

Hi,

I’m using the python twitter_ads SDK for API access.

This is the relevant code snippet:

from twitter_ads.client import Client

ads_client = Client(app_id,
              		app_secret,
              		access_token,
              		access_token_secret)

account = ads_client.accounts(id=account_id)
line_item = account.line_items(id=line_item_id)
campaign = account.campaigns(id=line_item.campaign_id)
campaign.paused = status == is_status_paused
campaign.save()

All the commands work as expected and return the requested line items and campaigns besides the campaign.save() line which yields an exception as mentioned above.


#4

@eladzaa: Thanks for the question.

The error response in your original post usually indicates that the authentication credentials are missing or incorrect. I’d recommend using twurl to ensure that your app actually has access. Twurl knows how to grant the access token and signs all requests with the necessary credentials.

In terms of the Python SDK, please note that the .save() method is what actually performs the operation on the object and its attributes, as you’ve specified them.


#5

@juanshishido Thank you for your response.

I’ve tried twurl authentication and was able to fetch my account tweets. However, the python SDK is our preferred Twitter Ads API access technology and as I understand, the ‘twitter_ads’ python package is officially supported by Twitter.

I’m getting the error message only after I’m using an update request. Does the Ads API have different permissions for getting and for updating campaigns and line items?

If so, I need an update Ads API permission for my Twitter app. If not, how can it be that authentication credentials are missing or incorrect when I’m getting valid line items data?


#6

@eladzaa: Glad you’ve got it working with twurl. To confirm, you’re able to use twurl to make the same request you’re trying to make with the Python SDK, right (e.g., pausing the campaign)?

Also, ceck your .twurlrc file—should be in $ cd ~—and make sure you’re using those authentication credentials when using the SDK.


#7

@juanshishido That’s not the case, as twurl is not working on Ads API related requests which is the API I need.

After sending the command:

twurl -H ads-api.twitter.com /1/accounts

I’m getting the message:

The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.

Also, when I’m sending:

twurl authorize -H ads-api.twitter.com --consumer-key <KEY> --consumer-secret <SECRET>

I get the response:

Authorization failed. Check that your consumer key and secret are correct, as well as username and password.

I’m using the same consumer key and secret like in the Python SDK and I have no problems there getting the accounts list.

I’ve also checked the .twurlrc file. The consumer key and secret are the same but the access token and access token secret are different from what I have in my Twitter app which I use in Python SDK.


#8

@eladzaa: That error message is returned only when making a request to the api.twitter.com host with a /1/ resource path. Please double check your request. I’d like to confirm that you’re able to successfully make a GET request using twurl to the accounts endpoint, especially given:

Finally, what is your app ID?


#9

@juanshishido I’m making requests to ads-api.twitter.com not to api.twitter.com.

In your Ads API documentation https://dev.twitter.com/ads/reference/get/accounts it says that the Ads account GET request is https://ads-api.twitter.com/1/accounts. Isn’t the Ads API account latest version is 1?

When sending request:
twurl -H ads-api.twitter.com /1.1/accounts

I get:

{"errors":[{"code":"ROUTE_NOT_FOUND","message":"The requested resource could not be found"}],"request":{"params":{}}}

My App ID is 12438526.


#10

That’s correct, @eladzaa. We are currently on version 1 of the Ads API.

The previous comment was intended to clarify the fact that the error message you previously shared (shown below) is only returned when making a /1/ request to api.twitter.com—after all, it calls out “REST API.” For the ads-api.twitter.com domain, we have no such message defined.

"The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview."

Please share a successful Ads API GET request using twurl, so we may further assist you.


#11

@juanshishido I’ve successfully managed to get my accounts list using the following twurl request:

twurl -H ads-api.twitter.com /1/accounts/

But when sending the request:

twurl -X PUT -H ads-api.twitter.com /1/accounts/<ACCOUNT ID>/line_items/<LINE ITEM ID>?paused=true

I’m getting the error:

"errors":[{"code":"UNAUTHORIZED_CLIENT_APPLICATION","message":"The client application making this request does not have access to this API"}]

#12

That’s great. Thanks for confirming, @eladzaa! Your app should now be able to make writes (it was originally set for read-only access). Please let us know if this resolves your issue.


#13

@juanshishido Yes, this resolves my issue.

Thank you for your assistance.


#14

@juanshishido, Hello again,

I now able to perform update requests in my ads API account. However, I would like to create promoted tweets in order to create campaigns via the API. When I try to make a POST request to the endpoint:

'/1/accounts/<ACCOUNT ID>/tweet'

I’m getting an error:

[{u'message': u'User <USER ID> is not authorized to create tweets for user id <USER ID>', u'code': u'UNAUTHORIZED_ACCESS'}]

Would you please enable access for tweet creation for my user?

Reagrds,
Elad


Guidance for UNAUTHORIZED_ACCESS issues
#15

@eladzaa: Please remember to provide the full request and response when asking questions here. See Guidelines for Reporting Issues for a refresher.

In addition, don’t forget to search the forums for similar questions.

In any case, this post and this thread should help you.


#16

Hi,

I hope this thread is the right place for my message.

I have the same problem with modifying campaigns.
Request: GET https://ads-api.twitter.com/2/accounts/18ce54iyngp/campaigns/8xk2z works just fine, but
POST is returning UNAUTHORIZED_CLIENT_APPLICATION (The client application making this request does not have access to this API).

I’m confused because my app (app id: 13993779, Basic licence) has “Read and write” access level permission.
Any advice?

Best regards,
Igor