Get customer ID - PHP V13 Google Ads

199 views
Skip to first unread message

Jessica Villa

unread,
May 3, 2023, 7:45:04 PM5/3/23
to Google Ads API and AdWords API Forum
Hello!

I have a question and hope someone can help me: how can I get the customer ID if I only have the ad_group_id?

I tried using this query: 
$query = "SELECT customer.id FROM ad_group WHERE ad_group.id = ".$ad_group_id." LIMIT 1";

and accessing like this: $googleAdsClient->getCustomerId()

but my query is not successful, so is this the right way?

Note:
$ad_group_id is retrieved from an array so the query is dynamic, and the customer id too, so that's why I want to get the customer id.

I'm using php v13 of google ads.

Thanks!!

Google Ads API Forum Advisor

unread,
May 4, 2023, 6:36:19 AM5/4/23
to jes...@cleverclick360.com, adwor...@googlegroups.com

Hi Jessica,

Thank you for reaching out to us.

For our team to further check this and provide you with an appropriate recommendation, could you please provide us with the complete API logs (request and response with request-id) generated on your end?

Note that logs can be requested or provided to the developer handling the Google Ads API transactions when logging of the API requests has been enabled.

This is the specific guideline to enable PHP: https://developers.google.com/google-ads/api/docs/client-libs/php/logging

You may then send the requested information via the Reply privately to author option. If this option is not available, you may send the details directly to our googleadsa...@google.com alias instead.

Best regards,
Google Logo Google Ads API Team


ref:_00D1U1174p._5004Q2lA73z:ref

Jessica Villa

unread,
May 4, 2023, 5:54:18 PM5/4/23
to Google Ads API and AdWords API Forum
The issue is not the log, is to know if there is possible to retrieve the customer.id having only the ad_group_id
doing the $query and using search() like this:
$googleAdsServiceClient->search($query);

or something, in the examples couldn't find something about it

Thank you!

Google Ads API Forum Advisor

unread,
May 5, 2023, 5:57:37 AM5/5/23
to jes...@cleverclick360.com, adwor...@googlegroups.com
Hi Jessica,

Thank you for responding back with the additional context of your concern.

As per your use case, customer is an attributed resources of ad_group report so you should be able to retrieve the customer fields from ad_group report. Here's an example query for your reference.
 
SELECT customer.id, customer.descriptive_name, ad_group.id, ad_group.name FROM ad_group WHERE ad_group.id = 'AD_YOUR_ADGROUP_ID_HERE'

Regards,
Message has been deleted

Jessica Villa

unread,
May 5, 2023, 1:41:28 PM5/5/23
to Google Ads API and AdWords API Forum
Thank you for your answer, I have other question:
using the function search()  or searchStream() is the right way to retrieve info?

$googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();
$query = "SELECT customer.id, customer.descriptive_name, ad_group.id, ad_group.name FROM ad_group WHERE ad_group.id = AD_GROUP_ID LIMIT 1";
$response = $googleAdsServiceClient->searchStream('????' $query); // is this line right?

foreach ($response->iterateAllElements() as $googleAdsRow) {
$customers[] = [
'customer_client.id' => $googleAdsRow->getCustomerClient()->getId(),
];
}
 because I got empty response... and maybe is another way to get the info.

I don't have the customer_id value (so that's why I put '???' I don't know exactly if I am using the right function), only I got ad_group_id value

Thank you!

Jessica Villa

unread,
May 5, 2023, 2:02:09 PM5/5/23
to Google Ads API and AdWords API Forum
If I put the manager id as param of searchStream I got an empty result but no errors...

$googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();
$query = "SELECT customer.id, customer.descriptive_name, ad_group.id, ad_group.name FROM ad_group WHERE ad_group.id = AD_GROUP_ID LIMIT 1";
$response = $googleAdsServiceClient->searchStream('MANAGER_ACCOUNT_ID' $query); // is this line right?

foreach ($response->iterateAllElements() as $googleAdsRow) {
$customers[] = [
'customer_client.id' => $googleAdsRow->getCustomerClient()->getId(),
];
}

is there any function where customer id don't need to be required in order to get the customer id?

Thank you again!

Google Ads API Forum Advisor

unread,
May 8, 2023, 1:27:33 AM5/8/23
to jes...@cleverclick360.com, adwor...@googlegroups.com

Hi,

Thanks for getting back to us.

Please note that as per the guide included in the links below, both GoogleAdsService.Search and GoogleAdsService.SearchStream would require the customer_id to be supplied in the request body. 

Can you try performing a request to List Accessible Accounts method? Through this method, you can list customers accessible to you. Listing accessible customers is one of the few requests in the Google Ads API that does not require you to specify a customer ID in the request. The resulting list of customers is based on your OAuth credentials. The request returns a list of all accounts that you are able to act upon directly given your current credentials. This will not necessarily include all accounts within the account hierarchy, rather, it will only include accounts where your authenticated user has been added with admin or other rights in the account.

You may also try checking the Find your Google Ads customer ID help article in finding your customer ID from Google Ads UI.

Let us know how it goes.

Reference links included in this email:

Reply all
Reply to author
Forward
0 new messages