ListAccessibleCustomers Google Ads API

2,361 views
Skip to first unread message

cv

unread,
Mar 13, 2019, 9:54:46 AM3/13/19
to AdWords API and Google Ads API Forum
Hi,

ListAccessibleCustomers example for PHP lib for Google Ads API is not giving all the Managed customers for the MCC.

Is there anything need to be done to get All the Accounts?

Thanks,

googleadsapi...@google.com

unread,
Mar 13, 2019, 2:41:33 PM3/13/19
to AdWords API and Google Ads API Forum
Hello Chirag, 

The CustomerService.ListAccessibleCustomers is to retrieve only the list of accounts that are directly accessible by your OAuth credentials. This being said, even if your OAuth credentials have directly access to your MCC, this service will not include the sub-accounts under your MCC unless your OAuth credentials has direct access to your sub-accounts as well. If you still have an issue with this, could you please share the request and response logs so I can take a closer look? You can reply back via Reply privately to author option.

Regards,
Bharani, 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/

cv

unread,
Mar 14, 2019, 1:04:00 AM3/14/19
to AdWords API and Google Ads API Forum
Hello Bharani,

IN Adwords API I can get the all accounts which are there under MCC with MCC account credentials.

I have a system where client can link any of his account which has access to MCC account.
For e.g. MCC email x...@gmail.com has access to 70 other accounts, and I have system where client can link any one account from 70 account he has access, How I can list those 70 accounts?

Please let me know if I am unclear.

Thanks,

googleadsapi...@google.com

unread,
Mar 14, 2019, 1:45:50 PM3/14/19
to AdWords API and Google Ads API Forum
Hello Chirag, 

The AdWords API Account Hierarchy code sample uses the ManagedCustomerService.get() operation which returns all the accounts that meet the criteria. The equivalent to this would be GetCustomerClientRequest which will return the accounts under a manager account. If you're looking to get the accounts list of accounts that are directly accessible via your OAuth credentials by issuing a CustomerService.ListAccessibleCustomers request. This will return all the accounts directly accessible by the user authenticating the call. 

Let me know if you have any other questions.

Regards,
Bharani, 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/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

cv

unread,
Mar 15, 2019, 3:21:29 AM3/15/19
to AdWords API and Google Ads API Forum
Hello Bharani,

As I have sent you message via Reply Privately to Author, I have given you details what I am getting with CustomerService.ListAccessibleCustomers and with ManagedCustomerService.get().

Please let me know If I am doing something wrong.

Thanks,
Message has been deleted

cv

unread,
Mar 15, 2019, 6:28:17 AM3/15/19
to AdWords API and Google Ads API Forum
Hello Bharani,
GetCustomerClientRequest is giving me request error
request_error: Resource name 'customers/1234567890' is malformed: expected 'customers/{customer_id}/customerClients/{part_1}'.

What is customerClients nd what I neeed to pass?

Thanks,



On Thursday, 14 March 2019 23:15:50 UTC+5:30, googleadsapi-forumadvisor wrote:

googleadsapi...@google.com

unread,
Mar 15, 2019, 12:14:13 PM3/15/19
to AdWords API and Google Ads API Forum
Hello Chirag, 

I have raised this concern about the customer_client fields in the query builder to the team. Could you try with the query below and let me know if you're having an issue?

$query = 'SELECT customer_client.resource_name, customer_client.level FROM customer_client';

Thanks,
Bharani, 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/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

cv

unread,
Mar 16, 2019, 6:28:54 AM3/16/19
to AdWords API and Google Ads API Forum
Hello Bharani,

Thanks, I am able to use query, but my main concern remains same.

As I said Out of few accounts accessible under my MCC I can only get few of them so how would I know that or my client know that which account he has to link, since I have not all listed.

I can query that and find the account but that to required customerID, how would that I can have?


Thanks,

Darshan Pradhan

unread,
Mar 16, 2019, 1:43:29 PM3/16/19
to AdWords API and Google Ads API Forum
I had similar issue and the thread is in here.

TLDR, the listAccessibleCustomers pull all the active and inactive directly accessible accounts. 
You should be able to grab the indirectly accessible customer(acounts under MCC) using the query provide by Google Team which is "select *  from customer_client" .

