Step 1) Find the id
of the contact you are interested in
Step 2) Retrieve the set Click
Events for that contact
Here is the sample code retrieve the contact by email address using the Contacts Resource, Querying the Contacts Collection.
Header locationHeader;
// URL to get all of the "sends" events for contact id 32 (John's Contact ID)
GetMethod httpGet = new GetMethod(
"https://api.constantcontact.com/ws/customers/joesflowers/contacts?email=jflowers@mail.com");
try {
int status = httpClient.executeMethod(httpGet);
if (status >= 400){
throw new RuntimeException("HTTP request failed with status: " + httpGet.getStatusText() + ". message: " + httpGet.getStatusLine());
}
//response XML can be parsed using parser of choice.
System.out.println(httpGet.getResponseBodyAsString());
} catch (Exception ex) {
throw new RuntimeException(
"Caught exception while GETting "
+ httpGet.getURI(),
ex);
} finally {
// release any connection resources used by the method
httpGet.releaseConnection();
}
The response body will look something like this:
<?xml version='1.0' encoding='UTF-8'?> <feed xmlns="http://www.w3.org/2005/Atom"> <id>< a style="text-decoration: none;" onclick="return false" onmouseover="return false" rel="nofollow" target="_blank" onfocus="return false">< a style="text-decoration: none;" onclick="return false" onmouseover="return false" rel="nofollow" target="_blank" onfocus="return false">http://api.constantcontact.com/ws/customers/joesflowers/contacts</id> <title type="text">Contacts for Customer: joesflowers</title> <link href="http://api.constantcontact.com/ws/customers/joesflowers/contacts" /> <link href="http://api.constantcontact.com/ws/customers/joesflowers/contacts" rel="self" /> <author> <name>joesflowers</name> </author> <updated>2008-10-16T13:43:52.342Z</updated> <link href="/ws/customers/joesflowers/contacts" rel="first" /> <link href="/ws/customers/joesflowers/contacts" rel="current" /> <entry> <link href="/ws/customers/joesflowers/contacts/32" rel="edit" /> <id>< a style="text-decoration: none;" onclick="return false" onmouseover="return false" rel="nofollow" target="_blank" onfocus="return false">< a style="text-decoration: none;" onclick="return false" onmouseover="return false" rel="nofollow" target="_blank" onfocus="return false">http://api.constantcontact.com/ws/customers/joesflowers/contacts/32</id> <title type="text">Contact: jflowers@mail.com</title> <updated>2008-10-16T13:43:52.360Z</updated> <author> <name>Constant Contact</name> </author> <content type="application/vnd.ctct+xml"> <Contact xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/joesflowers/contacts/32"> <Status>Active</Status> <EmailAddress>jflowers@mail.com</EmailAddress> <EmailType>HTML</EmailType> <Name></Name> <OptInTime>2008-09-09T14:44:14.233Z</OptInTime> <OptInSource>ACTION_BY_CUSTOMER</OptInSource> <Confirmed>false</Confirmed> <InsertTime>2008-09-09T14:44:14.233Z</InsertTime> </Contact> </content> </entry> </feed>
The next step is to retrieve the clicks associated with this contact using the Contact Events Service for this unique Contact Id.
clicks
for that ContactHere is Java sample code to retrieve the clicks
for the Contact
Header locationHeader;
// URL to get all of the "sends" events for contact id 32 (John's Contact ID)
GetMethod httpGet = new GetMethod(
"https://api.constantcontact.com/ws/customers/joesflowers/contacts/32/events/clicks");
try {
int status = httpClient.executeMethod(httpGet);
if (status >= 400){
throw new RuntimeException("HTTP request failed with status: " + httpGet.getStatusText() + ". message: " + httpGet.getStatusLine());
}
//response XML can be parsed using parser of choice.
System.out.println(httpGet.getResponseBodyAsString());
} catch (Exception ex) {
throw new RuntimeException(
"Caught exception while GETting "
+ httpGet.getURI(),
ex);
} finally {
// release any connection resources used by the method
httpGet.releaseConnection();
}
The xml result of the above code would be some thing similar to following.
Below xml shows the format of the response that is being refered. Highlighted URLs are the campaigns in which click happened by the given contact in requested URI.
ID attribute in ClickEvent tag represents unique identifier for every event.
<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns="http://www.w3.org/2005/Atom">
<id>< a style="text-decoration: none;" onclick="return false" onmouseover="return false" rel="nofollow" target="_blank" onfocus="return false">http://api.constantcontact.com/ws/customers/joesflowers/contacts/32/events/clicks</id>
<title type="text">Click Events for Customer: joesflowers, Contact id: 1</title>
<link href="http://api.constantcontact.com/ws/customers/joesflowers/contacts/32/events/clicks" />
<link href="http://api.constantcontact.com/ws/customers/joesflowers/contacts/32/events/clicks" rel="self" />
<author>
<name>joesflowers</name>
</author>
<updated>2008-10-15T18:09:45.070Z</updated>
<link href="/ws/customers/joesflowers/contacts/32/events/clicks" rel="first" />
<link href="/ws/customers/joesflowers/contacts/32/events/clicks" rel="current" />
<entry>
<id>< a style="text-decoration: none;" onclick="return false" onmouseover="return false" rel="nofollow" target="_blank" onfocus="return false">http://api.constantcontact.com/ws/customers/joesflowers/contacts/32/events/clicks/1100537019381,1,12...</id>
<title type="text">Click Event for Customer: joesflowers,
Campaign: http://api.constantcontact.com/ws/customers/joesflowers/campaigns/110053...
</title>
<updated>2008-10-03T18:39:02.910Z</updated>
<author>
<name>Constant Contact</name>
</author>
<content type="application/vnd.ctct+xml">
<ClickEvent xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/joesflowers/contacts/32/events/clicks/1100537019381,1,12...">
<Contact id="http://api.constantcontact.com/ws/customers/joesflowers/contacts/32">
<EmailAddress>jflowers@mail.com</EmailAddress>
<link xmlns="http://www.w3.org/2005/Atom" href="http://api.constantcontact.com/ws/customers/joesflowers/contacts/32" rel="self" />
</Contact>
<Campaign id="http://api.constantcontact.com/ws/customers/joesflowers/campaigns/1100537019381">
<link xmlns="http://www.w3.org/2005/Atom" href="http://api.constantcontact.com/ws/customers/joesflowers/campaigns/1100537019381" rel="self" />
</Campaign>
<EventTime>2008-10-03T18:39:02.910Z</EventTime>
<LinkUrl>< a style="text-decoration: none;" onclick="return false" onmouseover="return false" rel="nofollow" target="_blank" onfocus="return false">http://www.boston.com</LinkUrl>
</ClickEvent>
</content>
</entry>
<entry>
<id>< a style="text-decoration: none;" onclick="return false" onmouseover="return false" rel="nofollow" target="_blank" onfocus="return false">http://api.constantcontact.com/ws/customers/joesflowers/contacts/32/events/clicks/1100536902615,1,12...</id>
<title type="text">
Click Event for Customer: joesflowers, Campaign: http://api.constantcontact.com/ws/customers/joesflowers/campaigns/110053...
</title>
<updated>2008-09-29T17:09:53.887Z</updated>
<author>
<name>Constant Contact</name>
</author>
<content type="application/vnd.ctct+xml">
<ClickEvent xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/joesflowers/contacts/32/events/clicks/1100536902615,1,12...">
<Contact id="http://api.constantcontact.com/ws/customers/joesflowers/contacts/32">
<EmailAddress>jflowers@mail.com</EmailAddress>
<link xmlns="http://www.w3.org/2005/Atom" href="http://api.constantcontact.com/ws/customers/joesflowers/contacts/32" rel="self" />
</Contact>
<Campaign id="http://api.constantcontact.com/ws/customers/joesflowers/campaigns/1100536902615">
<link xmlns="http://www.w3.org/2005/Atom" href="http://api.constantcontact.com/ws/customers/joesflowers/campaigns/1100536902615" rel="self" />
</Campaign>
<EventTime>2008-09-29T17:09:53.887Z</EventTime>
<LinkUrl>< a style="text-decoration: none;" onclick="return false" onmouseover="return false" rel="nofollow" target="_blank" onfocus="return false">http://www.boston.com</LinkUrl>
</ClickEvent>
</content>
</entry>
</feed>
Accessing the set of Email sends, bounces, forwards or unsubscribes can be done in a similar manner.