Skip to content

Updated api.py #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 59 additions & 36 deletions python/api.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,71 @@
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"] = "[email protected]"
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"] = "[email protected]";
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 SPECIFIED 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 10
page = 1; #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 #%3d had tag \"%s\" applied on %s." %(result["ContactId"], result["ContactGroup"],result["DateCreated"])