The problem i ran into was the customer_client only returns the customer_clients account id(extract from resource_name) which is not very meaningful since I needed to present the user's account by name. 
So for each account i get back for the customer_client I had to go and make a customerServiceClient.getCustomer(resourceName) call, which would give me the details I needed( other attributes such as is_manager, test_account etc). 
With above solution one Caveat is that if you have to make an api call for each account you will have to implement a delay between the call which sometimes will still results in resource_exhaustion which is not very easy to handle in new Ads API. 

There was not easy way to do this so to retrieve the details of the customer I had to fall back to old adwords api to pull the customer clients details (managedCustomers resource). The old adwords api only return active accounts thought so my solution was to 
mash the result of both old adwords api and new ads api for now until new Ads words provides a way to pull the clients accounts name from the customer_client resource. 

cv

unread,
Mar 17, 2019, 3:29:59 AM3/17/19
to AdWords API and Google Ads API Forum
Hello Darshan,

Yes, It is exactly same issue I was refer to.
Old Adwords API is quick to get those info while for current API I need to do as many as 3 API calls required to get 1 MCC account info.
Imaging If you had a large size account, it not only delay the response but also use unnecessary resources.

I had try this to get the details, In my case so many accounts were hidden but still I need to gone through each of them due to nature of the API




function getAllCustomers() {
    $customerServiceClient
= $googleAdsClient->getCustomerServiceClient();
    echo
"<pre>";
   
// Issues a request for listing all accessible customers.
    $accessibleCustomers
= $customerServiceClient->listAccessibleCustomers();
   
print 'Total results: ' . count($accessibleCustomers) . PHP_EOL;




   
// Iterates over all accessible customers' resource names and prints them.
   
foreach ($accessibleCustomers->getResourceNames() as $resourceName) {
       
/** @var string $resourceName */
        printf
("Customer resource name: '%s'%s", $resourceName, PHP_EOL);
        $customer
= $customerServiceClient->getCustomer($resourceName);
        $customerId
= ($customer->getId() != '') ? $customer->getId()->getValue() : '';
        $this
->getCustomersFromCustomerId($customerId);
   
}
}


function getCustomersFromCustomerId($customerId) {


    $googleAdsServiceClient
= $googleAdsClient->getGoogleAdsServiceClient();
   
// Creates a query that retrieves all campaigns.
    $query
= 'SELECT customer_client.resource_name,
                customer_client.client_customer,
                customer_client.level,
                customer_client.hidden,
                customer_client.level
                FROM customer_client'
;
   
// Issues a search request by specifying page size.
    $response
= $googleAdsServiceClient->search($customerId, $query, ['pageSize' => self::PAGE_SIZE]);


   
// Iterates over all rows in all pages and prints the requested field values for
   
// the campaign in each row.
   
foreach ($response->iterateAllElements() as $googleAdsRow) {
       
//print_r($googleAdsRow);
       
//"Customer with ID '%s', ResourceName '%s', Level '%s' and isHidden '%s' was found.",
        printf
(
               
"Customer ResourceName '%s', isHidden %d, Level %d and clientCustomer '%s' was found.%s", $googleAdsRow->getCustomerClient()->getResourceName(), $googleAdsRow->getCustomerClient()->getHidden()->getValue(), $googleAdsRow->getCustomerClient()->getLevel()->getValue(), $googleAdsRow->getCustomerClient()->getClientCustomer()->getValue(), PHP_EOL
       
);
   
}
}


Thanks,

googleadsapi...@google.com

unread,
Mar 18, 2019, 10:40:59 AM3/18/19
to AdWords API and Google Ads API Forum
Hello Chirag, 

Following up on this thread, please let us know if you need any additional assistance with this.

Thanks,
Bharani, 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/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

cv

unread,
Mar 19, 2019, 12:59:04 AM3/19/19
to AdWords API and Google Ads API Forum
Hello Bharani,

No, as currently this is the only way to get all the accounts. But please do update as some of the thread says API team is looking where we can get account related info on simple way.


Thanks,

Costantin

