Google Ads API V4 - Get AccountHierarchy

129 views
Skip to first unread message

Vinitha Khambadkar

unread,
Jul 15, 2020, 7:11:27 PM7/15/20
to AdWords API and Google Ads API Forum
Hello ,

I am using the .net version of the code to fetch all Clients at all levels using the query below
            const string query = @"SELECT
                                    customer_client.client_customer,
                                    customer_client.level,
                                    customer_client.manager,
                                    customer_client.descriptive_name,
                                    customer_client.currency_code,
                                    customer_client.time_zone,
                                    customer_client.id,
                                    customer_client.resource_name
                                FROM customer_client
                                WHERE
                                    customer_client.level <= 3";
Successfully i get a list but it is flat with all clients at different levels.
My issue is i need to hierarchically create a tree with different levels. I need to know the clients that have level 2 is linked to which client on level1.

I tried using CustomerClientLink but if i provide a customer ID other than Login_CustomerId it throws USER_PERMISSION_DENIED exception. (FYI- this was not the behaviour with V2 version as i was previously using.) Please advise.

Thank you,
Vinitha.

Google Ads API Forum Advisor Prod

unread,
Jul 16, 2020, 10:55:24 AM7/16/20
to vin...@closedloop.com, adwor...@googlegroups.com
Hi Vinitha,

Thank you for reaching out. Please see here for information on getting the account hierarchy. As it says, it is necessary to provide the login-customer-id as this will be the starting point for returning the accounts. The sample code runs recursively to get the accounts linked to sub-manager accounts as well. If you continue to have issues with this, please share your client customer ID and complete detailed request and response logs via Reply privately to author so I can further investigate the issue. You can find information on enabling logging here.

Regards,
Mitchell
Google Ads API Team

ref:_00D1U1174p._5004Q21mPvZ:ref

Vinitha Khambadkar

unread,
Jul 16, 2020, 1:29:34 PM7/16/20
to AdWords API and Google Ads API Forum
Hello Mitchell,
Thank you for the response.
NOTE:  via Reply privately to author is grayed out for me. (please enable that for me as it is enabled in the browser settings)
Some more info, As i mentioned i am using the same code from https://developers.google.com/google-ads/api/docs/account-management/get-account-hierarchy#c to retrieve all accounts info.
But my issue is this :

There are multiple accounts under my login account. and there are multiple sub-accounts linked to all the accounts. I get all the clients resource name as below:
What i get back :  customers/M1/customerClients/C1 ,  customers/M1/customerClients/p1 or  customers/M1/customerClients/L1
What i expect/need :  customers/M1/customerClients/C1, customers/C1/customerClients/p1 or  customers/y2/customerClients/L1

I need the direct parent customer info and not indirect one which straight links to Login Customer.
                                


I tried the below:
1)  giving a where clause to const string query = @"SELECT
                                    customer_client.client_customer,
                                    customer_client.level,
                                    customer_client.manager,
                                    customer_client.descriptive_name,
                                    customer_client.currency_code,
                                    customer_client.time_zone,
                                    customer_client.id,
                                    customer_client.resource_name
                                FROM customer_client - resulted in error
2)  Tried giving P1 as customerId  PagedEnumerable<SearchGoogleAdsResponse, GoogleAdsRow> response =
                        googleAdsServiceClient.Search(
                            customerId.ToString(),
                            query,
                            pageSize: PAGE_SIZE
                        ); - resulted in USER_PERMISSION_DENIED 

Please let me know if you need more info on the issue..

Vinitha Khambadkar

unread,
Jul 16, 2020, 1:32:57 PM7/16/20
to AdWords API and Google Ads API Forum
Hierarchy.png

Google Ads API Forum Advisor Prod

unread,
Jul 17, 2020, 10:22:28 AM7/17/20
to vin...@closedloop.com, adwor...@googlegroups.com
Hi Vinitha,

If you are still having an issue with the reply privately button, please send the logs directly to googleadsa...@google.com. The print statement in the example should print "-"s that indicate the level of each account.

Vinitha Khambadkar

unread,
Jul 17, 2020, 11:38:51 AM7/17/20
to AdWords API and Google Ads API Forum
Hello Mitchell,

I have send the logs directly to  the email address mentioned. 
Waiting for a response here. Please let me know if more info needed.

Thank you,
Vinitha. 

Reply all
Reply to author
Forward
0 new messages