Get the names of the customer accounts using listAccessibleCustomers

2,287 views
Skip to first unread message

Muhammad Adil

unread,
Apr 11, 2022, 2:30:51 PM4/11/22
to Google Ads API and AdWords API Forum
Hello, 

I am able to get the IDs of the accounts with listAccessibleCustomers method but I would also like to get the account names along with the IDs. The main aim is to get all accessible accounts along with their name. Is it possible to do so through this endpoint? If not, which other API endpoint or approach will be best to do this? 

Google Ads API Forum Advisor

unread,
Apr 12, 2022, 1:21:37 AM4/12/22
to mohamma...@gmail.com, adwor...@googlegroups.com

Hi Muhammad,

Thank you for raising this concern to the Google Ads API team.

Moving forward to your concern, I see that you used the ListAccessibleCustomers method. As per this document, the expected response for this call is the resource name of customers directly accessible by the user authenticating the call. That said,if you want to get further information about the account, then you will need to use the customer_client report. Also, kindly note to include the customer_client.descriptive_name for you to get the names of the accounts.

I hope this helps. Let us know if you have further questions.

Regards,

Google Logo
Carmela
Google Ads API Team
 


ref:_00D1U1174p._5004Q2ZM01g:ref

Muhammad Adil

unread,
Apr 12, 2022, 2:57:02 AM4/12/22
to Google Ads API and AdWords API Forum
Hello, 

Thank you for your response. I had given this approach a thought. I think the problem with this is that if we have to list down 20 accounts, we will have to send 20 requests to get the names of all the top-level or manager accounts names, which will make the process extremely slow and inefficient.  Or, can we generate this report by giving multiple manager IDs so we can get all of them in one go? Or more ideally, is there a scenario where we can replace the ListAccessibleCustomers method with this report? 

Regards,
Adil

Google Ads API Forum Advisor

unread,
Apr 12, 2022, 11:01:45 AM4/12/22
to mohamma...@gmail.com, adwor...@googlegroups.com

Hello Muhammad,

Thanks for reaching out to the Google Ads API Forum. Unfortunately there is no way to add multiple MCC account Id to fetch the list of accessible accounts. Feel free to use our sample code list-accessible-customers to retrieve the customer IDs accessible by the user.

List Accessible Accounts provides the list of accounts you are a direct user on. To illustrate this, if you are a user in 3 MCC's that have deep hierarchies and 2 regular ads accounts you will get 5 accounts returned. To get the similar list of accounts in the UI you would click on the top right representation of your Google Account and the same list should be there for you to pick from.

And by using Get Account Hierarchy it will get the account hierarchy of your manager account. You aren't necessarily a user in all accounts that are in the hierarchy, only because you are a user in an MCC that has access can you see those accounts. Feel free to get back to us if you have any questions.

Best Regards,

Google Logo
Jakeia Sabrina
Google Ads API Team
 

ref:_00D1U1174p._5004Q2ZM01g:ref
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Muhammad Adil

unread,
Apr 13, 2022, 2:42:41 PM4/13/22
to Google Ads API and AdWords API Forum
Hello,

Thanks for the response Jakeia. I still have some confusion regarding the API. I think I did not make myself very clear in the above questions. 

I am able to get the account IDs (e.g. 123-456-789, etc.) using the List Accessible Accounts call. The behavior is exactly as you mentioned in your reply and that is the behavior that I require. The only thing that is missing is that I also require the Account Names (e.g. Google Ads account, Ads Manager Account 2, etc.) along with the IDs to show these names to the user so they have some ease in choosing the account. So, what I require is the functionality that the List Accessible Accounts provide but instead of only providing the IDs of the accounts, I also get the names of the accounts. 

I am sure there should be some method to achieve this, can you point out which one?

Also, in the earlier response, as Carmela pointed out that to fetch the details of the individual account, we will need to use the customer_client report. But I think it will be an inefficient use of the resources if we were to get the list of IDs and then iterate over the list and make API calls to get the name of each Ads account. Also, it will quickly kill the API usage quota. So, can you point out if any efficient solution exists to solve this issue?

Really grateful for the awesome support

Regards, 
Adil

Google Ads API Forum Advisor

unread,
Apr 14, 2022, 1:46:08 PM4/14/22
to mohamma...@gmail.com, adwor...@googlegroups.com

Hello Muhammad,

Thanks for the clarification and for all the details. I understand your question correctly as you said you want to fetch the account name details when using list-accessible-customers call. Unfortunately this functionality (account name) is not available on Ads API under listAccessibleCustomers API calls.

With regards to your concern, I have raised a feature request for your concern (require an account name details when using listAccessibleCustomers API calls) internally within our team on your behalf. Please note our team is unable to share any update/status for internal planning features, timeline information, and there is no guarantee the request will be approved.

Please keep an eye on our release notes and the blog for further updates and announcements or for any upcoming functionality updates.

Best Regards,

Google Logo
Jakeia
Google Ads API Team

Miguel Angel Garcia

