Forum Discussion

ivan_larson_cki's avatar
ivan_larson_cki
Icon for Helper III rankHelper III
7 years ago
Solved

Trouble with Pagnation for Airtable

Airtable will only let an API pull data from 100 records at a time. I've searched around and found a single formula that keeps getting re-posted to circumvent the 100-record limit. I've tried applyin...
  • ivan_larson_cki's avatar
    7 years ago

    Resolved using this code:

     

     Pagination = List.Skip(List.Generate( () => [Last_Key = "init", Counter=0], // Start Value
       		each  [Last_Key] <> null, // Condition under which the next execution will happen
       		each [ Last_Key = try if [Counter]<1 then "" else [WebCall][Value][offset] otherwise null,// determine the LastKey for the next execution
                           WebCall = try if [Counter]<1 then Json.Document(Web.Contents("https://api.airtable.com/v0/<APP_ID>/<TABLE_ID>?api_key=<KEY_ID>")) else Json.Document(Web.Contents("https://api.airtable.com/v0/<APP_ID>/<TABLE_ID>?api_key=<KEY_ID>&offset="&Last_Key)), // retrieve results per call
        		       Counter = [Counter]+1// internal counter
                          ],
       		each [WebCall]
        ),1)

    The issue was not so much the exact phrasing, but rather that after editing the original "Source" code that only pulled 100 records to a Pagination code, I needed to hit "Refresh Preview" so that the full set of paginated data segments appeared. Only then was it possible to tell the query to open all of them. Before that, it was pulling all the data, but just not showing it correctly in the preview, which led to me not knowing to fix the command after the Pagination command.