Last active
October 13, 2017 01:22
-
-
Save bmcbride/592777220b7bd141d517 to your computer and use it in GitHub Desktop.
Update Fulcrum records from a CSV file.
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
import csv | |
from fulcrum import Fulcrum | |
from fulcrum.exceptions import NotFoundException | |
api_key = 'your-api-key' | |
form_id = 'your-form-id' | |
fulcrum = Fulcrum(key=api_key) | |
updates = csv.reader(open('record-updates.csv'), delimiter=',') | |
# skip header | |
next(updates, None) | |
# loop through CSV records | |
for row in updates: | |
# fetch existing record | |
try: | |
data = fulcrum.records.find(row[0]) | |
except NotFoundException: | |
print 'No record found with id ' + row[0] | |
continue | |
# update fields with CSV values | |
data['record']['form_values']['9d69'] = row[5] | |
data['record']['form_values']['1299'] = row[6] | |
# send updates back to Fulcrum | |
record = fulcrum.records.update(row[0], data) | |
print 'Record ' + row[0] + ' successfully updated!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Bryan i'm a newby in this area and trying to learn, is this script assuming that the CSV is ready to be uploaded right?
So the full process will be to download the outdated records on a CSV, update de records and then apply the script right?
Thanks
Hector Garcia