Help

Save the date! Join us on October 16 for our Product Ops launch event. Register here.

Offset param does not work as expected for POST requests when fetching records

Topic Labels: API
Solved
Jump to Solution
2481 3
cancel
Showing results for 
Search instead for 
Did you mean: 
Collin_Schwante
5 - Automation Enthusiast
5 - Automation Enthusiast

Hey All,

I maintain a fork of one of the R packages for manipulating data in Airtable and have run into some issues while trying to create a function that uses POST to handle extremely long queries or queries with more than 22 fields and the offset values to retrieve a table with more than 100 records. 

See package here: https://github.com/ecohealthalliance/airtabler/tree/master

The function in question is this one: https://github.com/ecohealthalliance/airtabler/blob/master/R/air_post.R

When using POST, the  offset param seems to have no effect. 

The offset ID changes with each request. So if i have 600 records, the first offset id is "itr72y1g3QhvFAKE1/rec9RPMSRlQrWVyum", then the second is l ""itr72y1g3QhvFAKE2/rec9RPMSRlQrWVyum" etc. Only the Offset ID (the bit that starts with `itr`) changes, not the record. By contrast, with GET requests, only the record ID changes.

here is an example of the body of a post request:

 

 

{ "offset": ["itr72y1g3QhvYZw5Y/rec9RPMSRlQrWVyum"], 
"fields[0]": ["1 - Some Longish String of Text"], "fields[1]": ["2 - Some Longish String of Text"], "fields[2]": ["3 - Some Longish String of Text"], "fields[3]": ["4 - Some Longish String of Text"], "fields[4]": ["5 - Some Longish String of Text"], "fields[5]": ["6 - Some Longish String of Text"], "fields[6]": ["7 - Some Longish String of Text"], "fields[7]": ["8 - Some Longish String of Text"], "fields[8]": ["9 - Some Longish String of Text"], "fields[9]": ["10 - Some Longish String of Text"], "fields[10]": ["11 - Some Longish String of Text"], "fields[11]": ["12 - Some Longish String of Text"], "fields[12]": ["13 - Some Longish String of Text"], "fields[13]": ["14 - Some Longish String of Text"], "fields[14]": ["15 - Some Longish String of Text"], "fields[15]": ["16 - Some Longish String of Text"], "fields[16]": ["17 - Some Longish String of Text"], "fields[17]": ["18 - Some Longish String of Text"], "fields[18]": ["19 - Some Longish String of Text"], "fields[19]": ["20 - Some Longish String of Text"], "fields[20]": ["21 - Some Longish String of Text"], "fields[21]": ["22 - Some Longish String of Text"] }

 

 

There is nothing in the List Records API documentation that says POST requests can't be offset. 
https://airtable.com/developers/web/api/list-records#
 

 

 

1 Solution

Accepted Solutions
Collin_Schwante
5 - Automation Enthusiast
5 - Automation Enthusiast

Turns out I misspecified the POST request in R. I needed to encode the request as "raw" set the content type to "JSON". I figured this out by using the Post man - https://www.postman.com/ - api testing application as suggested by the airtable support team. 

See Solution in Thread

3 Replies 3
CarolynHead
4 - Data Explorer
4 - Data Explorer

Hy there i can see your post and i must say

 

  1. HTTP Method: The "offset" parameter is typically used with GET requests to indicate how many records to skip before fetching the next set of records. It's less common to use the "offset" parameter with POST requests, as POST requests are generally used for creating or updating resources.

  2. API Documentation: Check the API documentation for the specific endpoint you're using. The documentation should provide clear guidance on how to use the "offset" parameter and whether it's supported for POST requests.

  3. Pagination: In APIs, pagination is often used to retrieve a large number of records in smaller batches. Instead of using "offset" directly, the API might use a combination of "limit" (number of records per page) and "page" (current page number) parameters. This approach is more common for GET requests.

  4. Verify API Behavior: Double-check the expected behavior of the "offset" parameter in the API documentation. If you're encountering unexpected behavior, it's possible that there might be a mistake in how you're constructing the POST request or handling the response.

Thanks and regards

CarolynHead

Collin_Schwante
5 - Automation Enthusiast
5 - Automation Enthusiast

@CarolynHead Thanks for your reply, there is nothing in the documentation about a difference in behavior between GET and POST. 

https://airtable.com/developers/web/api/list-records

Collin_Schwante
5 - Automation Enthusiast
5 - Automation Enthusiast

Turns out I misspecified the POST request in R. I needed to encode the request as "raw" set the content type to "JSON". I figured this out by using the Post man - https://www.postman.com/ - api testing application as suggested by the airtable support team.