unread,
Aug 8, 2023, 2:58:07 PM8/8/23
to Google Ads API and AdWords API Forum
Any updates on this? Seems like a pretty frequent need (I've found several threads about this in this forum and other websites).

If listAccessibleCustomers is not going to provide account names anytime soon, can you at least provide code examples of how to get that info in the most efficient and reliable way possible (I need it for Python).

Thanks!

Google Ads API Forum Advisor

unread,
Aug 8, 2023, 4:29:57 PM8/8/23
to delval...@gmail.com, adwor...@googlegroups.com

Hi,

Thanks for reaching out to Google Ads API Forum.

With regards to your concern, I have checked this on our side and unfortunately this feature on list-accessible-customers is still not available on Google Ads API. Kindly note that we already raised a feature request for this to be available in Google Ads API, subject for review. For now, what we can advise you is to follow our Blog post or Release Notes for the latest updates in the API.    

Links included in this email:

 
This message is in relation to case "ref:_00D1U1174p._5004Q2ZM01g:ref"

Thanks,
 
Google Logo Google Ads API Team


Miguel Angel Garcia

unread,
Aug 9, 2023, 2:11:45 AM8/9/23
to Google Ads API and AdWords API Forum
OK, and what about the second part of my message?

If listAccessibleCustomers is not going to provide account names anytime soon, can you at least provide code examples of how to get that info in the most efficient and reliable way possible (I need it for Python).

Miguel Angel Garcia

unread,
Aug 9, 2023, 2:55:29 AM8/9/23
to Google Ads API and AdWords API Forum
In case it helps, here is the code that I got so far (it probably could be improved a lot and maybe has mistakes, I'm a Python beginner):

def one(request):
    client = credenciales(request)
    ga_service = client.get_service("GoogleAdsService")

    # Get customer resource names from the original code
    customer_service = client.get_service("CustomerService")
    accessible_customers = customer_service.list_accessible_customers()
    customer_resource_names = accessible_customers.resource_names

    # Prepare a list to store customer data
    list_clients = []

    # Iterate through each customer resource name
    for resource_name in customer_resource_names:
        # Extract the customer ID from the resource name
        custom_id = resource_name.split('/')[-1]

        # Create a query using the customer_id
        query = f'''
            SELECT
            customer_client.descriptive_name,
            customer_client.id,
            customer_client.status
            FROM customer_client
        '''

        stream = ga_service.search_stream(customer_id=custom_id, query=query)
       
        for batch in stream:
            for row in batch.results:
                data_clients = {}
                data_clients["descriptive_name"] = row.customer_client.descriptive_name
                data_clients["id"] = row.customer_client.id
                data_clients["status"] = row.customer_client.status
                list_clients.append(data_clients)

    # Pass the list of customer data to the template
    context = {
        'list_clients': list_clients,
    }
    return render(request, 'one.html', context)

It gives me the error "authorization_error: USER_PERMISSION_DENIED" (which I don't understand, because it should be automatically showing the accounts that the user has permission to access, I'm not giving those accounts/IDs manually).


Google Ads API Forum Advisor

unread,
Aug 9, 2023, 8:47:15 AM8/9/23
to delval...@gmail.com, adwor...@googlegroups.com

Hi Miguel,

 

Would you be so kind as to provide the complete API logs (request and response with request-id and request header) generated on your end? This is so we can further check your implementation and investigate further:

 

For the client libraries, logging can be enabled by navigating to the Client libraries > Your client library (ex Java) > Logging documentation, which you can access from this link: https://developers.google.com/google-ads/api/docs/client-libs. For REST interface requests, you can enable logging via the curl command by using the -i flag. This will cause the tool to include the HTTP response headers in the output.

 

You may send the requested information via the Reply privately to author option. Note that you may need to join the Google Group for you to use this option. If this option is not available on your end still, you may send the details directly to our alias `googleadsa...@google.com` instead.

Olivier Clémence

unread,
Nov 22, 2023, 4:18:55 AM11/22/23
to Google Ads API and AdWords API Forum
Hi, 
i use this to get the descriptive name in one go : 
$query = 'SELECT customer_client.descriptive_name, 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 FROM customer_client WHERE customer_client.level <= 1';

Google Ads API Forum Advisor

unread,
Nov 22, 2023, 10:44:21 AM11/22/23
to man...@gmail.com, adwor...@googlegroups.com
Hi,

Thank you for reaching out to the Google Ads API support team.

The solution provided by ‘Olivier’ is correct. I would recommend you to kindly execute the below query for retrieving the descriptive name from the customer_client resource. 
 
SELECT customer_client.descriptive_name, customer_client.client_customer, customer_client.level, customer_client.manager, customer_client.currency_code, customer_client.time_zone, customer_client.id FROM customer_client WHERE customer_client.level <= 1

Please let us know if you run into any issues with this solution. 

Kindly get back to us if you have any further questions related to the Google Ads API. 
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02ZM01g:ref"


Thanks,
 
Google Logo Google Ads API Team


Rathina Boopathi

unread,
May 15, 2024, 11:52:04 AM5/15/24
to Google Ads API and AdWords API Forum
Hi all,

I tried the query the API team gave. I got the following error and the response itself takes above 10secs. 
mg {
  errors: [],
  '@type': 'type.googleapis.com/google.rpc.BadRequest',
  field_violations: [
    {
      description: 'Invalid value (query), Starting an object on a scalar field'
    }
  ]
}

What is the status of getting the descriptive names in listAccessibleCustomers() call itself?

Google Ads API Forum Advisor

unread,
May 16, 2024, 1:13:54 AM5/16/24
to rathinabo...@gmail.com, adwor...@googlegroups.com
Hi,

Kindly note that the error message Invalid value (query), Starting an object on a scalar field indicates that you're trying to use a query parameter within the listAccessibleCustomers() method, which is not supported. I would like to inform you that the query which we have provided to you is a valid query and I did not receive any error message when I tried to validate it. So, i suggest you try running the given query again and let me know how it goes at your end.
SELECT customer_client.descriptive_name, customer_client.client_customer, customer_client.level, customer_client.manager, customer_client.currency_code, customer_client.time_zone, customer_client.id FROM customer_client WHERE customer_client.level <= 1
You can use Query Builder to create your query and Query Validator to validate your query. Kindly refer to the document customer to get more information on all the available fields in the customer report.

I hope this helps. kindly get back to us if you have any further queries.
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02ZM01g:ref" (ADR-00101552)


Thanks,
 
Google Logo Google Ads API Team


Reply all
Reply to author
Forward
0 new messages