OPERATION_NOT_PERMITTED_FOR_CONTEXT with PHP examples AddCampaigns.php

752 views
Skip to first unread message

Matěj Humpál

unread,
Aug 11, 2021, 10:32:34 AM8/11/21
to AdWords API and Google Ads API Forum

Hello,

I keep getting the error above on adding a budget when using PHP example code from https://github.com/googleads/google-ads-php (examples/BasicOperations/AddCampaigns.php) . I do have a test account and the only thing I changed in the code was the account ID.

Various GET operations are running OK, although the result is mostly empty as the account is new.

Do I have to set additional permissions somehow? I find the documentation not quite aligning with reality in places.

I am using the ID of my test account. Do I have to create a customer sub-account and use that for testing the API? When I try that, the only error I get is USER_PERMISSION_DENIED.

Below is the result I get running the example file:

[2021-08-11T16:00:53.997292+02:00] google-ads.WARNING: Request made: Host: "googleads.googleapis.com", Method: "/google.ads.googleads.v8.services.CampaignBudgetService/MutateCampaignBudgets", CustomerId: 7868560570, RequestId: "-M7Gbo0wtv4jblE2qXWg3A", IsFault: 1, FaultMessage: "["The operation is not allowed for the given context."]"  
[2021-08-11T16:00:53.999249+02:00] google-ads.NOTICE: Request
-------
Method Name: /google.ads.googleads.v8.services.CampaignBudgetService/MutateCampaignBudgets
Host: googleads.googleapis.com
Headers: {
    "x-goog-api-client": "gl-php\/7.4.21 gapic\/ gax\/1.7.1 grpc\/1.38.0",
    "x-goog-request-params": "customer_id=7868560570",
    "developer-token": "REDACTED"
}
Request:
{"customerId":"7868560570","operations":[{"create":{"name":"Interplanetary Cruise Budget #2021-08-11T16:00:53.239+02:00","amountMicros":"500000","deliveryMethod":"STANDARD"}}]}

Response
-------
Headers: {
    "request-id": "-M7Gbo0wtv4jblE2qXWg3A",
    "date": "Wed, 11 Aug 2021 14:00:54 GMT",
    "alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-T051=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\""
}

Fault
-------
Status code: 3
Details: Request contains an invalid argument.
Failure: {"errors":[{"errorCode":{"contextError":"OPERATION_NOT_PERMITTED_FOR_CONTEXT"},"message":"The operation is not allowed for the given context.","location":{"fieldPathElements":[{"fieldName":"operations","index":0}]}}],"requestId":"-M7Gbo0wtv4jblE2qXWg3A"}  

Thank you for your help.

MH

Google Ads API Forum Advisor

unread,
Aug 12, 2021, 3:09:20 AM8/12/21
to hum...@followbubble.com, adwor...@googlegroups.com

Hi MH,

Thanks for reaching out to us.

Kindly note that you may receive error ‘USER_PERMISSION_DENIED’ if you’re incorrectly setting the 'login-customer-id’ in the request or when a user doesn't have permission to access a customer and you’re accessing a client customer using 'login-customer-id’ in the request. 

That being said, you may refer to this documentation on how to specify the login-customer-id property in the request properly.

With regards to the issue found in the logs you’ve shared, the error OPERATION_NOT_PERMITTED_FOR_CONTEXT means that sometimes the operation may work for some configurations, but for your particular configuration, it will not work. 

That being said, the target customer ID from your request, 7868560570, is a test manager account, which is why you are receiving the error, OPERATION_NOT_PERMITTED_FOR_CONTEXT. The CampaignBudgetService may only be used on a client customer account (i.e. an account that has campaigns in it). Please retry using a client customer. 

Let us know if you have any further questions.

Regards,

Google Logo
Yasar Ramjan Makandar
Google Ads API Team
 

 

 



ref:_00D1U1174p._5004Q2LmM8U:ref

Matěj Humpál, Follow Bubble

