Last active
February 1, 2021 19:40
-
-
Save limata3/ca94430c2fa2f04f43827407a0cae63c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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