-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathTestContact.java
More file actions
179 lines (133 loc) · 6.19 KB
/
Copy pathTestContact.java
File metadata and controls
179 lines (133 loc) · 6.19 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package com.test;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;
import com.agilecrm.api.APIManager;
import com.agilecrm.api.ContactAPI;
import com.agilecrm.stubs.Contact;
import com.agilecrm.stubs.Contact.Type;
import com.agilecrm.stubs.ContactField.FieldName;
import com.agilecrm.stubs.Tag;
/**
* <code>TestContact</code> class contains main method to test all the methods
* in <code>ContactAPI</code> class
*
* @author Ghanshyam
* @since July 2016
* @see ContactAPI
*
*/
public class TestContact
{
public static void main(String[] args)
{
try
{
String baseUrl = "https://ghanshyam.agilecrm.com/dev";
String userEmail = "ghanshyam.raut@agilecrm.com";
String restAPIKey = "***************************";
// Create a connection to Agile CRM
APIManager apiManager = new APIManager(baseUrl, userEmail, restAPIKey);
ContactAPI contactApi = apiManager.getContactAPI();
// List of tags to add it to contact
List<String> tags;
// -------------------- Adding a company --------------------------
Contact company = new Contact();
company.setType(Type.COMPANY);
company.setContactField(FieldName.COMPANY, "ClickDesk");
company.setContactField(FieldName.URL, "https://www.clickdesk.com");
tags = new ArrayList<String>();
tags.add("Product based");
tags.add("Service based");
company.setTags(tags);
//company = contactApi.addContact(company);
System.out.println("Added company... " + company);
// -------------------- Adding a company end ------------------------
// ------------------- Adding a person ----------------------------
Contact person1 = new Contact();
person1.setType(Type.PERSON);
person1.setLead_score(3);
person1.setContactField(FieldName.FIRST_NAME, "Annie");
person1.setContactField(FieldName.LAST_NAME, "Besant");
person1.setContactField(FieldName.ORGANIZATION, "London School Board");
person1.setContactField(FieldName.EMAIL, "annie@henry.com");
person1.setContactField(FieldName.TITLE, "socialist");
person1.setContactField(FieldName.PHONE, "+48624981");
person1.setContactField(FieldName.WEBSITE,
"http://agile-crm-cloud.appspot.com");
JSONObject address = new JSONObject();
address.put("city", "Clapham");
address.put("state", "London");
address.put("country", "United Kingdom");
person1.setContactField(FieldName.ADDRESS, address.toString());
person1.setCustomField("Date Of Joining", "Test Add Custom Field");
tags = new ArrayList<String>();
tags.add("developer");
tags.add("subscribe");
tags.add("connection");
person1.setTags(tags);
//person1 = contactApi.addContact(person1);
System.out.println("Added person... " + person1);
// ------------------- Adding a person end--------------------------
// ------------------- Update Contact properties ---------------------
String contactDeailJson = "{\"id\":5698246273925120, "
+ "\"properties\":[{\"type\":\"SYSTEM\", \"name\":\"email\",\"value\":\"jason123@gmail.com\"},"
+ " {\"type\":\"SYSTEM\", \"name\":\"first_name\", \"value\":\"Jason\"}, "
+ " {\"type\":\"SYSTEM\", \"name\":\"website\", \"value\":\"https://github.com/agilecrm/rest-api\"},"
+ " {\"type\":\"SYSTEM\", \"name\":\"address\", \"value\":'{\"address\":\"225 George Street\",\"city\":\"NSW\",\"state\":\"Sydney\",\"zip\":\"2000\",\"country\":\"Australia\"}'},"
+ "{\"type\":\"SYSTEM\", \"name\":\"phone\", \"value\":\"918888888888\"}]}";
contactApi.updateContactPartialUpdate(contactDeailJson);
// ------------------- Update Contact properties end -----------------
// --------------------- Get contacts -----------------------------
JSONArray contacts = contactApi.getContacts("10","first_page");;
System.out.println("All contacts.." + contacts);
// ----------------- Get contact by contact id --------------------
Contact contact = new Contact();
contact = contactApi.getContact(String.valueOf("5755821854031872"));
System.out.println("Got contact by id... " + contact);
// ---------------- Get contact from email ------------------------
Contact contact1 = contactApi.getContactFromEmail("annie@henry.com");
System.out.println("Got contact by email... " + contact1);
// ------------ Adding tag to contact based on email -------------
Tag tag = new Tag();
tags = new ArrayList<String>();
tags.add("alfa1");
tags.add("alfa2");
tags.add("alfa3");
tag.setTags(tags);
contactApi.addTagsToEmail(tag, "mark@henry.com");
System.out.println("Added tag based on email..............");
// ---- Adding tags to contact based on contact id ---------------
String TagsJson = "{\"id\":\"5750240208486400\",\"tags\":[\"tag1\", \"tag2\"]}";
contactApi.addTagsByContactId(TagsJson);
System.out.println("Added tag based on contact id..............");
// ---------Delete tags to contact based on email ------------------
Tag tag1 = new Tag();
tags = new ArrayList<String>();
tags.add("alfa2");
tags.add("alfa4");
tag1.setTags(tags);
contactApi.deleteTags(tag1, "mark@henry.com");
System.out.println("Delete tag based on email..............");
// ------------ delete contact by contact id --------------------
contactApi.deleteContact("5170081277411328");
// ------------- delete bulk contacts ------------------------
List<String> contactIds;
contactIds = new ArrayList<String>();
contactIds.add("5655368558444544");
contactIds.add("5769320147714048");
contactApi.deleteBulkContacts(contactIds);
// ---------Add Score to a Contact using Email-ID------------------
contactApi.addScoreToEmail("5", "mark@henry.com");
System.out.println("Addedd score based on email..............");
// ---------Get contacts by custom field------------------
contactApi.getContactsByDynamicFilter("tags","Lead","5","first_page");
}
catch (Exception e)
{
System.out.println("message" + e.getMessage());
e.printStackTrace();
}
}
}