pageSize is there, but where's the Offset?

SOLVED
Go to solution
Occasional Participant

pageSize is there, but where's the Offset?

Hi,

 

For paging of results in API calls, you can specify pageSize parameter in the GET requests, but how do I specify window offset. For example, https://mycall?pagesize=200 will return results from 1 to 200, but now how do I ask for the next batch, i.e. results from 201 to 400?

 

Kind Regards,

Shujaat

1 ACCEPTED SOLUTION

Hey Shujaat,

 

The XML that will be returned will be similiar to this. 

 

<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>http://api.constantcontact.com/ws/customers/{username}/campaigns/1107379863433/events/bounces</id>
  <title type="text">Bounce Events for Customer: {username}, Campaign id: 1107379863433</title>
  <link href="bounces"></link>
  <link href="bounces" rel="self"></link>
  <author>
    <name>{username}</name>
  </author>
  <updated>2011-09-20T06:30:43.863Z</updated>
  <link href="/ws/customers/{username}/campaigns/1107379863433/events/bounces?next=554" rel="next"></link>
  <link href="/ws/customers/{username}/campaigns/1107379863433/events/bounces" rel="first"></link>
  <link href="/ws/customers/{username}/campaigns/1107379863433/events/bounces" rel="current"></link>
  <entry>
    <id>http://api.constantcontact.com/ws/customers/{username}/events/bounces/1107379863433,504,1314737910548</id>
    <title type="text">Email Bounce Event for Customer: {username}, Campaign: http://api.constantcontact.com/ws/customers/{username}/campaigns/1107379863433</title>
    <updated>2011-08-30T20:58:30.548Z</updated>
    <author>
      <name>Constant Contact</name>
    </author>
    

This is an example of bounces but the opens will be identical with the exception of minor details in the contact.  But what you are looking for exactly is:

 

<link href="/ws/customers/{username}/campaigns/1107379863433/events/bounces?next=554" rel="next"></link>

That will become your new URI.  You would want to parse your XML to get the results for ex: 

 string xpathNext = @"//at:link[@rel='next']";

 There are other ways but that is what I use.  


Please let me know if this clears everything up.

 

Ryan Davis
Quality Engineer

View solution in original post

4 REPLIES 4
Employee

Hey,

 

The offset is its own URI.  When you do a get to a collection you will get a few different links.  You will see that they are separated by various REL attributes.  They will contain the same URI with a token at the end. 

 

Please let me know if this helps.

Ryan Davis
Quality Engineer
Occasional Participant

Not sure if I understood you correctly. I'm trying to fetch all the "Open" events for a particular campaign by accessing the following web service call:

 

https://api.constantcontact.com/ws/customers/UserName/campaigns/CampaignID/events/opens

 

This call returns an XML feed containing a list of all Open events that I then parse to extract the information I need. So my questions are:

 

1. Will it return ALL open events or just the first 50 (or 200)?

2. If it returns only the first 50 (or 200), how do I access subsequent pages?

 

Kind Regards,

Shujaat

Hey Shujaat,

 

The XML that will be returned will be similiar to this. 

 

<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>http://api.constantcontact.com/ws/customers/{username}/campaigns/1107379863433/events/bounces</id>
  <title type="text">Bounce Events for Customer: {username}, Campaign id: 1107379863433</title>
  <link href="bounces"></link>
  <link href="bounces" rel="self"></link>
  <author>
    <name>{username}</name>
  </author>
  <updated>2011-09-20T06:30:43.863Z</updated>
  <link href="/ws/customers/{username}/campaigns/1107379863433/events/bounces?next=554" rel="next"></link>
  <link href="/ws/customers/{username}/campaigns/1107379863433/events/bounces" rel="first"></link>
  <link href="/ws/customers/{username}/campaigns/1107379863433/events/bounces" rel="current"></link>
  <entry>
    <id>http://api.constantcontact.com/ws/customers/{username}/events/bounces/1107379863433,504,1314737910548</id>
    <title type="text">Email Bounce Event for Customer: {username}, Campaign: http://api.constantcontact.com/ws/customers/{username}/campaigns/1107379863433</title>
    <updated>2011-08-30T20:58:30.548Z</updated>
    <author>
      <name>Constant Contact</name>
    </author>
    

This is an example of bounces but the opens will be identical with the exception of minor details in the contact.  But what you are looking for exactly is:

 

<link href="/ws/customers/{username}/campaigns/1107379863433/events/bounces?next=554" rel="next"></link>

That will become your new URI.  You would want to parse your XML to get the results for ex: 

 string xpathNext = @"//at:link[@rel='next']";

 There are other ways but that is what I use.  


Please let me know if this clears everything up.

 

Ryan Davis
Quality Engineer

View solution in original post

Occasional Participant

Thank you very much Ryan. Your tips were of great value. I'm now able to paginate through the results. I'll get back if I see any other issues.

Developer Portal

View API documentation, code samples, get your API key.

Visit Page