unread,
Aug 12, 2021, 3:23:59 AM8/12/21
to adwor...@googlegroups.com

Thanks for a quick response!

Also thanks for the clarification, I expected something along these lines.

I still don't understand why I wouldn't have permissions to access customers I created myself 5 minutes ago. The USER_PERMISSION_DENIED i get is when I use --customerId parameter 7930612705.

Do I assume correctly that I should be able to query customers I am able to see/change in the administration?

Or is it necessary to additionally set up permissions somewhere?

Matěj Humpál
Developer Lead
Follow Bubble s.r.o.

Dne 12. 8. 2021 v 9.09 Google Ads API Forum Advisor napsal(a):
ref:_00D1U1174p._5004Q2LmM8U:ref --
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
 
You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to adwor...@googlegroups.com
To unsubscribe from this group, send email to
adwords-api...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "AdWords API and Google Ads API Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-api/If1zxD7UBmk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-api...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/rOizA000000000000000000000000000000000000000000000QXPT7600ohHvqFjuRluJRp6A-xStVg%40sfdc.net.

Matěj Humpál, Follow Bubble

unread,
Aug 12, 2021, 3:36:32 AM8/12/21
to adwor...@googlegroups.com

Never mind, I just accepted an invitation to a client account (under the same e-mail address that the Manager Account is under) and everything (or basic get/add campaign operations) started working.

Not that this is super clear behaviour, but OK. Is there a clearer, more straightforward way?

Is there anything else I should be aware about?

Matěj Humpál
Developer Lead
Follow Bubble s.r.o.

Dne 12. 8. 2021 v 9.09 Google Ads API Forum Advisor napsal(a):

Hi MH,

Google Ads API Forum Advisor

unread,
Aug 13, 2021, 1:29:53 AM8/13/21
to hum...@followbubble.com, adwor...@googlegroups.com
Hi Matěj,

Thanks for the reply. I work with Yasar and let me provide support to your concern.

Could you confirm if your question is related on how to authenticate in Google Ads API to avoid the error? If yes, then you may see the key things to remember below:
1. Set customer ID (without hyphen) of the manager account to login-customer-id
2. Generate Oauth2 credential / API token using user account / email address that has access to that manager account
3. Set customer ID of the client account (without hyphen), where you want to make API request, to the customer_id field. This client account should have an active link with the manager account mentioned in first step

Regards,
Google Logo
Ernie John Blanca Tacata
Google Ads API Team
 


ref:_00D1U1174p._5004Q2LmM8U:ref

Matěj Humpál, Follow Bubble

unread,
Aug 16, 2021, 4:33:39 AM8/16/21
to adwor...@googlegroups.com

Hi Ernie,

yes, I have followed all the steps you mention before and as I mention in the previous message, I was able to make the API work after I accepted the invitation to the client account I myself created a few moments before.

My concern is: Do I have to be explicitly invited to all client accounts I need to work with via the API, even though my Manager Account can already work with their data in the ads administration? Or will I have access through the manager account?

Thanks for clarification.

Sincerely,

Matěj Humpál
Developer Lead
Follow Bubble s.r.o.

Dne 13. 8. 2021 v 7.29 Google Ads API Forum Advisor napsal(a):
ref:_00D1U1174p._5004Q2LmM8U:ref --
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
 
You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to adwor...@googlegroups.com
To unsubscribe from this group, send email to
adwords-api...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "AdWords API and Google Ads API Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-api/If1zxD7UBmk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-api...@googlegroups.com.

Google Ads API Forum Advisor

unread,
Aug 17, 2021, 2:41:15 AM8/17/21
to hum...@followbubble.com, adwor...@googlegroups.com
Hi Matěj,

Thank you for the reply.

You need to link the client accounts to your manager account, which your user account have an access, and follow the call structure that I've mentioned on my previous email. You may check this document as it discussed the suggestion that I provided.

Let me know if you have further questions.
Reply all
Reply to author
Forward
0 new messages