How to get "Cost within spending limit" and "Budget left" for a campaign?

72 views
Skip to first unread message

Haiyang Si

unread,
Oct 28, 2021, 4:04:26 AM10/28/21
to AdWords API and Google Ads API Forum
Hi support team,

As in the image below, I am trying to set the daily budget based on the budget left and the day left dynamically.

Is there an easy way to get the Cost within spending limit or Budget left for a campaign?

Screen Shot 2021-10-28 at 12.35.03 AM.png

Currently, I do it in this way:
1. get the start_date of a campaign
2. query the metrics.cost_micros from start_date until today
    query = f"""
        SELECT 
            campaign_budget.amount_micros, 
            campaign_budget.total_amount_micros, 
            metrics.cost_micros,
        FROM 
            campaign_budget
        WHERE 
            campaign.id = 123456
            AND segments.date = '{input_date}'
    """

3. Because metrics.cost_micros is the "served cost" I have to calculate the real cost like this: real_cost = min(metrics.cost_micros, 2*campaign_budget.amount_micros)
4. Sum the real_cost in every day up as the "Cost within spending limit".


But in this way, there is a bug. 
Google query campaign_budget.amount_micros always returns the current daily_budget value, even the segments.date set on another day.
E.g. in the image below, on Oct, 26, 2021, the campaign_budget.amount_micros should be 850000, but the return value is amount_micros: 1220000 even the segments.date = '2021-10-25'. 
1220000 is the current daily_budget.

Screen Shot 2021-10-28 at 12.57.43 AM.png

In summary there are 1 question and 1 issue to report:
1. How to get the budget left or cost within spending limit easily?
2. There is a potential bug  when query campaign_budget.amount_micros. The return value is different from the value on segments.date date

Looking forward to your response.
Thank you!

Haiyang



Haiyang Si

unread,
Oct 28, 2021, 4:07:01 AM10/28/21
to AdWords API and Google Ads API Forum
BTW: forget to mention I reset the daily budget from 850000 to 1220000 on 2021-10-28

Haiyang Si

unread,
Oct 28, 2021, 4:08:54 AM10/28/21
to AdWords API and Google Ads API Forum
Looks like the image is not clear.
I repost the images

Screen Shot 2021-10-28 at 12.57.43 AM.pngScreen Shot 2021-10-28 at 12.35.03 AM.png

Google Ads API Forum Advisor

unread,
Oct 28, 2021, 3:48:52 PM10/28/21
to adwor...@googlegroups.com
Hi Haiyang,

Could you privately send us a request and response log of API communication that would show this issue?  The request and response appears similar to the JSON Mappings in our REST documentation. Our client libraries have loggers with logging instructions, to see these instructions you can click on the client library you use in the sidebar of our client library guide and click on "Logging". Setting the logger to 'DEBUG' will get the desired log.

Regards,

Google Logo
Aryeh Baker
Google Ads API Team
 


ref:_00D1U1174p._5004Q2QFvdQ:ref
Message has been deleted

Google Ads API Forum Advisor

unread,
Oct 29, 2021, 4:29:30 AM10/29/21
to adwor...@googlegroups.com
Hi Haiyan,

Thank you for sharing these details. However, I had to remove your most recent response as it contained your logs.

The budget details (Cost within spending limit, budget left) are currently not supported in the API. What you can currently only retrieve would be the following fields :
  • campaign_budget.amount_micros
  • campaign_budget.total_amount_micros
That being said, allow me to raise a feature request, subject for review, on the said UI fields to be supported in the API. For now, you may keep an eye on our blog for updates and announcements.

Moving forward to the discrepancy concern, could you also share the complete Google Ads UI screenshot containing the view of the campaign budget (with 850000 value) you mentioned is different from the value (1220000) retrieved via the API?

In addition, could you also share the updated and complete request and response logs, with the request-id, of your campaign_budget request? You may ensure that the login-cusotmer-id is also included so that our team may try to replicate the report on our end.

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
Peter Laurence Napa Oliquino
Google Ads API Team
 


ref:_00D1U1174p._5004Q2QFvdQ:ref

Mat

unread,
Oct 29, 2021, 7:06:19 AM10/29/21
to AdWords API and Google Ads API Forum
Hi Peter,

II would also very much appreciate such a feature. 

@Haiyang: Unlike the metrics fields,  the value of the campaign_budget.amount_micros field, just like any other resource field, is not subject to the segmentation (e.g. by day), but always reflect the current state of that resource at the moment you perform the request. 
So, if you want to keep track of historical values of the resource fields, you need to query them regularly and store the data on your end e.g. in a database.

Regards
Mat

Google Ads API Forum Advisor

unread,
Oct 29, 2021, 10:31:36 AM10/29/21
to m...@keyword-experte.de, adwor...@googlegroups.com
Hi Mat,

We have submitted your feature request internally. Please monitor the blog and release notes for updates on new feature additions.

Regards,
Matt
Google Ads API Team

Google Logo
Matt
Google Ads API Team
 


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