Get campaign amount spend using node.js

165 views
Skip to first unread message

Leonardo Lins

unread,
Mar 7, 2023, 7:01:58 PM3/7/23
to Google Ads API and AdWords API Forum
Hey guys,

How can I get the amount spent on all my campaigns in a specific time period?

I was reading the documentation, you guys don't have javascript library.

Should I use reports? https://developers.google.com/google-ads/api/fields/v13/campaign#segments.date

Or use the rest interface? if the answer is yes to using the rest interface, what is the correct rest resource to get all the campaigns and the amount spent?

Thank you very much!!

Google Ads API Forum Advisor

unread,
Mar 8, 2023, 5:41:29 AM3/8/23
to leonard...@gmail.com, adwor...@googlegroups.com

Hi Leonardo,

Thank you for raising this concern to the Google Ads API Forum. We hope you are doing well today.

Please refer to the answer below:

To answer your question, you can use the campaign report filtering metrics.cost_micros to get the amount spent. You can use the segments.date field specifically in the day not in time period. You may use the search and searchstream requests for REST.

On the other hand, you may check this sample code if you want to use the client library. You may just edit the query there.

You may also check this guide, as it describes the steps necessary to create and submit a query to the Google Ads API to get back data.

If the mentioned reports and fields not getting the data that you are looking for, you may provide us the complete Google Ads UI screenshot that you want to get by API.  For security purposes, you can provide it via the Reply privately to author option. If this option is not available, then send it instead on this email address googleadsa...@google.com.


Best regards,

Google Logo Google Ads API Team


ref:_00D1U1174p._5004Q2jX9Nx:ref

Leonardo Lins

unread,
Mar 14, 2023, 10:31:56 PM3/14/23
to Google Ads API and AdWords API Forum
Thanks for your response :)

If we use the search and searchstream requests for REST, where can I find the customerId path parameter?

Example below: 

questionCustomerId.png

Google Ads API Forum Advisor

unread,
Mar 15, 2023, 4:44:32 AM3/15/23
to leonard...@gmail.com, adwor...@googlegroups.com

Hi Leonardo,

Thank  you for the reply.

You may place your customerId to the HTTP request you can see here.
Screenshot 2023-03-15 4.43.22 PM
Let me know if you have further questions.

Best regards,

Leonardo Lins

unread,
Mar 15, 2023, 8:02:16 AM3/15/23
to Google Ads API and AdWords API Forum
Got it. 

So, how can I get my customerId?

Google Ads API Forum Advisor

unread,
Mar 15, 2023, 1:01:15 PM3/15/23
to leonard...@gmail.com, adwor...@googlegroups.com

Hi,

Thanks for getting back to us.

You may refer to this guide on how and where to find your Google Ads customer ID.

Let me know how it goes.

Regards,  

Leonardo Lins

unread,
Mar 16, 2023, 7:49:43 AM3/16/23
to Google Ads API and AdWords API Forum
Hi,

is there a way to get the customerId using the API?

Thanks!

Leonardo Lins

unread,
Mar 16, 2023, 7:55:08 AM3/16/23
to Google Ads API and AdWords API Forum

Because I'm integrating Google's Rest API with my platform.
So our customers use our platform to integrate with Google via OAuth, so we use the generated token to make the requests.

If there is a way to get the customerId via API I can do it because it's easier for my customers.

Google Ads API Forum Advisor

unread,
Mar 16, 2023, 1:18:02 PM3/16/23
to leonard...@gmail.com, adwor...@googlegroups.com
Hi Leonardo,

Thank you for returning to our team.

Regarding your concern, it appears that you want to get customerId via the Google Ads API. That said, as mentioned, the customerId is your account's id. As per this guide, this is the account number of the Google Ads client account you want to manage with the API, usually in the form 123-456-7890. You may use this Method: customers.listAccessibleCustomers as this will return a list of all accounts that you are able to act upon directly given your current credentials.

You may also check this document for more information about this.

Let us know if you have further questions.
Reply all
Reply to author
Forward
0 new messages