-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathISServerincremented.py
More file actions
158 lines (150 loc) · 16 KB
/
ISServerincremented.py
File metadata and controls
158 lines (150 loc) · 16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: Jeremiah Marks
# @Date: 2015-06-21 15:00:03
# @Last Modified 2015-07-08
# @Last Modified time: 2015-07-08 00:38:53
import xmlrpclib
class ISServer:
def __init__(self, infusionsoftapp, infusionsoftAPIKey):
self.infusionsoftapp=infusionsoftapp
self.infusionsoftAPIKey=infusionsoftAPIKey
self.appurl = "https://" + self.infusionsoftapp + ".infusionsoft.com:443/api/xmlrpc"
self.connection = xmlrpclib.ServerProxy(self.appurl)
########################################################
## Methods to get records from various tables
##
##
def getMatchingRecords(self, tableName, criteria, desiredFields=None, orderedBy=None):
"""Search at table by criteria
"""
return self.getAllRecords(tableName, searchCriteria=criteria, interestingData=desiredFields, orderedBy=orderedBy)
def getTagCats(self):
return self.getAllRecords("ContactGroupCategory")
def getAllTags(self):
return self.getAllRecords("ContactGroup")
def getAllProductCats(self):
return self.getAllRecords("ProductCategory")
def getAllProducts(self):
return self.getAllRecords("Product")
def getAllRecords(self, tableName, interestingData=None, searchCriteria=None, orderedBy=None):
if interestingData is None:
interestingData = tables[tableName]
if searchCriteria is None:
searchCriteria={}
if orderedBy is None:
orderedBy = interestingData[0]
records = []
p=0
while True:
listOfDicts = self.connection.DataService.query(self.infusionsoftAPIKey, tableName, 1000, p, searchCriteria, interestingData, orderedBy, True)
for each in listOfDicts:
thisRecord={}
for eachbit in interestingData: # this should be records.append(zip(interestingData, each)) perhaps
if not each.has_key(eachbit): # TODO: research THIS
each[eachbit]=None
thisRecord[eachbit] = each[eachbit]
records.append(thisRecord)
if not(len(listOfDicts)==1000):
break
p+=1
if
return records
########################################################
## Methods to create records
##
def cnp(self, productValues):
return self.createNewRecord('Product', productValues)
def createNewRecord(self, table, recordvalues):
return self.connection.DataService.add(self.infusionsoftAPIKey, table, recordvalues)
########################################################
## Methods to updating existing records
##
def updateRecord(self, tableName, recordId, updateValues):
return self.connection.DataService.update(self.infusionsoftAPIKey, tableName, recordId, updateValues)
def deleteRecordsOnTable(self, tableName):
allTableIds=self.getAllRecords(tableName, ["Id"])
for eachid in allTableIds:
try:
self.connection.DataService.delete(tablename, eachid)
except:
print "Cannot Delete " + str(eachid)
########################################################
## Method to create a new contact record, or updates an existing
## potential values for checktype are
## ['Email', 'EmailAndName', 'EmailAndNameAndCompany']
def dupeCreate(self, contactData={}, checktype='Email'):
return self.connection.ContactService.addWithDupCheck(self.infusionsoftAPIKey, contactData, checktype)
########################################################
## Methods to get meta-data about records
def getCount(self, tableName, query):
return self.connection.DataService.count(self.infusionsoftAPIKey, tableName, query)
def verifyConnection(self):
try:
listOfDicts=self.connection.DataService.query(self.infusionsoftAPIKey, "User", 1000, 0,{},["Email"],"Email",True)
return True
except:
return False
tables={}
# This is a dictionary of the tables accessiable through the API
# It has not been fully sanitized with regards to permissions, so you
# Will likely run into issues where you cannot read something
# but you may be able to write to it, or visa-versa. Basically,
# until you have worked with a specific table a couple of times,
# expect to run into errors.
tables["ActionSequence"] = ["Id", "TemplateName", "VisibleToTheseUsers"]
tables["AffResource"] = ["Id", "Notes", "ProgramIds", "ResourceHREF", "ResourceHTML", "ResourceOrder", "ResourceType", "Title"]
tables["Affiliate"] = ["AffCode", "AffName", "ContactId", "DefCommissionType", "Id", "LeadAmt", "LeadCookieFor", "LeadPercent", "NotifyLead", "NotifySale", "ParentId", "Password", "PayoutType", "SaleAmt", "SalePercent", "Status"]
tables["CCharge"] = ["Amt", "ApprCode", "CCId", "Id", "MerchantId", "OrderNum", "PaymentId", "RefNum"]
tables["CProgram"] = ["Active", "BillingType", "DefaultCycle", "DefaultFrequency", "DefaultPrice", "Description", "Family", "HideInStore", "Id", "LargeImage", "ProductId", "ProgramName", "ShortDescription", "Sku", "Status", "Taxable"]
tables["Campaign"] = ["Id", "Name", "Status"]
tables["CampaignStep"] = ["CampaignId", "Id", "StepStatus", "StepTitle", "TemplateId"]
tables["Campaignee"] = ["Campaign", "CampaignId", "ContactId", "Status"]
tables["Company"] = ["AccountId", "Address1Type", "Address2Street1", "Address2Street2", "Address2Type", "Address3Street1", "Address3Street2", "Address3Type", "Anniversary", "AssistantName", "AssistantPhone", "BillingInformation", "Birthday", "City", "City2", "City3", "Company", "CompanyID", "ContactNotes", "ContactType", "Country", "Country2", "Country3", "CreatedBy", "DateCreated", "Email", "EmailAddress2", "EmailAddress3", "Fax1", "Fax1Type", "Fax2", "Fax2Type", "FirstName", "Groups", "Id", "JobTitle", "LastName", "LastUpdated", "LastUpdatedBy", "MiddleName", "Nickname", "OwnerID", "Password", "Phone1", "Phone1Ext", "Phone1Type", "Phone2", "Phone2Ext", "Phone2Type", "Phone3", "Phone3Ext", "Phone3Type", "Phone4", "Phone4Ext", "Phone4Type", "Phone5", "Phone5Ext", "Phone5Type", "PostalCode", "PostalCode2", "PostalCode3", "ReferralCode", "SpouseName", "State", "State2", "State3", "StreetAddress1", "StreetAddress2", "Suffix", "Title", "Username", "Validated", "Website", "ZipFour1", "ZipFour2", "ZipFour3"]
tables["Contact"] = ["AccountId", "Address1Type", "Address2Street1", "Address2Street2", "Address2Type", "Address3Street1", "Address3Street2", "Address3Type", "Anniversary", "AssistantName", "AssistantPhone", "BillingInformation", "Birthday", "City", "City2", "City3", "Company", "CompanyID", "ContactNotes", "ContactType", "Country", "Country2", "Country3", "CreatedBy", "DateCreated", "Email", "EmailAddress2", "EmailAddress3", "Fax1", "Fax1Type", "Fax2", "Fax2Type", "FirstName", "Groups", "Id", "JobTitle", "LastName", "LastUpdated", "LastUpdatedBy", "LeadSourceId", "Leadsource", "MiddleName", "Nickname", "OwnerID", "Password", "Phone1", "Phone1Ext", "Phone1Type", "Phone2", "Phone2Ext", "Phone2Type", "Phone3", "Phone3Ext", "Phone3Type", "Phone4", "Phone4Ext", "Phone4Type", "Phone5", "Phone5Ext", "Phone5Type", "PostalCode", "PostalCode2", "PostalCode3", "ReferralCode", "SpouseName", "State", "State2", "State3", "StreetAddress1", "StreetAddress2", "Suffix", "Title", "Username", "Validated", "Website", "ZipFour1", "ZipFour2", "ZipFour3"]
tables["ContactAction"] = ["Accepted", "ActionDate", "ActionDescription", "ActionType", "CompletionDate", "ContactId", "CreatedBy", "CreationDate", "CreationNotes", "EndDate", "Id", "IsAppointment", "LastUpdated", "LastUpdatedBy", "ObjectType", "OpportunityId", "PopupDate", "Priority", "UserID"]
tables["ContactGroup"] = ["GroupCategoryId", "GroupDescription", "GroupName", "Id"]
tables["ContactGroupAssign"] = ["Contact.Address1Type", "Contact.Address2Street1", "Contact.Address2Street2", "Contact.Address2Type", "Contact.Address3Street1", "Contact.Address3Street2", "Contact.Address3Type", "Contact.Anniversary", "Contact.AssistantName", "Contact.AssistantPhone", "Contact.BillingInformation", "Contact.Birthday", "Contact.City", "Contact.City2", "Contact.City3", "Contact.Company", "Contact.CompanyID", "Contact.ContactNotes", "Contact.ContactType", "Contact.Country", "Contact.Country2", "Contact.Country3", "Contact.CreatedBy", "Contact.DateCreated", "Contact.Email", "Contact.EmailAddress2", "Contact.EmailAddress3", "Contact.Fax1", "Contact.Fax1Type", "Contact.Fax2", "Contact.Fax2Type", "Contact.FirstName", "Contact.Groups", "Contact.Id", "Contact.JobTitle", "Contact.LastName", "Contact.LastUpdated", "Contact.LastUpdatedBy", "Contact.Leadsource", "Contact.MiddleName", "Contact.Nickname", "Contact.OwnerID", "Contact.Phone1", "Contact.Phone1Ext", "Contact.Phone1Type", "Contact.Phone2", "Contact.Phone2Ext", "Contact.Phone2Type", "Contact.Phone3", "Contact.Phone3Ext", "Contact.Phone3Type", "Contact.Phone4", "Contact.Phone4Ext", "Contact.Phone4Type", "Contact.Phone5", "Contact.Phone5Ext", "Contact.Phone5Type", "Contact.PostalCode", "Contact.PostalCode2", "Contact.PostalCode3", "Contact.ReferralCode", "Contact.SpouseName", "Contact.State", "Contact.State2", "Contact.State3", "Contact.StreetAddress1", "Contact.StreetAddress2", "Contact.Suffix", "Contact.Title", "Contact.Website", "Contact.ZipFour1", "Contact.ZipFour2", "Contact.ZipFour3", "ContactGroup", "ContactId", "DateCreated", "GroupId"]
tables["ContactGroupCategory"] = ["CategoryDescription", "CategoryName", "Id"]
tables["CreditCard"] = ["BillAddress1", "BillAddress2", "BillCity", "BillCountry", "BillName", "BillState", "BillZip", "CardType", "ContactId", "Email", "ExpirationMonth", "ExpirationYear", "FirstName", "Id", "Last4", "LastName", "MaestroIssueNumber", "NameOnCard", "PhoneNumber", "ShipAddress1", "ShipAddress2", "ShipCity", "ShipCompanyName", "ShipCountry", "ShipFirstName", "ShipLastName", "ShipMiddleName", "ShipName", "ShipPhoneNumber", "ShipState", "ShipZip", "StartDateMonth", "StartDateYear", "Status"]
tables["DataFormField"] = ["DataType", "DefaultValue", "FormId", "GroupId", "Id", "Label", "ListRows", "Name", "Values"]
tables["DataFormGroup"] = ["Id", "Name", "TabId"]
tables["DataFormTab"] = ["FormId", "Id", "TabName"]
tables["Expense"] = ["ContactId", "DateIncurred", "ExpenseAmt", "ExpenseType", "Id", "TypeId"]
tables["FileBox"] = ["ContactId", "Extension", "FileName", "FileSize", "Id", "Public"]
tables["GroupAssign"] = ["Admin", "GroupId", "Id", "UserId"]
tables["Invoice"] = ["AffiliateId", "ContactId", "CreditStatus", "DateCreated", "Description", "Id", "InvoiceTotal", "InvoiceType", "JobId", "LeadAffiliateId", "PayPlanStatus", "PayStatus", "ProductSold", "PromoCode", "RefundStatus", "Synced", "TotalDue", "TotalPaid"]
tables["InvoiceItem"] = ["CommissionStatus", "DateCreated", "Description", "Discount", "Id", "InvoiceAmt", "InvoiceId", "OrderItemId"]
tables["InvoicePayment"] = ["Amt", "Id", "InvoiceId", "PayDate", "PayStatus", "PaymentId", "SkipCommission"]
tables["Job"] = ["ContactId", "DateCreated", "DueDate", "Id", "JobNotes", "JobRecurringId", "JobStatus", "JobTitle", "OrderStatus", "OrderType", "ProductId", "ShipCity", "ShipCompany", "ShipCountry", "ShipFirstName", "ShipLastName", "ShipMiddleName", "ShipPhone", "ShipState", "ShipStreet1", "ShipStreet2", "ShipZip", "StartDate"]
tables["JobRecurringInstance"] = ["AutoCharge", "DateCreated", "Description", "EndDate", "Id", "InvoiceItemId", "RecurringId", "StartDate", "Status"]
tables["Lead"] = ["AffiliateId", "ContactID", "CreatedBy", "DateCreated", "EstimatedCloseDate", "Id", "LastUpdated", "LastUpdatedBy", "Leadsource", "NextActionDate", "NextActionNotes", "Objection", "OpportunityNotes", "OpportunityTitle", "ProjectedRevenueHigh", "ProjectedRevenueLow", "StageID", "StatusID", "UserID"]
tables["LeadSource"] = ["CostPerLead", "Description", "EndDate", "Id", "LeadSourceCategoryId", "Medium", "Message", "Name", "StartDate", "Status", "Vendor"]
tables["LeadSourceCategory"] = ["Description", "Id", "Name"]
tables["LeadSourceExpense"] = ["Amount", "DateIncurred", "Id", "LeadSourceId", "LeadSourceRecurringExpenseId", "Notes", "Title"]
tables["LeadSourceRecurringExpense"] = ["Amount", "EndDate", "Id", "LeadSourceId", "NextExpenseDate", "Notes", "StartDate", "Title"]
tables["MtgLead"] = ["ActualCloseDate", "ApplicationDate", "CreditReportDate", "DateAppraisalDone", "DateAppraisalOrdered", "DateAppraisalReceived", "DateRateLockExpires", "DateRateLocked", "DateTitleOrdered", "DateTitleReceived", "FundingDate", "Id"]
tables["OrderItem"] = ["CPU", "Id", "ItemDescription", "ItemName", "ItemType", "Notes", "OrderId", "PPU", "ProductId", "Qty", "SubscriptionPlanId"]
tables["PayPlan"] = ["AmtDue", "DateDue", "FirstPayAmt", "Id", "InitDate", "InvoiceId", "StartDate", "Type"]
tables["PayPlanItem"] = ["AmtDue", "AmtPaid", "DateDue", "Id", "PayPlanId", "Status"]
tables["Payment"] = ["ChargeId", "Commission", "ContactId", "Id", "InvoiceId", "PayAmt", "PayDate", "PayNote", "PayType", "RefundId", "Synced", "UserId"]
tables["Product"] = ["BottomHTML", "CityTaxable", "CountryTaxable", "Description", "HideInStore", "Id", "InventoryLimit", "InventoryNotifiee", "IsPackage", "LargeImage", "NeedsDigitalDelivery", "ProductName", "ProductPrice", "Shippable", "ShippingTime", "ShortDescription", "Sku", "StateTaxable", "Status", "Taxable", "TopHTML", "Weight"]
tables["ProductCategory"] = ["CategoryDisplayName", "CategoryImage", "CategoryOrder", "Id", "ParentId"]
tables["ProductCategoryAssign"] = ["Id", "ProductCategoryId", "ProductId"]
tables["ProductInterest"] = ["DiscountPercent", "Id", "ObjType", "ObjectId", "ProductId", "ProductType", "Qty"]
tables["ProductInterestBundle"] = ["BundleName", "Description", "Id"]
tables["ProductOptValue"] = ["Id", "IsDefault", "Label", "Name", "OptionIndex", "PriceAdjustment", "ProductOptionId", "Sku"]
tables["ProductOption"] = ["AllowSpaces", "CanContain", "CanEndWith", "CanStartWith", "Id", "IsRequired", "Label", "MaxChars", "MinChars", "Name", "OptionType", "Order", "ProductId", "TextMessage"]
tables["RecurringOrder"] = ["AffiliateId", "AutoCharge", "BillingAmt", "BillingCycle", "CC1", "CC2", "ContactId", "EndDate", "Frequency", "Id", "LastBillDate", "LeadAffiliateId", "MaxRetry", "MerchantAccountId", "NextBillDate", "NumDaysBetweenRetry", "OriginatingOrderId", "PaidThruDate", "ProductId", "ProgramId", "PromoCode", "Qty", "ReasonStopped", "ShippingOptionId", "StartDate", "Status", "SubscriptionPlanId"]
tables["RecurringOrderWithContact"] = ["AffiliateId", "AutoCharge", "BillingAmt", "BillingCycle", "CC1", "CC2", "City", "ContactId", "ContactId", "Country", "Email", "EmailAddress2", "EmailAddress3", "EndDate", "FirstName", "Frequency", "LastBillDate", "LastName", "LeadAffiliateId", "MaxRetry", "MerchantAccountId", "MiddleName", "NextBillDate", "Nickname", "NumDaysBetweenRetry", "PaidThruDate", "Phone1", "Phone1Ext", "Phone1Type", "Phone2", "Phone2Ext", "Phone2Type", "PostalCode", "ProductId", "ProgramId", "PromoCode", "Qty", "ReasonStopped", "RecurringOrderId", "ShippingOptionId", "SpouseName", "StartDate", "State", "Status", "StreetAddress1", "StreetAddress2", "SubscriptionPlanId", "Suffix", "Title", "ZipFour1"]
tables["Referral"] = ["AffiliateId", "ContactId", "DateExpires", "DateSet", "IPAddress", "Id", "Info", "Source", "Type"]
tables["SavedFilter"] = ["FilterName", "Id", "ReportStoredName", "UserId"]
tables["Stage"] = ["Id", "StageName", "StageOrder", "TargetNumDays"]
tables["StageMove"] = ["CreatedBy", "DateCreated", "Id", "MoveDate", "MoveFromStage", "MoveToStage", "OpportunityId", "PrevStageMoveDate", "UserId"]
tables["Status"] = ["Id", "StatusName", "StatusOrder", "TargetNumDays"]
tables["SubscriptionPlan"] = ["Active", "Cycle", "Frequency", "Id", "PlanPrice", "PreAuthorizeAmount", "ProductId", "Prorate"]
tables["Template"] = ["Categories", "Id", "PieceTitle", "PieceType"]
tables["TicketStage"] = ["Id", "StageName"]
tables["TicketType"] = ["CategoryId", "Id", "Label"]
tables["User"] = ["City", "Email", "EmailAddress2", "EmailAddress3", "FirstName", "HTMLSignature", "Id", "LastName", "MiddleName", "Nickname", "Phone1", "Phone1Ext", "Phone1Type", "Phone2", "Phone2Ext", "Phone2Type", "PostalCode", "Signature", "SpouseName", "State", "StreetAddress1", "StreetAddress2", "Suffix", "Title", "ZipFour1"]
tables["UserGroup"] = ["Id", "Name", "OwnerId"]