Can't get Google Ads metrics for manager account, can't get permission for client account
I am trying to access the metrics for client accounts using the Google Ads API, through the Python client.
Currently I'm using a modified version of the get_campaign_stats_to_csv.py
example, with the query:
import datetime last_three_days = datetime.datetime.today() - datetime.timedelta(days=3) query = """ SELECT customer.descriptive_name, metrics.cost_micros FROM customer WHERE segments.date > '{last_three_days}' AND segments.date <= '{today}'""".format( last_three_days=last_three_days.strftime('%Y-%m-%d'), today=datetime.datetime.today().strftime('%Y-%m-%d'))
It requires the commandline argument --customer_id=
of the account we're reporting on, used as follows:
search_request.customer_id = customer_id # e.g., '--customer_id=1234567890'
The problem is that when I use my Manager account customer id 1234567890
, I get the error:
error_code { query_error: REQUESTED_METRICS_FOR_MANAGER } message: "Metrics cannot be requested for a manager account. To retrieve metrics, issue separate requests against each client account under the manager account." }
Which I assume means using the client id. But when I use the client ID 0987654321
, I get the error:
error_code { authorization_error: USER_PERMISSION_DENIED } 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#cid" }
The link in the error message leads to the following header:
Which brings me back to square one, where the API spits the dummy when I use the Manager Account ID.
I've checked out this stack overflow question, but I think we're having different problems, as all my accounts have the red 'TEST ACCOUNT' flag next to them.
As a final note: there are two test client accounts, both which I've set up with quasi campaigns.
I wrote that example. You can set the client ID in the command line or the YAML file. It will not work if you use a manager account ID.
I know the terminology is confusing but that's what that API expects.
If you have any further issues with it, let me know.
My solution is list the customers that you have got access to, and aren't manager, the customer_id i passed to the request was login-customer-id i.e.
customer_id_query = """SELECT customer_client.id FROM customer_client where customer_client.manager = false""" request = SearchSearchAds360Request() request.customer_id = login_customer_id request.query = queryMake sure you print the ids, as it will help seeing if your access is correct, then do a loop on your initial query but this time specifying customer_id as the customer_client.id i.e.
for customer_id in customer_ids: query = """ SELECT customer.descriptive_name, metrics.cost_micros FROM customer WHERE segments.date > '{last_three_days}' AND segments.date <= '{today} AND customer.id = {customer_id}'""".format( last_three_days=last_three_days.strftime('%Y-%m-%d'), today=datetime.datetime.today().strftime('%Y-%m-%d'), customer_id=customer_id) request = SearchSearchAds360Request() request.customer_id = customer_id request.query = querySo I didn't have the manager account number in the google-ads.yaml. Adding it fixed my problem when I use the client ID as the commandline line argument.
Here's a picture of where I added the manager account number..