Skip to content

Instantly share code, notes, and snippets.

@nealrs
Last active April 18, 2016 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nealrs/b47406464f2979727fef1eccd38c4f9d to your computer and use it in GitHub Desktop.
Save nealrs/b47406464f2979727fef1eccd38c4f9d to your computer and use it in GitHub Desktop.
bulk add notes to companies in prosperworks CRM
# API key
akey = "2cd366345l3derpppp3948city566ae6c"
# email address associated with API key
auser = "foo@bar.baz"
import requests
import json
import csv
from keys import *
### API CONFIG & KEYS
api = "https://api.prosperworks.com/developer_api/v1/activities"
h = {"X-PW-AccessToken": akey, "X-PW-Application" : "developer_api","X-PW-UserEmail" : auser}
### OPEN CSV
f = csv.reader(open("data.csv", "rU"), dialect=csv.excel_tab, delimiter=",")
header = f.next() # truncate header row (expected order: companyid, userid, activity date (as a timestamp), and the note as a string)
# ITERATE THROUGH CSV & MAKE API CALLS
# FYI, rate limit is 600 calls / 10 min ~ evaluated on rolling basis
for a, b, c, d in f:
print "\n"
# assign parameters
company_id = a
user_id = b
activity_date = c
details = d.decode('utf-8', 'ignore')
print "processing: ", str(a), str(b), str(c), str(d)
# compile payload
parent = {"type":"company", "id": int(company_id)}
atype = {"category": "user", "count_as_interaction": "false", "is_disabled": "false", "id": 0, "name": "Note"}
data = {"parent": parent, "type": atype, "details": details, "user_id": int(user_id), "activity_date": int(activity_date)}
# print payload
#print json.dumps(data)
# run api call
r = requests.post(api, json=data, headers=h)
# print response
print json.dumps(r.json())
print "All CSV rows processed -- verify online :)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment