Created
March 11, 2016 18:18
-
-
Save jeremiahmarks/27897e065e318f06095f to your computer and use it in GitHub Desktop.
Link contacts to companies in Infusionsoft based on data in 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
# @Author: jeremiah.marks | |
# @Date: 2016-03-11 10:43:53 | |
# @Last Modified by: jeremiah.marks | |
# @Last Modified time: 2016-03-11 11:17:56 | |
# This script will process a csv which contains an FKID | |
# column and a companyId column and assign the contacts | |
# to the correct company. | |
# These variables will be determined by the names the columns | |
# in your csv or the custom fields in Infusionsoft | |
fkidColumnName = 'FKID' | |
companyIdColumn = 'companyId' | |
fkidCustomFieldName = '_FKID' | |
appname = '' | |
apikey = '' | |
import csv | |
import xmlrpclib | |
import Tkinter as tk | |
import tkFileDialog | |
tk.Tk().withdraw() | |
def getFilePath(): | |
return tkFileDialog.askopenfilename() | |
def main(): | |
companies={} | |
appurl = "https://%s.infusionsoft.com:443/api/xmlrpc" %(appname) | |
print "Please select input file:" | |
inputfile = getFilePath() | |
connection = xmlrpclib.ServerProxy(appurl) | |
with open(inputfile, 'r') as csvin: | |
thisreader = csv.DictReader(csvin) | |
for eachrow in thisreader: | |
companyid = int(eachrow[companyIdColumn]) | |
contactFKID = eachrow[fkidColumnName] | |
searchresult = connection.DataService.query(apikey, 'Contact', 1, 0, {fkidCustomFieldName: contactFKID}, ['Id', ], ['Id'], False)[0] | |
if companyid not in companies: | |
companies[companyid] = connection.DataService.query(apikey, 'Company', 1, 0, {'Id': companyid}, ['Company', ], ['Id'], False)[0]['Company'] | |
connection.DataService.update(apikey, 'Contact', searchresult['Id'], {'AccountId': companyid, 'CompanyID': companyid, 'Company': companies[companyid]}) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment