Search code examples
node.jsgoogle-apigoogle-ads-apigoogle-api-nodejs-client

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?


Solution

  • 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

    enter image description here

    If you still have an issue with this, could you please share the request and response logs so I can take a closer look?