Error while trying to fetch campaigns

66 views
Skip to first unread message

Youri Nouri

unread,
Jul 31, 2020, 5:39:32 AM7/31/20
to AdWords API and Google Ads API Forum
Hello, 

One of our lambda is retrieve campaign data but since begining of July it's not working anymore, we get the following error message:

> User doesn't have permission to access customer. Note: If you're accessing a client customer, the manager's customer id must be set in the 'login-customer-id' header. See https://developers.google.com/google-ads/api/docs/concepts/call-structure#login-customer-id

We tried to understand why we have this message but we're clueless now.
Here's what we checked:
- Client ID & Client Secret (they're correct)
- CUSTOMER_ACCOUNT_ID (it's referring to the account we want to get google ads campaign)
- DEVELOPER_TOKEN (it's the same as shown in the manager account)
- LOGIN_CUSTOMER_ID (it's the manager account ID)
- GOOGLE_REFRESH_TOKEN (I tried to refresh it and use the refreshed version.)

I also tried to run a basic code in Ruby in order to see if that wasn't because we're using NodeJS and the error is the same but I have a confirmation that the right login-customer-id is sent:

> I, [2020-07-31T11:32:02.648165 #441]  INFO -- : Outgoing request: Headers: {"x-goog-api-client":"gl-ruby/2.5.5 gapic/6.0.0 gax/1.8.1 grpc/1.28.0","developer-token":"mVM-XXXXXXXXXXXX","login-customer-id":"516XXXXXXX","x-goog-request-params":"customer_id=600XXXXXXX"} Payload: {"customerId":"600XXXXXXX","query":"SELECT campaign.id,\n       campaign.name,\n       segments.date,\n       metrics.impressions,\n       metrics.clicks,\n       metrics.cost_micros\nFROM campaign\nWHERE segments.date DURING LAST_7_DAYS\n  AND campaign.status = 'ENABLED'\nORDER BY segments.date DESC\n","pageSize":10}

Here's the code I ran:
  client = Google::Ads::GoogleAds::GoogleAdsClient.new(version: :v4) do |config|
    config.client_id = GOOGLE_CLIENT_ID
    config.client_secret = GOOGLE_CLIENT_SECRET
    config.developer_token = GOOGLE_DEVELOPER_TOKEN
    config.login_customer_id = GOOGLE_LOGIN_CUSTOMER_ID
    config.refresh_token = GOOGLE_REFRESH_TOKEN
    config.log_target = STDERR
    config.log_level = 'INFO'
    
  end
  campaign_service = client.service.campaign
  ga_service = client.service.google_ads
  query = <<~QUERY
      SELECT campaign.id,
             campaign.name,
             segments.date,
             metrics.impressions,
             metrics.clicks,
             metrics.cost_micros
      FROM campaign
      WHERE segments.date DURING LAST_7_DAYS
        AND campaign.status = 'ENABLED'
      ORDER BY segments.date DESC
    QUERY

  response = ga_service.search(GOOGLE_CUSTOMER_ACCOUNT_ID, query, page_size: 10)

If anyone has an idea, I'd be glad to try it.

Best Regards,
Youri Nouri

Google Ads API Forum Advisor Prod

unread,
Jul 31, 2020, 12:44:55 PM7/31/20
to youri...@uptodate.de, adwor...@googlegroups.com
Hi Youri,

Thank you for reaching out to us. I see that you're encountering a "permission denied" error. Could you provide us the full request and response log for where you're encountering this error so that I can further investigate this error? You can provide us these logs privately by using "reply privately to author".

Thank you,
Bryan, Google Ads API Team

ref:_00D1U1174p._5004Q22aZat:ref

Youri Nouri

unread,
Aug 4, 2020, 5:15:43 AM8/4/20
to AdWords API and Google Ads API Forum
Thanks a lot for your help :)

So what we had to do is convincing someone who had more right than developer to set a developer as "Manager" (the account refereed as  GOOGLE_LOGIN_CUSTOMER_ID in the script) with standard access.
Once done, we refreshed the token (refereed as  GOOGLE_REFRESH_TOKEN in the script) and execute our lambda with the new token. Now everything works fine :)

Note: It wasn't working because developer only had access to GOOGLE_CUSTOMER_ACCOUNT_ID which regardless of the admin status didn't gave the right to see the data.
Reply all
Reply to author
Forward
0 new messages