AnsweredAssumed Answered

next_offset seems incorrect

Question asked by MrWhammy MrWhammy on Sep 22, 2015
Latest reply on Sep 22, 2015 by
I use the rest API to retrieve multiple records, using GET /:module

When retrieving multiple records, I keep retrieving until next_records is -1 or I retrieve 0 records.

According to the documentation and the sample response, next_records should be -1 if there are no more records to retrieve.

However, when I retrieve multiple records, the next_records always seems to be offset + max_num.

For instance, when I retrieve all users from my instance (there are 6 users)
REQ: GET /sugar/rest/v10/Users?fields=...
RES: {"next_offset":20,"records":[ ...6 records... ]}

REQ: GET /sugar/rest/v10/Users?fields=...&offset=20
RES: {"next_offset":40,"records":[]}

This isn't really a problem for the retrieve all, however, when I try to do the same using a filter

REQ: POST /sugar/rest/v10/Users/filter?fields=...
RES: {"next_offset":20,"records":[ ...6 records... ]}

REQ: POST /sugar/rest/v10/Users/filter?fields=...&offset=20
RES: {"error":"missing_parameter","error_message":"Missing username"}

My filter does not seem to work, but that might have other causes. What I'm really after is how I should best handle the next_offset. Maybe add a check that assumes that if the resulting number of items is less than the max_num that it is the last result instead of relying on next_offset?