Retrieving a tree of all customers

360 views
Skip to first unread message

Marc Selman

unread,
Jan 3, 2019, 6:34:16 AM1/3/19
to AdWords API and Google Ads API Forum
I'm trying to retrieve a complete nested tree of all customers (and if it's a manager account, the customers below that etc.)
To do this I'm using the new Google Ads API (v0.7) to retrieve the CustomerClientLinks recursively and for every link I'm using GetCustomer to retrieve the customer information such as the DescriptiveName.
But for a simple tree with two levels and a total of 37 customers this takes around a minute.

The API methods seem rather slow. Is that normal?

Also, I need to retrieve the links and the customerdata for every found customerId to check if they have subaccounts and to get the name.
Because of this I need to perform a lot of calls which could (with a large tree) easily hit the rate limit.
It would be better if I could retrieve all the available customers (paged) in one call instead of having to recursively find them.

Teja Makani

unread,
Jan 7, 2019, 5:23:28 PM1/7/19
to AdWords API and Google Ads API Forum
Hello Marc,

Apologies for the delay. I was checking with the team for an alternative solution. I will get back to you once I have more information from the team. Meanwhile to analyze the performance issue you are facing, could you please share the code snippet that is taking more time to fetch the hierarchy?

Regards,
Sai Teja, Google Ads API Team

Teja Makani

unread,
Jan 8, 2019, 5:05:26 PM1/8/19
to AdWords API and Google Ads API Forum
Hello Marc,

You could use customer_client resource to fetch the hierarchy of the accounts in a single API call. For example you could use the below query in your sample code to fetch the entire hierarchy in a single API call.

Sample query below:
.setQuery("SELECT customer.id, customer.descriptive_name, customer_client.resource_name, customer_client.client_customer, customer_client.level, customer_client.hidden FROM customer_client")

Hope this helps you, please let me know if you have any further questions.


Regards,
Sai Teja, Google Ads API Team

On Thursday, January 3, 2019 at 6:34:16 AM UTC-5, Marc Selman wrote:

Marc Selman

unread,
Jan 9, 2019, 6:58:58 AM1/9/19
to AdWords API and Google Ads API Forum
Hi Teja,

I'm using the Google Ads .NET client library (https://github.com/googleads/google-ads-dotnet) and I can't send a query request without a customer ID.
But ofcourse when I send a customer ID I only get the details of that specific customer.
Is that a problem with the .NET library or am I missing something else?

Op dinsdag 8 januari 2019 23:05:26 UTC+1 schreef Teja Makani:

Teja Makani

unread,
Jan 9, 2019, 3:24:50 PM1/9/19
to AdWords API and Google Ads API Forum
Hello Marc,

It is expected to result out the details of single account when the CID passed in the program is of non manager account. Just like AdWords API,  you could sent the Manager's client customer Id to to get the entire hierarchy. Please give it a try and please elaborate the scenario trying if the problem persists. You could also try the below CURL command from the terminal for the same.

curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN"      -H "developer-token: DEVELOPER_TOKEN"      -H "Content-Type: application/json"      https://googleads.googleapis.com/v0/customers/YOUR_MCC_ID/googleAds:search      --data '{query: "SELECT customer.id, customer.descriptive_name, customer_client.resource_name, customer_client.client_customer, customer_client.level, customer_client.hidden FROM customer_client"}'

Regards,
Sai Teja, AdWords API Team


On Thursday, January 3, 2019 at 6:34:16 AM UTC-5, Marc Selman wrote:

Marc Selman

unread,
Jan 10, 2019, 6:57:05 AM1/10/19
to AdWords API and Google Ads API Forum
Hi Teja,

I'm using a refreshtoken of a Google account that has access to multiple Google Ads accounts.
So first I need to get the available customers for that Google account. And then for each account I need to query for sub-accounts.
If that account is a manager account I can retrieve the sub-accounts from customer_client or customer_client_link.

When I use the query you provided the first two requested properties 'customer.id' and 'customer.descriptive_name' are always the same; the id and name of the manager account itself.
So I still need to query every subaccount id for the descriptive_name. And if that subaccount is also a manager account I need to do the same for his subaccounts etc.

Marc

Op woensdag 9 januari 2019 21:24:50 UTC+1 schreef Teja Makani:

Teja Makani

unread,
Jan 10, 2019, 4:00:51 PM1/10/19
to AdWords API and Google Ads API Forum
Hello Marc,

To get the accessible accounts for a user you can use CustomerService.ListAccessibleCustomers which returns resource names of customers directly accessible by the user authenticating the call and then you can use the query specified earlier to get the entire hierarchy. I used the same query and got all the accounts under my MCC, the sub MCCs and accounts under that sub MCCs as well. 

Also the Customer.id and customer.descriptive_name are same for all as the call made with that account and customer object refers to. I am getting in touch with the team to see if there is a possibility to get them in a single call. I will update you once I have more information. meanwhile you can double check whether you are receiving all the accounts in the hierarchy under your MCC with that query. If not, please share the query and response along with the email address of the user authenticating the API call to take a closer look.    

Regards,
Sai Teja, Google Ads API Team


On Thursday, January 3, 2019 at 6:34:16 AM UTC-5, Marc Selman wrote:

googleadsapi...@google.com

unread,
Jan 15, 2019, 2:20:07 PM1/15/19
to AdWords API and Google Ads API Forum
Hello Marc,

Thanks for your patience. I checked with my team and confirmed that it is an expected behavior of the customer_client, in fact in Google Ads API only one resource is responsible for a field to maintain normalization. Since the descriptive_name is a field in Customer resource, for each of the client_customer would have to call customer resource. Please let me know if you have any further questions.


Regards,
Sai Teja, Google Ads API Team


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    http://googleadsdeveloper.blogspot.com/search/label/adwords_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

Was your question answered? Please rate your experience with us by taking a short survey.
If not -- reply to this email and tell us what else we can do to help.

Take Survey

Also find us on our blog and discussion group:
http://googleadsdeveloper.blogspot.com/search/label/adwords_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/2bd6f102-4141-44ce-a435-835d3dea8509%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

beter...@gmail.com

unread,
May 19, 2021, 5:53:13 PM5/19/21
to AdWords API and Google Ads API Forum
We are suffering from the same problem. Clients with a big amount of accounts can take minutes to list all available accounts.
This problem is the same with both Adwords and Google Ads API.
There should be a simple "list all accounts" method the would actually return all accounts available for a given user token.


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...@googlegroups.com.

Google Ads API Forum Advisor Prod

unread,
May 20, 2021, 2:12:25 PM5/20/21
to beter...@gmail.com, adwor...@googlegroups.com

Hi,

Thank you for reaching out. The hierarchical tree of the accounts are built dynamically as the tree structure of the accounts itself is dynamic and keeps changing all the time. It would be impractical to persist all the subtree structure for each node in the tree as the amount of data to be stored would be huge. I would say you could use your local cache to save the accounts info that you have retrieved so you don’t have to query them each time.

Thanks and regards,
Xiaoming, Google Ads API Team

 

Google Logo
Xiaoming
Google Ads API Team
 


ref:_00D1U1174p._5004Q2HCG9G:ref

Pablo Lemos

unread,
May 20, 2021, 6:18:56 PM5/20/21
to Google Ads API Forum Advisor Prod, adwor...@googlegroups.com
Well, the same problem you have to persist it, we have too. :)
Those things change all the time and cache gets unreliable.

One thing that would be interesting is if we could query if there was any change on the tree. That way we could create safe caches and quickly check if we need to rebuild it.
Reply all
Reply to author
Forward
0 new messages