Skip to content

Instantly share code, notes, and snippets.

@zachmiri
Created September 19, 2019 10:39
Show Gist options
  • Save zachmiri/9ba0d2ac78db4aa93e9aae48e13242de to your computer and use it in GitHub Desktop.
Save zachmiri/9ba0d2ac78db4aa93e9aae48e13242de to your computer and use it in GitHub Desktop.
# Update Adset Bids
import requests
import json
import time
# Update with your Facebook Ad Account ID and Access Token
access_token = ''
# Update with a list of IDs, bids, and bid type to update
# Note: bid types can be event or minroas
# Note: event bids are multipled by 100 e.g $100 should be 10000 via the API
# Note: minroas bids are multiplied by 10000 e.g 0.010 should be 100 via the API
to_update = [
{
'id': '',
'bid': '',
'type': ''
}
]
for update in to_update:
time.sleep(0.5)
if update['type'] == 'event':
data_dump = {
'bid_amount': update['bid'],
'access_token': access_token
}
elif update['type'] == 'minroas':
data_dump = {
"bid_constraints": json.dumps({"roas_average_floor": update['bid']}),
'access_token': access_token
}
else:
data_dump = {}
print('Bid Type is missing.')
r = requests.post('https://graph.facebook.com/v4.0/' + update['id'], data=data_dump)
result = r.json()
if 'success' in result:
print('Successfully updated ID: ' + update['id'])
else:
print('Error updating ID: ' + update['id'] + ', Error: ' + result['error']['message'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment