From 1c29c2736ff04381c9f33c7bb763845fd4d85c41 Mon Sep 17 00:00:00 2001 From: Jeremiah Marks Date: Thu, 17 Jul 2014 11:50:00 -0700 Subject: [PATCH 1/3] * Updated comment on line 40 to accurately reflect the limit that is being set. \n* Updated page value on line 41 to actually start with the first page rather than the second. --- python/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/api.py b/python/api.py index ee1c60b..11dad89 100644 --- a/python/api.py +++ b/python/api.py @@ -37,8 +37,8 @@ #Fields I want to select fields = ["ContactId", "ContactGroup"]; -limit = 50; #Limit the number of rows that will be returned to 10 -page = 1; #Start with the first page +limit = 50; #Limit the number of rows that will be returned to 50 +page = 0; #Start with the first page #Make the API call results = server.DataService.findByField(key, "ContactGroupAssign", limit, page, "GroupId", groupId, fields); From 867e9c4662abb76eade640e7fdb4e450e08b6907 Mon Sep 17 00:00:00 2001 From: Jeremiah Marks Date: Thu, 17 Jul 2014 13:32:22 -0700 Subject: [PATCH 2/3] Added header information to sample Cleaned up commenting style Grouped sections of code together slightly differently Removed semicolon from end of lines Replaced extranious print statements with \n Updated verbiage from "Group" to "Tag" in variable names and comments Added DateCreated field to the last search Updated comment regarding the search limit so that it accuratly represents the value assigned Updated page value from 1 to 0 so that it will return the first page of results Modified final print statement to include DateCreated field in a meaningful manner --- python/api.py | 96 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 36 deletions(-) diff --git a/python/api.py b/python/api.py index 11dad89..63b3c29 100644 --- a/python/api.py +++ b/python/api.py @@ -1,48 +1,72 @@ -import xmlrpclib - -#Python has built-in support for xml-rpc. All you need to do is add the -#line above. +################################################################################ +### ### +### Sample updated by Jeremiah Marks on 17 July 2014 ### +### ### +### ### +### Sample currently works in Python2.7 ### +### Sample currently does not work in Python 3.4 ### +### ### +### This sample connects to the remote Infusionsoft server, demonstrates the ### +### ability to add a new contact, add a tag to a contact, and find all ### +### contacts with the same tag. ### +### ### +################################################################################ -#Set up the API server variable -server = xmlrpclib.ServerProxy("https://appName.infusionsoft.com:443/api/xmlrpc"); +################################################################################ +######## Import the xml-rpc library ######## +################################################################################ +import xmlrpclib -#The encrypted API key -key = "dcbe038fbdc9c3f0d538b545a1705006"; +################################################################################ +######## Configure variables for your account. ######## +######## Replace "appName" with your appname/subdomain and insert ######## +######## your Encrypted Key from Admin > Settings > Application ######## +################################################################################ +server = xmlrpclib.ServerProxy("https://appName.infusionsoft.com:443/api/xmlrpc") +key = "4a9a88ca89ab126b5fdc368eea0abd2a" -######## PING & ECHO ############# -#This is the easiest api call -print server.DataService.echo("Hello, World"); +################################################################################ +######## ADD CONTACT ######## +######## Set up the contact data we want to add ######## +################################################################################ +contact = {} +contact["FirstName"] = "John" +contact["LastName"] = "Doe" +contact["Email"] = "john@doe.com" +contact["Company"] = "ACME" +################################################################################ +######## Make the call to "DataService.add" method. The ID for the######## +######## newly added record will be returned as the variable "id" ######## +################################################################################ +id = server.DataService.add(key, "Contact", contact) +print "Added contact with id ", id, "\n" -######## ADD CONTACT ############# -#Set up the contact data we want to add -contact = {}; #blank dictionary -contact["FirstName"] = "John"; -contact["LastName"] = "Doe"; -contact["Email"] = "john@doe.com"; -contact["Company"] = "ACME"; +################################################################################ +######## ADD TAG TO CONTACT ######## +######## Note: if you do not have a tag with the id of 269, this ######## +######## will fail. ######## +################################################################################ +tagId = 269 +added = server.ContactService.addToGroup(key, id, tagId) +print "Tag added to contact: ", added, "\n" -#Make the call to "DataService.add" method. The ID for the newly added record will be returned as the variable "id" -id = server.DataService.add(key, "Contact", contact); -print "Added contact with id ", id; -print; +################################################################################ +######## FIND ALL CONTACTS WITH A TAG ######## +######## This search illustrates how to find all contacts that ######## +######## have a particular tag as well as when those tags were ######## +######## applied. ######## +################################################################################ -######## ADD TO GROUP ############# -groupId = 97; -bool = server.ContactService.addToGroup(key, id, groupId); -print "Contact added to group: ", bool; -print; +fields = ["ContactId", "ContactGroup", "DateCreated"] -######## FIND ALL CONTACTS IN GROUP ####### -#Fields I want to select -fields = ["ContactId", "ContactGroup"]; +limit = 50; #Limit the number of rows that will be returned to 50 +page = 0; #Start with the first page -limit = 50; #Limit the number of rows that will be returned to 50 -page = 0; #Start with the first page -#Make the API call -results = server.DataService.findByField(key, "ContactGroupAssign", limit, page, "GroupId", groupId, fields); +results = server.DataService.findByField(key, "ContactGroupAssign", limit, \ + page, "GroupId", tagId, fields) -#Results will be a python list containg dictionaries. Let's loop through each item in the list and examine it for result in results: - print "Found ", result["ContactId"], " was in ", result["ContactGroup"] + print "Found: Contact #%(ID)3d had tag \"%(tagName)s\" applied on %(date)s."\ + %{"ID":result["ContactId"], "tagName":result["ContactGroup"], "date":result["DateCreated"]} \ No newline at end of file From 366feeabb3dd5566af6397fd47091846cb45a218 Mon Sep 17 00:00:00 2001 From: Jeremiah Marks Date: Thu, 17 Jul 2014 13:35:24 -0700 Subject: [PATCH 3/3] Added header information to sample Cleaned up commenting style Grouped sections of code together slightly differently Removed semicolon from end of lines Replaced extranious print statements with \n Updated verbiage from "Group" to "Tag" in variable names and comments Added DateCreated field to the last search Updated comment regarding the search limit so that it accuratly represents the value assigned Updated page value from 1 to 0 so that it will return the first page of results Modified final print statement to include DateCreated field in a meaningful manner --- python/api.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/python/api.py b/python/api.py index 63b3c29..ac8c989 100644 --- a/python/api.py +++ b/python/api.py @@ -52,7 +52,7 @@ print "Tag added to contact: ", added, "\n" ################################################################################ -######## FIND ALL CONTACTS WITH A TAG ######## +######## FIND ALL CONTACTS WITH SPECIFIED TAG ######## ######## This search illustrates how to find all contacts that ######## ######## have a particular tag as well as when those tags were ######## ######## applied. ######## @@ -68,5 +68,4 @@ page, "GroupId", tagId, fields) for result in results: - print "Found: Contact #%(ID)3d had tag \"%(tagName)s\" applied on %(date)s."\ - %{"ID":result["ContactId"], "tagName":result["ContactGroup"], "date":result["DateCreated"]} \ No newline at end of file + print "Found: Contact #%3d had tag \"%s\" applied on %s." %(result["ContactId"], result["ContactGroup"],result["DateCreated"]) \ No newline at end of file