-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathapi.py
More file actions
71 lines (60 loc) · 4.07 KB
/
api.py
File metadata and controls
71 lines (60 loc) · 4.07 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
################################################################################
### ###
### 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. ###
### ###
################################################################################
################################################################################
######## Import the xml-rpc library ########
################################################################################
import xmlrpclib
################################################################################
######## 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"
################################################################################
######## 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 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"
################################################################################
######## 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. ########
################################################################################
fields = ["ContactId", "ContactGroup", "DateCreated"]
limit = 50; #Limit the number of rows that will be returned to 50
page = 0; #Start with the first page
results = server.DataService.findByField(key, "ContactGroupAssign", limit, \
page, "GroupId", tagId, fields)
for result in results:
print "Found: Contact #%3d had tag \"%s\" applied on %s." %(result["ContactId"], result["ContactGroup"],result["DateCreated"])