Get the list of Customer IDs under a Manager account

1,861 views
Skip to first unread message

Miguel Angel Garcia

unread,
Jul 26, 2022, 1:16:30 PM7/26/22
to Google Ads API and AdWords API Forum
I want to get info (just for reporting) of all the customers that are being managed by my Manager account. 

I'm specially interested in getting a list of all the Customer IDs, but having other extra info and stats would be nice too. 

I've tried with https://developers.google.com/google-ads/api/fields/v11/customer_client, but it gives me an error (INVALID_CUSTOMER_ID).

I've tried with the Customer ID of my Manager account and also with the ID of one of the customers/accounts being managed. Same error. 

I'm always using my Manager Customer ID as the login-customer-id for the API. 

I have many other API queries working OK (to create reports of individual clients), but I'm not sure how to configure it for reporting at a Manager level.  

Any tips or links would be much appreciated.

Thanks!

Google Ads API Forum Advisor

unread,
Jul 26, 2022, 4:45:12 PM7/26/22
to delval...@gmail.com, adwor...@googlegroups.com
Hi Miguel,

Thank you for reaching out to Google Ads API with your question. To explain how to access accounts in a visual way here are the following pointers:

Imagine that the same Google account that generated the refresh token used to access the API was to access an account in the Ads UI. They will see all the the accounts that List Accessible Accounts returns in the top right drop down list when you click the circle representation of the user in the UI. These are accounts the user has direct access to. If an account in that list is an MCC with child accounts attached, then to see the child accounts you would select that MCC in the top right of the UI and then the child accounts are accessible in the top left - middle accounts drop down list box in the UI. These are the same accounts that Get Account Hierarchy shows. 

To access accounts that are in the top left - middle accounts drop down list box via the API you would put the selected account in the top right list in the UI as login customer Id, and you would put the selected account in the top left - middle accounts drop down list box as the operating customer.

Here are a few more useful pointers:

Here's our login customer Id guide and migration guide.

Any account returned by List Accessible Accounts when using a specific refresh token doesn't need the login customer Id.

Another property of those accounts returned by List Accessible Accounts is they are the only accounts that can be a login customer Id for the specific refresh token making the API call.

Any account returned by Get Account Hierarchy when you you don't specify manager ID and login customer ID can be accessed by your refresh token you used to make the API call.

Debugging API calls:

To generate a refresh token and be able to detect who generated it you can follow our OAuth Playground guide and add another scope -https://www.googleapis.com/auth/userinfo.email.

 If that works, then generate an access token from that refresh token in a Bash Terminal.

  • curl --data "refresh_token=<INSERT_REFRESH_TOKEN>&client_id=<INSERT_YOUR_CLIENT_ID_FROM_API_CONSOLE>&client_secret=<INSERT_CLIENT_SECRET>&grant_type=refresh_token" -X POST "https://oauth2.googleapis.com/token"

Now, we want to check the data on the access token to make sure everything on the access token is working as expected. Put this in your browser with the access token inserted that you got back.

If that works, then let's try a request from the command line:

  • curl --header "Authorization: Bearer <INSERT_ACCESS_TOKEN>" --header "developer-token: <INSERT_DEV_TOKEN>" --header "login-customer-id: {LGNCID}" --data "{ 'query': 'SELECT campaign.id FROM campaign LIMIT 1' }" -X POST -H "Content-Type: application/json" https://googleads.googleapis.com/v11/customers/{CID}/googleAds:searchStream

If the above doesn't help you, can you send us the log of all your refresh token creation attempt listed above and the list of accounts returned when following the List Accessible Accounts guide?

You may send the requested information via "Reply to author" or via googleadsa...@google.com with a link to this forum post added to the new thread.

Regards,

Google Logo
Aryeh
Google Ads API Team
 



 

ref:_00D1U1174p._5004Q2d1gXF:ref

Miguel Angel Garcia

unread,
Jul 27, 2022, 3:11:14 AM7/27/22
to Google Ads API Forum Advisor, adwor...@googlegroups.com
Thanks for the detailed response, but it sounds super confusing to me. Probably my fault, not yours. 

I want the top left - middle accounts drop down (accounts under my MCC), so I guess I have to use https://developers.google.com/google-ads/api/docs/account-management/get-account-hierarchy, right?

