How to retrieve Adwords accounts under an MCC account using CustomerService?

76 views
Skip to first unread message

Stijn van Lieshout

unread,
Sep 10, 2018, 1:26:19 AM9/10/18
to AdWords API and Google Ads API Forum
I am building an Adwords application with oAuth 2.0 authentication in python. 

I'm able to retrieve all Adwords accounts associated with a google account using the get_accounts function below. But now I would like to drill down deeper into the account hierarchy if an account canManageClients (read: mcc account). 

I've already had a look at the Get account hierarchy under the current account but there ManagedCustomerService is used whereas I don't manage these accounts and am using CustomerService instead. 

How to retrieve Adwords accounts under an MCC account using CustomerService?

How I am currently retrieving accounts:

from googleads import adwords

def get_accounts(client):
    customer_service
= client.GetService('CustomerService', version='v201806')  
    selector
= {
       
'fields': ['customerId', 'descriptiveName', 'canManageClients']
   
}
    accounts
= customer_service.getCustomers(selector)

    result
= []
   
for account in accounts:
        customerId
= account['customerId']
        name
= account['descriptiveName']
        canManageClients
= account['canManageClients']
       
if canManageClients:
           
# How to retrieve all accounts under MCC account here?
        result
.append({"id": customerId, "name": name, "canManageClients": canManageClients})
   
return result

Peter Oliquino (AdWords API Team)

unread,
Sep 10, 2018, 3:56:44 AM9/10/18
to AdWords API and Google Ads API Forum
Hi Stijn,

The CustomerService is a service used only to retrieve account specific information. If what you wish is to retrieve information on accounts under a specific hierarchy, you will need to use the ManagedCustomerService instead. You may note that the CanManageClients field is also supported in the ManagedCustomer object of the ManagedCustomerService.

I hope this helps and feel free to write back if you need further information.

Thanks and regards,
Peter
AdWords API Team

Stijn van Lieshout

unread,
Sep 10, 2018, 12:05:35 PM9/10/18
to AdWords API and Google Ads API Forum
Gotcha. I got the definition to work now by using the ManagedCustomerService. Thanks!
Reply all
Reply to author
Forward
0 new messages