Sadly, there are no examples of this (and I've been digging for some time.)
I would like to be able to programmatically modify a campaign's budget. I can see that BudgetService exists, but I don't know how (or where to go to find out how) to get the id of a budget or the name of a budget.
I surmise that one has to query the campaign for its budget, derive from that the budgetId and then use that in a BudgetService request. Is that the case? If not, what's the go?
I don't know what language / client library you are using, but the following should work for Ruby, assuming that you already have your configuration and authorization handled. I'd imagine it would be very similar in any of the other client libraries.
First, establish an API connection.
adwords = AdwordsApi::Api.new
Use CampaignService to get the budget's id. You can also learn the budget's current amount and period (DAILY, MONTHLY, etc).
campaign_srv = adwords.service(:CampaignService, API_VERSION)
selector = {
fields: ['Id', 'Name', 'BudgetId', 'BudgetName', 'Amount', 'Period'],
predicates: [
{field: 'Id', operator: 'EQUALS', values: [CAMPAIGN_ID]}
]
}
campaign_response = campaign_srv.get(selector)
Extract the budget's id from the response, and use BudgetService to alter the amount.
budget_id = response[:entries][0][:budget][:budget_id]
budget_srv = adwords.service(:BudgetService, API_VERSION)
operation = {
operator: 'SET',
operand: {
id: budget_id,
amount: DESIRED_AMOUNT_IN_LOCAL_CURRENCY_FOR_ACCOUNT
}
}
budget_response = budget_srv.mutate([operation])