Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save limata3/ca94430c2fa2f04f43827407a0cae63c to your computer and use it in GitHub Desktop.
Save limata3/ca94430c2fa2f04f43827407a0cae63c to your computer and use it in GitHub Desktop.
def create_and_assign_budget():
adwords_client = connect_to_adwords_api()
# This bit here creates the budget
budget_service = adwords_client.GetService('BudgetService', version='v201809')
budget = {
'name': {an appropriate name}, # Doesn't need to be unique. Budget Id is what matters for uniqueness
'amount': {
'microAmount': int(round({budget_amount} * 1000000))
},
'isExplicitlyShared': 'false',
'deliveryMethod': 'STANDARD'
}
budget_operations = [{
'operator': 'ADD',
'operand': budget
}]
budget_id = budget_service.mutate(budget_operations)['value'][0]['budgetId']
# And this 2nd part of the function assigns it to your campaign
campaign_service = adwords_client.GetService('CampaignService', version='v201809')
campaign = {
'id': {campaign_id},
'budget': {
'budgetId': budget_id
},
}
campaign_service.mutate([{
'operator': 'SET',
'operand': campaign
}])
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment