Google Ads API - Invalid Customer ID

82 views
Skip to first unread message

Ahmet Buğra Buğa

unread,
Feb 28, 2025, 4:21:44 AM2/28/25
to Google Ads API and AdWords API Forum
Hi team,

I am using Google Ads API to get report from Google Ads. I am running the same code on GCP but when I try to run it locally I get an error. The error says Invalid Customer ID. I am sure everything is correct, I am using Python 3.12 version and using latest version of Google Ads API. But I get the same error every time. I am sending my code script and error message:

def get_campaign(date_start, date_end, customer_id):
ca_query = f"""
SELECT
campaign.id,
campaign.name,
customer.id,
customer.descriptive_name,
customer.currency_code,
segments.date,
segments.product_brand,
segments.product_title,
segments.product_item_id,
metrics.clicks,
metrics.cost_micros,
metrics.impressions
metrics.conversions,
metrics.conversion_value,
metrics.revenue_micros,
metrics.gross_profit_micros,
metrics.product_category_level1,
metrics.product_category_level2,
metrics.product_category_level3,
metrics.product_category_level4,
metrics.product_category_level5

FROM campaign
WHERE
segments.date BETWEEN {"'" + date_start + "'"} AND {"'" + date_end + "'"}"""

search_request = gads_client.get_type("SearchGoogleAdsStreamRequest")
search_request.customer_id = f"{customer_id}"
search_request.query = ca_query
gads_stream = gads_ga_service.search_stream(search_request)
print("Google Ads Client OK")

data_list = []
for batch in gads_stream:
for row in batch.results:
data_dict = {
'campaign_id': row.campaign.id,
'campaign.name': row.campaign.name,
'customer_id': row.customer.id,
'customer_name': row.customer.descriptive_name,
'product_brand': row.segments.product_brand,
'product_title': row.segments.product_title,
'product_item_id': row.segments.product_item_id,
'currency_code': row.customer.currency_code,
'ad_group_id': row.ad_group.id,
'ad_group_name': row.ad_group.name,
'date': row.segments.date,
'clicks': row.metrics.clicks,
'cost_micros': row.metrics.cost_micros,
'impressions': row.metrics.impressions,
'conversions': row.metrics.conversions,
'conversion_value': row.metrics.conversion_value,
'revenue_micros': row.metrics.revenue_micros,
'gross_profit_micros': row.metrics.gross_profit_micros,
'product_category_level1': row.metrics.product_category_level1,
'product_category_level2': row.metrics.product_category_level2,
'product_category_level3': row.metrics.product_category_level3,
'product_category_level4': row.metrics.product_category_level4,
'product_category_level5': row.metrics.product_category_level5

}
data_list.append(data_dict)

df = pd.DataFrame(data_list)
print("Dataframe read is OK!")
try:
df[['cost_micros']] = df[['cost_micros']] / 1000000

df['date'] = df['date'].astype('datetime64[ns]')
except:
print("Columns has not found")

return df

I forward to API my customer_id like below:

"2852897198"

Can you help me about this ? 


Best,
Bugra

xiaochuan li

unread,
Feb 28, 2025, 5:53:04 AM2/28/25
to Google Ads API and AdWords API Forum
Line 15, missing comma at the end of the line.

metrics.impression

Google Ads API Forum Advisor

unread,
Feb 28, 2025, 7:07:47 AM2/28/25
to bugra...@mathrics.com, adwor...@googlegroups.com
Hi Bugra,

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

Based on the information provided, I understand that you are encountering the "INVALID_CUSTOMER_ID" error. Kindly note that this error occurs when you pass the invalid customer ID while making the API request. So kindly make sure you pass the correct customer ID without hyphens (-) in your API request. Also, as per the provided GAQL I could see that you are using some fields which are not supported in the campaign resource. I would recommend you to refer to this documentation to know more about the Fields/Segments/Metrics that can be used with the campaign resource.

If you still face any issues, in order to investigate your issue further, kindly provide us with the complete API logs (request and response logs with request-id and request header) generated at your end to better assist you further.

If you are using a client library and haven't enabled the logging yet, I would request you to enable logging for the specific client library that you are using. You can refer to the guide PHP to enable logging at your end. For REST interface requests, you can enable logging via the curl command by using the -i flag.

You can send the details via Reply privately to the author option, or direct private reply to this email.
 

Thanks,
 
Google Logo Google Ads API Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5
[2025-02-28 12:07:03Z GMT] This message is in relation to case "ref:!00D1U01174p.!5004Q02vH4kg:ref" (ADR-00290456)



Google Ads API Forum Advisor

unread,
Feb 28, 2025, 7:11:03 AM2/28/25
to bugra...@mathrics.com, adwor...@googlegroups.com
Hi Bugra,

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

Please ignore my previous response.


Based on the information provided, I understand that you are encountering the "INVALID_CUSTOMER_ID" error. Kindly note that this error occurs when you pass the invalid customer ID while making the API request. So kindly make sure you pass the correct customer ID without hyphens (-) in your API request. Also, as per the provided GAQL I could see that you are using some fields which are not supported in the campaign resource. I would recommend you to refer to this documentation to know more about the Fields/Segments/Metrics that can be used with the campaign resource.

If you still face any issues, in order to investigate your issue further, kindly provide us with the complete API logs (request and response logs with request-id and request header) generated at your end to better assist you further.

If you are using a client library and haven't enabled the logging yet, I would request you to enable logging for the specific client library that you are using. You can refer to the guide Python to enable logging at your end. For REST interface requests, you can enable logging via the curl command by using the -i flag.


You can send the details via Reply privately to the author option, or direct private reply to this email.
 

Thanks,
 
Google Logo Google Ads API Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5

[2025-02-28 12:10:13Z GMT] This message is in relation to case "ref:!00D1U01174p.!5004Q02vH4kg:ref" (ADR-00290456)



Google Ads API Forum Advisor

unread,
Feb 28, 2025, 9:09:27 AM2/28/25
to clixia...@gmail.com, adwor...@googlegroups.com
Hi Bugra,

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

Based on the information provided, I understand that you are encountering the "INVALID_CUSTOMER_ID" error. Kindly note that this error occurs when you pass the invalid customer ID while making the API request. So kindly make sure you pass the correct customer ID without hyphens (-) in your API request. Also, as per the provided GAQL query, I could see that you are using some fields which are not supported in the campaign resource. I would recommend you to refer to this documentation to know more about the Fields/Segments/Metrics that can be used with the campaign resource.


If you still face any issues, in order to investigate your issue further, kindly provide us with the complete API logs (request and response logs with request-id and request header) generated at your end to better assist you further.

If you are using a client library and haven't enabled the logging yet, I would request you to enable logging for the specific client library that you are using. You can refer to the guide Python to enable logging at your end. For REST interface requests, you can enable logging via the curl command by using the -i flag.

You can send the details via Reply privately to the author option, or direct private reply to this email.
 

Thanks,
 
Google Logo Google Ads API Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5

[2025-02-28 14:08:34Z GMT] This message is in relation to case "ref:!00D1U01174p.!5004Q02vH4lZ:ref" (ADR-00290467)



Reply all
Reply to author
Forward
0 new messages