Update Adset Bids - https://mirigrowth.com/blog/automation-facebook-marketing-api-scripts
This file contains 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
# 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