unread,
Apr 26, 2019, 9:44:32 AM4/26/19
to AdWords API and Google Ads API Forum
Hello, I'm having the same issue. I need to do an extra API call for each account to extract the name, if it's test and all that info. With large accounts this becomes quickly impossible.
Is there a plan to update the ListAccessibleCustomers method and return more info like the account name? If it's MCC etc

Thanks

googleadsapi...@google.com

unread,
Apr 26, 2019, 3:24:20 PM4/26/19
to cos...@gmail.com, AdWords API and Google Ads API Forum
Hello, 

We have raised a feature request to the team regarding this. We will not be able to share a definite timeline on when this feature will be available. Please keep an eye on our blog for more updates.

Thanks,
Bharani, Google Ads API Team

=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:

jor...@sightly.com

unread,
Apr 30, 2019, 4:43:21 PM4/30/19
to AdWords API and Google Ads API Forum
I'm running up against this issue too, however it seems to be compounded by an additional point of confusion.

  • When I run ListAccessibleAccounts, I get 2 accounts back.  One is the customer id of my master account, the other is an account that does not exist when I look at my dashboard.

  • When I run this query:  
    • SELECT customer_client.client_customer, customer_client.resource_name, customer_client.hidden, customer.manager, customer.descriptive_name, customer.id FROM customer_client
    • I get back a list of results that matches my dashboard's total count of accounts.  However, when I filter the dashboard to "all" instead of "direct link", the number changes and doesn't match.
  • When I run this query:
    • SELECT customer.descriptive_name, customer.id, customer_client_link.client_customer, customer_client_link.hidden, customer_client_link.manager_link_id, customer.resource_name  FROM customer_client_link
    • I get back another list of results with a different number of results, which still does not match back to what my dashboard shows.
Within the last 2 queries I listed off, the many of customer.id's that get returned do not appear anywhere in my dashboard.  It's a guessing game as to which of them are actual accounts I manage and which are not... as well as where these phantom accounts are coming from.

All I need to be able to do is download my account list/hierarchy as it displays within my dashboard in the UI.  It seems there is no way to do this in the current version of the API (nor plans to add this functionality), and the tools available are giving poor quality data with no explanation.

Thoughts on how I should proceed?

googleadsapi...@google.com

unread,
May 1, 2019, 11:06:32 AM5/1/19
to jor...@sightly.com, AdWords API and Google Ads API Forum
Hello Jordan, 

The ListAccessibleCustomers will return the list of accounts that are directly accessible through the OAuth credentials that you're using. The CustomerClient will return the complete hierarchy of the account specified. 

The customer_client_link will return the customer client link relationship. If you're specifying the manager account, this should return the direct links to that MCC. If you're seeing a discrepancy, could you please share the request and response logs to check this further? You can share the details privately via Reply privately to author option.

Regards.
Bharani, Google Ads API Team

jor...@sightly.com

unread,
May 1, 2019, 5:56:54 PM5/1/19
to AdWords API and Google Ads API Forum
From further investigation, it appears to me this may be related to the CustomerClient records not properly filtering based on inactive/canceled status.  I see from other postings on the forum that a feature request has been added to support this, so I'm hoping that a future release will fix this.

In the meantime, the "workaround" I have found is to get all the CustomerClients, then loop through them one by one and try to GetCustomer.  If it's inactive/canceled I get an unauthorized exception returned instead of receiving the customer info, so that seems to be how I can filter them out for now.  This is a non-ideal solution, as it requires me to make MANY additional calls to the API (one per account, including inactive ones), and getting my whole account hierarchy takes 12-15 minutes (for ~1100 customer/clients, but over 2300 when inactives are included in the count).

Looking forward to a fix to include this status in the object so it can be used for filtering, and consistent filtering across objects (Customer, CustomerClient, CustomerClientLink).

cv

unread,
May 2, 2019, 12:56:15 AM5/2/19
to AdWords API and Google Ads API Forum
Hello Jordan,

Yes, That is exactly needs to do with this new Ads API, you need to iterate all the accounts you get through customer_client (https://groups.google.com/d/msg/adwords-api/jbwX0-Nso4U/_Aq3F7_kCQAJ)

You can not get account hierarchy in single API call like Its possible in Adwords API.

Also this will require significant time to load results, like you said.

Thanks,
Reply all
Reply to author
Forward
0 new messages