Best pagination strategy?

When you get FA data they are provided page by page…
What is the best strategy to implement a get-all grabbing ?
It seems there is no way to know the total number records in advance.
So I should iterate until the bottom, but parsing the XML or JSON is not so
easy to understand that the result you get is actually the bottom…

Now I iterate N times where I estimate a N big enough to get all my data,
but that’s not the best approach.

Walter

Thank you Harry. Now with this “curl -i” option I can get working.

Walter

Hi Walter,

If a response from the API has enough results to need multiple pages the
headers will include a Link header with links to the next, previous, first
and last pages. For the first page only the next and last links are
included and for the last page only the previous and first pages are
included. Using this you can extract the next page link and iterate through
until there is no next page link and thus you’re on the last page.

If you want to reduce the number of requests you make you can pass in a
per_page parameter to retrieve more results. This defaults to 25 and can be
as high as 100. The documentation for all of this is available at
FreeAgent Developer Dashboard.

Regards,
Harry MillsOn Sat, Jan 5, 2013 at 9:01 AM, Ossowalt wmacorig@gmail.com wrote:

When you get FA data they are provided page by page…
What is the best strategy to implement a get-all grabbing ?
It seems there is no way to know the total number records in advance.
So I should iterate until the bottom, but parsing the XML or JSON is not
so easy to understand that the result you get is actually the bottom…

Now I iterate N times where I estimate a N big enough to get all my data,
but that’s not the best approach.

Walter


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/freeagent_api/-/p494lckhHUQJ.
To post to this group, send email to freeagent_api@googlegroups.com.
To unsubscribe from this group, send email to
freeagent_api+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/freeagent_api?hl=en.

Harry,

I’m using curl command both XML and JSON but I cannot find any reference on
my results about this to the next, previous, first and last page.

The command I use is:

curl “https://api.freeagent.com/v2/timeslips?per_page=100
-H "Authorization: Bearer "
-H “Accept: application/xml”
-H “Content-Type: application/xml”
-X GET >myfile.xml

Or the same with

-H “Accept: application/json”
-H “Content-Type: application/json” \

Could you please how can I get such pagination informatin using a command
line shell approach?
Thank you.

Walter

Hi Walter,

The pagination links are included in the headers. For curl you can view the
headers by passing the -i switch. This produces output in the following
form:

HTTP/1.1 200 OK
Link: https://api.freeagent.com/v2/timeslips?page=0&per_page=100;
rel=‘last’
Etag: “d41d8cd98f00b204e9800998ecf8427e”
Content-Type: application/json; charset=utf-8

In this case I don’t have sufficient timeslips to require an additional
page so only the link to the last page (which is also the current page) is
shown.

Regards,
Harry MillsOn Wed, Jan 9, 2013 at 8:58 PM, Ossowalt wmacorig@gmail.com wrote:

Harry,

I’m using curl command both XML and JSON but I cannot find any reference
on my results about this to the next, previous, first and last page.

The command I use is:

curl “https://api.freeagent.com/v2/timeslips?per_page=100
-H "Authorization: Bearer "
-H “Accept: application/xml”
-H “Content-Type: application/xml”
-X GET >myfile.xml

Or the same with

-H “Accept: application/json”
-H “Content-Type: application/json” \

Could you please how can I get such pagination informatin using a command
line shell approach?
Thank you.

Walter


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To view this discussion on the web visit
https://groups.google.com/d/msg/freeagent_api/-/oBPwI7D5cT0J.

To post to this group, send email to freeagent_api@googlegroups.com.
To unsubscribe from this group, send email to
freeagent_api+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/freeagent_api?hl=en.