From 262025542e7be4dfa45a413bf66016035640d5da Mon Sep 17 00:00:00 2001 From: acousticpants Date: Thu, 12 Feb 2015 16:45:33 +1100 Subject: [PATCH 1/4] examples and library ported to python 3 --- example.py | 156 ++++++++++++++++++++-------------------- infusionsoft/library.py | 52 +++++++------- 2 files changed, 104 insertions(+), 104 deletions(-) diff --git a/example.py b/example.py index 7bd1c20..1adf22c 100644 --- a/example.py +++ b/example.py @@ -1,78 +1,78 @@ -from infusionsoft.library import Infusionsoft - -infusionsoft = Infusionsoft('Infusionsoft Account Name', 'API Key Goes Here') - -# Example 1: Add Contact -#---------------------------------------------------------------------------------------- -contact = {'FirstName' : 'John', 'LastName' : 'Doe', 'Email' : 'johndoe@email.com'} -print infusionsoft.ContactService('add', contact) - -# Example 2: Merge two duplicate contacts -#---------------------------------------------------------------------------------------- -contactId = 56 -duplicateContactId = 57 -print infusionsoft.ContactService('merge', contactId, duplicateContactId) - -# Example 3: Query a contact using data service -#---------------------------------------------------------------------------------------- -table = 'Contact' -returnFields = ['Id', 'FirstName'] -query = {'FirstName' : 'John'} -limit = 10 -page = 0 -print infusionsoft.DataService('query', table, limit, page, query, returnFields) - -# Example 4: Return a products inventory using product service -#---------------------------------------------------------------------------------------- -productId = 1 -print infusionsoft.ProductService('getInventory', productId) - -# Example 5: Charge an invoice using the invoice service -#---------------------------------------------------------------------------------------- -invoiceId = 16 -notes = 'API Upsell Payment' -creditCardId = 2 -merchantAccountId = 1 -bypassCommissions = False -print infusionsoft.InvoiceService('chargeInvoice', invoiceId, notes, creditCardId, merchantAccountId, bypassCommissions) - -# Example 6: Send an email using the email service -#---------------------------------------------------------------------------------------- -contactList = [123, 456, 789] -fromAddress = 'john@test.com' -toAddress = '~Contact.Email~' -ccAddress = '' -bccAddress = '' -contentType = 'Text' -subject = 'This is just a test email, relax!' -htmlBody = '' -textBody = 'This is the contant for the email' -print infusionsoft.APIEmailService('sendEmail', contactList, fromAddress, toAddress, ccAddress, bccAddress, contentType, subject, htmlBody, textBody) - -# Example 7: Get all report columns using the search service -#---------------------------------------------------------------------------------------- -savedSearchId = 3 -userId = 1 -print infusionsoft.SearchService('getAllReportColumns', savedSearchId, userId) - -# Example 8: Get all shipping options with the shipping service -#---------------------------------------------------------------------------------------- -print infusionsoft.ShippingService('getAllShippingOptions') - -# Example 9: Get affiliate payouts info using filter with the affiliate service -#---------------------------------------------------------------------------------------- -from datetime import datetime -affiliateId = 2 -filterStartDate = datetime(2012, 10, 18) -filterEndDate = datetime(2012, 10, 23) -print infusionsoft.APIAffiliateService('affPayouts', affiliateId, filterStartDate, filterEndDate) - -# Example 10: Get the download URL of a particular file -#---------------------------------------------------------------------------------------- -fileId = 23 -print infusionsoft.FileService('getDownloadUrl', fileId) - -# Example 11: Using the library server method to access the API : Create a contact -#---------------------------------------------------------------------------------------- -contact = {'FirstName' : 'John', 'LastName' : 'Doe', 'Email' : 'johndoe@email.com'} -print infusionsoft.server().ContactService.add(infusionsoft.key, contact) +from infusionsoft.library import Infusionsoft + +infusionsoft = Infusionsoft('Infusionsoft Account Name', 'API Key Goes Here') + +# Example 1: Add Contact +#---------------------------------------------------------------------------------------- +contact = {'FirstName' : 'John', 'LastName' : 'Doe', 'Email' : 'johndoe@email.com'} +print(infusionsoft.ContactService('add', contact)) + +# Example 2: Merge two duplicate contacts +#---------------------------------------------------------------------------------------- +contactId = 56 +duplicateContactId = 57 +print(infusionsoft.ContactService('merge', contactId, duplicateContactId)) + +# Example 3: Query a contact using data service +#---------------------------------------------------------------------------------------- +table = 'Contact' +returnFields = ['Id', 'FirstName'] +query = {'FirstName' : 'John'} +limit = 10 +page = 0 +print(infusionsoft.DataService('query', table, limit, page, query, returnFields)) + +# Example 4: Return a products inventory using product service +#---------------------------------------------------------------------------------------- +productId = 1 +print(infusionsoft.ProductService('getInventory', productId)) + +# Example 5: Charge an invoice using the invoice service +#---------------------------------------------------------------------------------------- +invoiceId = 16 +notes = 'API Upsell Payment' +creditCardId = 2 +merchantAccountId = 1 +bypassCommissions = False +print(infusionsoft.InvoiceService('chargeInvoice', invoiceId, notes, creditCardId, merchantAccountId, bypassCommissions)) + +# Example 6: Send an email using the email service +#---------------------------------------------------------------------------------------- +contactList = [123, 456, 789] +fromAddress = 'john@test.com' +toAddress = '~Contact.Email~' +ccAddress = '' +bccAddress = '' +contentType = 'Text' +subject = 'This is just a test email, relax!' +htmlBody = '' +textBody = 'This is the contant for the email' +print(infusionsoft.APIEmailService('sendEmail', contactList, fromAddress, toAddress, ccAddress, bccAddress, contentType, subject, htmlBody, textBody)) + +# Example 7: Get all report columns using the search service +#---------------------------------------------------------------------------------------- +savedSearchId = 3 +userId = 1 +print(infusionsoft.SearchService('getAllReportColumns', savedSearchId, userId)) + +# Example 8: Get all shipping options with the shipping service +#---------------------------------------------------------------------------------------- +print(infusionsoft.ShippingService('getAllShippingOptions')) + +# Example 9: Get affiliate payouts info using filter with the affiliate service +#---------------------------------------------------------------------------------------- +from datetime import datetime +affiliateId = 2 +filterStartDate = datetime(2012, 10, 18) +filterEndDate = datetime(2012, 10, 23) +print(infusionsoft.APIAffiliateService('affPayouts', affiliateId, filterStartDate, filterEndDate)) + +# Example 10: Get the download URL of a particular file +#---------------------------------------------------------------------------------------- +fileId = 23 +print(infusionsoft.FileService('getDownloadUrl', fileId)) + +# Example 11: Using the library server method to access the API : Create a contact +#---------------------------------------------------------------------------------------- +contact = {'FirstName' : 'John', 'LastName' : 'Doe', 'Email' : 'johndoe@email.com'} +print(infusionsoft.server().ContactService.add(infusionsoft.key, contact)) diff --git a/infusionsoft/library.py b/infusionsoft/library.py index 9dfb5ee..4771a8a 100644 --- a/infusionsoft/library.py +++ b/infusionsoft/library.py @@ -1,27 +1,27 @@ -from xmlrpclib import ServerProxy, Error - -class Infusionsoft: - - def __init__(self, name, api_key): - self.client = ServerProxy("https://" + name + ".infusionsoft.com/api/xmlrpc") - self.client.error = Error - self.key = api_key - - def __getattr__(self, service): - def function(method, *args): - call = getattr(self.client, service + '.' + method) - try: - return call(self.key, *args) - except self.client.error, v: - return "ERROR", v - return function - - def server(self): - return self.client - -class InfusionsoftOAuth(Infusionsoft): - - def __init__(self, access_token): - self.client = ServerProxy("https://api.infusionsoft.com/crm/xmlrpc/v1?access_token=%s" % access_token) - self.client.error = Error +from xmlrpc.client import ServerProxy, Error + +class Infusionsoft: + + def __init__(self, name, api_key): + self.client = ServerProxy("https://" + name + ".infusionsoft.com/api/xmlrpc") + self.client.error = Error + self.key = api_key + + def __getattr__(self, service): + def function(method, *args): + call = getattr(self.client, service + '.' + method) + try: + return call(self.key, *args) + except self.client.error as v: + return "ERROR", v + return function + + def server(self): + return self.client + +class InfusionsoftOAuth(Infusionsoft): + + def __init__(self, access_token): + self.client = ServerProxy("https://api.infusionsoft.com/crm/xmlrpc/v1?access_token=%s" % access_token) + self.client.error = Error self.key = access_token \ No newline at end of file From 259ea53c4195a6de6e9df374615e85f6c01f3f24 Mon Sep 17 00:00:00 2001 From: BMJHayward Date: Tue, 24 Feb 2015 21:21:44 +1100 Subject: [PATCH 2/4] library will try import xmlrpc.client if python3, will import xmlrpclib if python2 --- infusionsoft/library.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/infusionsoft/library.py b/infusionsoft/library.py index 4771a8a..e7812d7 100644 --- a/infusionsoft/library.py +++ b/infusionsoft/library.py @@ -1,4 +1,7 @@ -from xmlrpc.client import ServerProxy, Error +try: + from xmlrpc.client import ServerProxy, Error +except ImportError: + from xmlrpclib import ServerProxy, Error class Infusionsoft: From b67d572621a1d428c975e9c2add9c7c924a1685a Mon Sep 17 00:00:00 2001 From: BMJHayward Date: Fri, 13 Mar 2015 10:52:19 +1100 Subject: [PATCH 3/4] include examples to count contacts with data service --- example.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/example.py b/example.py index 1adf22c..1537675 100644 --- a/example.py +++ b/example.py @@ -76,3 +76,15 @@ #---------------------------------------------------------------------------------------- contact = {'FirstName' : 'John', 'LastName' : 'Doe', 'Email' : 'johndoe@email.com'} print(infusionsoft.server().ContactService.add(infusionsoft.key, contact)) + +# Example 12: Find the total number of contacts using the data service +#---------------------------------------------------------------------------------------- +table = 'Contact' +query = {'AccountId': '%'} +print(infusionsoft.DataService('count', table, query) + +# Example 13: Find the number of contacts for a given lead source with the data service +#---------------------------------------------------------------------------------------- +table = 'Contact' +query = {'Leadsource': 'example leadsource name'} +print(infusionsoft.DataService('count', table, query) From b083e4d3755144d5018a667f90f6ad74c2749c36 Mon Sep 17 00:00:00 2001 From: BMJHayward Date: Fri, 13 Mar 2015 10:56:01 +1100 Subject: [PATCH 4/4] count contacts and leadsource examples --- example.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/example.py b/example.py index 1537675..f7ae816 100644 --- a/example.py +++ b/example.py @@ -77,14 +77,15 @@ contact = {'FirstName' : 'John', 'LastName' : 'Doe', 'Email' : 'johndoe@email.com'} print(infusionsoft.server().ContactService.add(infusionsoft.key, contact)) -# Example 12: Find the total number of contacts using the data service -#---------------------------------------------------------------------------------------- -table = 'Contact' -query = {'AccountId': '%'} -print(infusionsoft.DataService('count', table, query) - -# Example 13: Find the number of contacts for a given lead source with the data service -#---------------------------------------------------------------------------------------- -table = 'Contact' -query = {'Leadsource': 'example leadsource name'} -print(infusionsoft.DataService('count', table, query) +#Example 12: Find the total number of contacts using the data service +---------------------------------------------------------------------------------------- +# table = 'Contact' +# query = {'AccountId': '%'} +# print(infusionsoft.DataService('count', table, query) +# +#Example 13: Find the number of contacts for a given lead source with the data service +---------------------------------------------------------------------------------------- +# table = 'Contact' +# query = {'Leadsource': 'example leadsource name'} +# print(infusionsoft.DataService('count', table, query) +# \ No newline at end of file