Migration to Google Ads API - Get list of all accounts under MCC

2,249 views
Skip to first unread message

Marcel Zemp

unread,
Apr 1, 2019, 10:55:23 AM4/1/19
to AdWords API and Google Ads API Forum
Hi

We're in the process of migrating from AdWords API to the new Google Ads API. Our Python tool currently loops over all accounts under the MCC root account and downloads various reports for all accounts on a daily basis.

From what I understand, we also have to place calls for each account again with the Google Ads API. Therefore, we also need to know all accounts under the root level MCC account, but I'm already struggling with this.

In the AdWords API we would do something like this: I would use ManagedCustomerService.get(selector) with an appropriate selector and then loop over the pages (see also here) to get all accounts under the root MCC.

How would I do this with the new Google Ads API? The Python examples do not (yet) show how to do this. Or is there a better way to pull reports over all accounts, which are not managed accounts?

FYI: Credentials & token are working (we're using the same tokens as before for AdWords [see here]) and I can successfully pull the accessible customers via customer_service.list_accessible_customers().

googleadsapi...@google.com

unread,
Apr 1, 2019, 5:24:05 PM4/1/19
to marce...@d1-solutions.com, AdWords API and Google Ads API Forum
Hi Marcel,

To get the account hierarchy via Google Ads API, you could use the customer_client resource. Through which you can get only the resource name, level, Boolean value of hidden status and Client_customer details of the accounts under your manager account. To get these details the OAuth credentials used to make the API call should be of manager account and the ClientCustomerId passing in the header should be of manager account. Below is the sample query for your reference. 

Please note that, you have to iterate through all the customers to get the descriptive_name.

query = ('SELECT customer_client.resource_name,
                customer_client.client_customer,
                customer_client.level, customer_client.hidden,
                customer_client.level
                FROM customer_client');

Please let me know if you have any further questions.

Regards,
Anthony
Google Ads API Team


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    https://ads-developers.googleblog.com/search/label/google_ads_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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+unsubscribe@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 the Google Groups "AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/0d7a3c7e-4fc9-47d0-8628-7fca4889dcde%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marcel Zemp

unread,
Apr 3, 2019, 12:21:39 PM4/3/19
to AdWords API and Google Ads API Forum
Hi Anthony

Thanks for getting back. I've tried the CustomerClientService with Python

service = client.get_service('CustomerClientService')
query = ('SELECT customer_client.resource_name,'
                'customer_client.client_customer,'
                'customer_client.level, customer_client.hidden,'
                'customer_client.level'
                'FROM customer_client');
response = service.search(root_account_id, query=query, page_size=100)

Where root_account_id is the ID of the root level MCC account. But I get

AttributeError: 'CustomerClientServiceClient' object has no attribute 'search'

Is this the right service? If not, what service should be used?

Regards Marcel

googleadsapi...@google.com

unread,
Apr 3, 2019, 4:26:36 PM4/3/19
to marce...@d1-solutions.com, AdWords API and Google Ads API Forum
Hi Marcel,

You can try using the GoogleAdsService and set the query to the one that I provided earlier. You can find a similar API call here.

Regards,
Anthony
Google Ads API Team


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    https://ads-developers.googleblog.com/search/label/google_ads_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

Marcel Zemp

unread,
Apr 4, 2019, 12:14:54 PM4/4/19
to AdWords API and Google Ads API Forum
The query now runs, but I'm not sure what I'm getting back. According to the documentation for SearchGoogleAdsResponse, I should get a list of results back. Instead I get

AttributeError: 'GRPCIterator' object has no attribute 'results'

Also the total_results_count & field_mask do not seem to exist:

AttributeError: 'GRPCIterator' object has no attribute 'total_results_count'
AttributeError: 'GRPCIterator' object has no attribute 'field_mask'

For the next_page_token I get the value "None" - the only field I am not getting an error.

Not clear what is going wrong. How would I go about to see what I'm getting back in this rather opaque SearchGoogleAdsResponse object? It is certainly not as transparent as a simple JSON object where I can quickly check what I'm getting back.

Also, how does pagination with the Python library work? I could not find anything about this in the documentation or the examples so far.

If I try the "Get Keyword Stats" example, I get an error in case the ID is of the root manager account (ok - understandable) but if I use a client account ID I get:

"User doesn't have permission to access customer.".

But with the old AdWords API I can pull data for this account. So is there some additional permission needed? What else could go wrong?

Also the various concepts are not very clear: All over you talk about customers, clients and/or accounts - which seem to me like they all are the same object. Are you just not very precise here or what is exactly the difference? Is this documented somewhere?

Alexander Belozerov

unread,
Apr 4, 2019, 3:16:49 PM4/4/19
to AdWords API and Google Ads API Forum
Hi there,
Im having similar issue,
this would get me list of all accounts, including mcc.

For example if we have tree-like structure with master MCC and multiple level MCCs under it, what would be the best way to get a list of all non MCC account under master MCC?
This is in order to collect reporting data for all our accounts.

Thanks,
Alex

googleadsapi...@google.com

unread,
Apr 4, 2019, 5:00:24 PM4/4/19
to dju...@gmail.com, AdWords API and Google Ads API Forum
Hi Marcel,

You can have a look at the resources page to get a description between Customer, CustomerClient and CustomerClientLink. Your response should return in this format. I'd recommend enabling logs in your client library. I'd recommend reaching out to the client library owners for your concern regarding pagination since they will be better suited to respond to this. 

Regards,
Anthony
Google Ads API Team


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    https://ads-developers.googleblog.com/search/label/google_ads_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

cv

unread,
Apr 9, 2019, 4:49:19 AM4/9/19
to AdWords API and Google Ads API Forum
Hi,

But how I can get the Linked account(When user authorised through oAuth where I am not know he has linked with manager or normal account ) is Manager account or Normal account when user authorised my app with which clientCustomerId he has authorised?

Thanks

googleadsapi...@google.com

unread,
Apr 9, 2019, 3:08:41 PM4/9/19
to chirag....@gmail.com, AdWords API and Google Ads API Forum
Hello,

The manager field will give you a value to whether or not an account is a manager account.

Regards,
Anthony
Google Ads API Team


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    https://ads-developers.googleblog.com/search/label/google_ads_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

cv

unread,
Apr 10, 2019, 1:12:37 AM4/10/19
to AdWords API and Google Ads API Forum
Thanks for the answer,

But I was looking for loginCustomerId, that will give me whose refreshtoken I was using it when someone authorised throughoAuth.


Thanks,

googleadsapi...@google.com

unread,
Apr 10, 2019, 3:46:46 PM4/10/19
to chirag....@gmail.com, AdWords API and Google Ads API Forum
Hello,

You won't be able to return the customer ID that your refresh token comes from.

Regards,
Anthony
Google Ads API Team


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    https://ads-developers.googleblog.com/search/label/google_ads_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

Riley Blair

unread,
Sep 12, 2019, 2:43:35 AM9/12/19
to AdWords API and Google Ads API Forum
Hi Anthony,

Just curious why the descriptive_name field cannot be accessed with the same query? It currently seems as if accounts with, for example, 50+ customer clients, an additional 50+ requests must be made in order to get the descriptive_name for each? Is is possible to access the descriptive_name field with that same request?

Google Ads API Forum Advisor Prod

unread,
Sep 16, 2019, 11:22:02 AM9/16/19
to he...@rileyblair.com, adwor...@googlegroups.com

Hi Riley,

The descriptive_name should return the appropriate account names. If you are facing issues, you send me your API request and response through reply privately to author so I can take a closer look.



Regards,
Anthony
Google Ads API Team



ref:_00D1U1174p._5001UHGWyo:ref
Reply all
Reply to author
Forward
0 new messages