Get accounts associated to manager account

1,020 views
Skip to first unread message

Vikram Tiwari

unread,
Apr 3, 2017, 11:03:14 PM4/3/17
to AdWords API Forum
Sample code:

customerService = adwords_client.GetService(
            'CustomerService'version='v201609')
        customers = customerService.getCustomers()

When I use this, for most accounts I am able to get all the accounts associated. But recently I got issues with one of the accounts where the actual accounts are part of manager accounts.

I found some threads regarding using ManagedCustomerService API to get such data but did not find any example for the same in Python. Any help?

Peter Oliquino

unread,
Apr 3, 2017, 11:38:11 PM4/3/17
to AdWords API Forum
Hi Vikram,

Yes, the more correct service to use to retrieve the associated accounts to your MCC should be the ManagedCustomerService and you may refer to this Python sample code as to how.

Best regards,
Peter
AdWords API Team

Vikram Tiwari

unread,
Apr 4, 2017, 2:26:46 AM4/4/17
to AdWords API Forum
Hey Peter - Thanks for the quick reply.

I am using the exact same code on my local and getting following error:

suds.WebFault: Server raised fault: '[AuthenticationError.CLIENT_CUSTOMER_ID_IS_REQUIRED @ ; trigger:'<null>']'

Not sure what I am supposed to pass here.

Vikram Tiwari

unread,
Apr 4, 2017, 2:32:17 AM4/4/17
to AdWords API Forum
To give more relevance. I am using OAuth and using refresh_token and other values to create proper adwords client. Normally if I were to use CustomerService API, it works fine. I do not have any ClientCustomerId to pass at this moment (in code) since the only thing I have from end user is refresh_token.

Peter Oliquino

unread,
Apr 4, 2017, 3:22:45 AM4/4/17
to AdWords API Forum
Hi Vikram,

The AuthenticationError.CLIENT_CUSTOMER_ID_IS_REQUIRED error that you are encountering indicates that there was no customer ID specified in your request header. This means that you may have not specified a customer ID value in the client_customer_id field in your configuration file.

Please note that the ManagedCustomerService is different from the CustomerService. In the CustomerService.getCustomers, it is possible that no customer is specified in the request header as stated in the link. However, using the ManagedCustomerService and other AdWords API services will require you to pass the customer ID in your request header.

Additionally, since you are using the ManagedCustomerService, you will need to use your MCC account ID as the value for you client_customer_id.

Thanks and regards,
Peter
AdWords API Team

Vikram Tiwari

unread,
Apr 4, 2017, 3:51:27 AM4/4/17
to AdWords API Forum
Makes sense. But then shouldn't a better example be:
- get accounts using CustomerService.getCustomers
- loops though accounts to check if the account has canManageClients set as true
- if so, then gets all the associated accounts to that manager account

Returns all accounts, including the hierarchy of manager accounts.

Peter Oliquino

unread,
Apr 4, 2017, 4:35:17 AM4/4/17
to AdWords API Forum
Hi Vikram,

Yes, what you have suggested is an ideal approach, however, the CustomerService.getCustomers currently does not function as what you have stated. Currently, the CustomerService.getCustomers can only return customers associated to the login you used to authenticate the request. These customers that I mentioned, however, does not necessarily mean that they are in the same manager structure hierarchy. You can find out more about this feature by visiting this blog post.

What I could recommend is that to first use the ManagedCustomerService.get and using the customer IDs from the result, make separate calls using the CustomerService for each of the customer IDs to check if canManageClients = true. If true, then you may make another call to ManagedCustomerService to return the next hierarchy if available.

I hope this helps and please let me know if you are still experiencing any issues using the any of the services.

Best regards,
Peter
AdWords API Team

aa...@cbo.me

unread,
Apr 30, 2018, 5:28:52 AM4/30/18
to AdWords API and Google Ads API Forum
Hi Peter,

Is there perhaps a way to programmatically retrieve the MCC account_id from the AdWords API so I can then use that in the ManagedCustomerService?

Regards,
Aaron

Bharani Cherukuri (AdWords API Team)

unread,
Apr 30, 2018, 1:40:16 PM4/30/18
to AdWords API and Google Ads API Forum
Hi Aaron, 

You could use the CustomerService.getCustomers() without specifying the clientCustomer Id in the request header. This will return the customerIds of the accounts which are directly accessible by the authenticating user. You can check for the canManageClients attribute to confirm if the returned account is manager or a client account. 

You can also use ManagedCustomerService to get the complete account hierarchy. You may refer to the code sample in Java here. Code samples in other languages can be found here. Let me know if you have any other questions. 

Regards,
Bharani, AdWords API Team
Reply all
Reply to author
Forward
0 new messages