If I understand correctly the comments on that code, sending login_customer_id is not required but the API query should work OK if I send the login_customer_id (just like I'm doing in the other API queries that are working OK), right?

I guess I don't need to send any Customer ID (it wouldnt make sense, because what I want to get is the list of Customer IDs under my MCC), but I still get the INVALID_CUSTOMER_ID error when I don't provide any. 

Also, do I have to use all the code on https://developers.google.com/google-ads/api/docs/account-management/get-account-hierarchy just to get a simple list of the Customer IDs (I don't care about hierarchy, I just want a simple list of IDs)?

Seems a super complex code to get something very simple. All my other API queries are basically just the GAQL query, a couple of lines of Python code to process the info from the query and that's it. There is no simple solution like this to get a list of the Customer IDs?

In case it helps this is a bigger version of the error that I get:

GoogleAdsException at /listing
(<_SingleThreadedRendezvous of RPC that terminated with:
status = StatusCode.INVALID_ARGUMENT
details = "Request contains an invalid argument."
debug_error_string = "{"created":"@1658904934.409000000","description":"Error received from peer ipv4:142.250.200.138:443","file":"src/core/lib/surface/call.cc","file_line":953,"grpc_message":"Request contains an invalid argument.","grpc_status":3}"
>, <_SingleThreadedRendezvous of RPC that terminated with:
status = StatusCode.INVALID_ARGUMENT
details = "Request contains an invalid argument."
debug_error_string = "{"created":"@1658904934.409000000","description":"Error received from peer ipv4:142.250.200.138:443","file":"src/core/lib/surface/call.cc","file_line":953,"grpc_message":"Request contains an invalid argument.","grpc_status":3}"
>, errors {
  error_code {
    request_error: INVALID_CUSTOMER_ID
  }
  message: "Invalid customer ID \'\'."
}
request_id: "Vn8OyAiSL6hALb_i1O7feA"
, 'Vn8OyAiSL6hALb_i1O7feA')

Thanks!

Google Ads API Forum Advisor

unread,
Jul 27, 2022, 4:46:21 AM7/27/22
to delval...@gmail.com, adwor...@googlegroups.com

Hi Miguel,

Thanks for getting back to us.

Upon checking the stacktrace you’ve provided with us, I can see that you’ve encountered an INVALID_CUSTOMER_ID error. It appears that the customer_id field is not set in your request or customer_id is added with hyphens (-). Could you please double check if you’re indeed using the correct CID on your end without hyphens (-)?

If you’re running Python client library code using terminal, then the value is passed via the command line when executing the example, so for instance, note the -c flag in the below command:

python examples/basic_operations/get_campaigns.py -c 123456789

With regards to questions asked in above email, you may see below responses:



I want the top left - middle accounts drop down (accounts under my MCC), so I guess I have to use https://developers.google.com/google-ads/api/docs/account-management/get-account-hierarchy, right?

>> Your understanding is correct.



If I understand correctly the comments on that code, sending login_customer_id is not required but the API query should work OK if I send the login_customer_id (just like I'm doing in the other API queries that are working OK), right?

>> your understanding is correct. Login_customer_id is optional for this guide.



I guess I don't need to send any Customer ID (it wouldnt make sense, because what I want to get is the list of Customer IDs under my MCC), but I still get the INVALID_CUSTOMER_ID error when I don't provide any. 

>> Could you provide us with the complete request and response logs with the request-id generated after following the logging guide , so our team can better check?

For the Python client library, logging can be enabled by navigating to the Client libraries > Your client library (select Python) > Logging documentation, which you can access from this link. You may then send the requested information via the Reply privately to author option.



Also, do I have to use all the code on https://developers.google.com/google-ads/api/docs/account-management/get-account-hierarchy just to get a simple list of the Customer IDs (I don't care about hierarchy, I just want a simple list of IDs)?

>> This example fetches the account hierarchy of the specified manager account and login customer ID. If you don't specify manager ID and login customer ID, the example will instead print the hierarchies of all accessible customer accounts for your authenticated Google account. Note that if the list of accessible customers for your authenticated Google account includes accounts within the same  hierarchy, this example will retrieve and print the overlapping portions of the hierarchy for each accessible customer.



Seems a super complex code to get something very simple. All my other API queries are basically just the GAQL query, a couple of lines of Python code to process the info from the query and that's it. There is no simple solution like this to get a list of the Customer IDs?

>> You may also use customer_client report to get the list of the Customer IDs under the manager account.

Regards,

Google Logo
Yasar
Google Ads API Team
 


ref:_00D1U1174p._5004Q2d1gXF:ref
Reply all
Reply to author
Forward
0 new messages