How to get Google Ads API for getting account list
How to query api to get the list of accounts for a customer using Nodejs.
Customer details can be fetched by https://googleads.googleapis.com/v3/customers/xxxxxxxxx/
. but How can I fetch all the account for a particular customer?
Yes, accounts list can be accessible. ListAccessibleCustomers returns resource names of customers directly accessible by some Google Account. You might filter manager accounts from the response and list all client accounts for manager accounts.
Since clients customers might be managers too you might need some kind of recursion to build an accounts tree.
Apply a GET request to the below URL:
URL: 'https://googleads.googleapis.com/v1/customers:listAccessibleCustomers?key=XXXXXX'
For more details, you can check the documentation
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 direct access to your MCC, this service will not include the sub-accounts under your MCC unless your OAuth credentials have direct access to your sub-accounts as well.
Edit: Using manager account credentials to authenticate your API call, you can use ManagedCustomerService.get to retrieve a list of all accounts under your manager account. As per documentation: Your developer token can belong to Root Manager Account 1, or even a different manager account in another hierarchy: It doesn't affect which accounts you can target, as long as you supply the client customer ID for the targeted account.
To make API calls against Client account A, you can use the OAuth2 credentials of a login associated with Client account A, and set the clientCustomerId request header to the customer ID of either Client A, Manager Account 2, or Root Manager Account 1.
In this structure, OAuth2 credentials for a login associated with Manager Account 3 can make calls only against Client Account C. These credentials cannot make calls targeting Client Account A or B, because it doesn't manage them. OAuth2 credentials of a login associated with Root Manager Account 1 can make calls against any of the accounts in the hierarchy.
Calls made with the credentials of a manager account can only target the manager account or accounts that are beneath it in the hierarchy. Thus, in this hierarchy, only Root Manager Account 1 can make calls against Client Account D.
If you use either of the manager accounts, then set the clientCustomerId to that manager account, or one of its child accounts.
To read more about the ManagedCustomerService here is an official Link
If you still have an issue with this, could you please share the request and response logs so I can take a closer look?
ListAccessibleCustomers returning the manager accounts. I have lots of client accouts inside manager. I need the client account for a customer id. What is the KEY here?
this service will not include the sub-accounts under your MCC unless your OAuth credentials have direct access to your sub-accounts as well. key is adwards api key
I need all sub account under the mcc account. These are the client accounts. Is there any way to list them?
Using manager account credentials to authenticate your API call, you can use ManagedCustomerService.get to retrieve a list of all accounts under your manager account.
It will be good to work with you @SiddharthRout but I am quite busy with other priorities.
assuming what you want is the sub accounts, aka "client accounts", for the MCC, you can get them by running a report. Here's some code using the nodejs good-ads-api library:
let client = new GoogleAdsApi({ client_id: clientId, client_secret: clientSecret, developer_token: devToken }) let main = await client.listAccessibleCustomers(refreshToken) let mainId = main.resource_names?.[0]?.split('/').pop() let mcc = client.Customer({ customer_id: mainId, refresh_token: refreshToken, login_customer_id: mainId, }) let clusterClients = await mcc.report({ entity: 'customer_client', attributes: ['customer_client.id', 'customer_client.resource_name', 'customer_client.descriptive_name'], })