Ecological Data Services, LLC
Data Engineering and Analytics Consulting

iNaturalist Observations - PowerBI - API Paging

In order to get the full API results we need to make multiple calls to the API passing a page parameter. This article provides a good discussion of importing API results for page-limited APIs:

To get all of the data from the observations api:

1. Modify the original observations query to make it a function query that accepts a page number parameter

2. Create a new query that returns a list of page numbers for the full set of results

3. Use Invoke Function column operation to call the api for each page

Here are the details:

1. Convert original api query to a function query with a page parameter:

(page as text) as table=>
let
    Source = Json.Document(Web.Contents("https://api.inaturalist.org/v1/observations
        ?taxon_id=42391&per_page=200&order=desc&order_by=created_at&page=" & (page))),

... [additional power query transformation steps to expand and select desired columns]

2. Create a new query that returns a list of page numbers expected from the api method:

let
    Source = Json.Document(Web.Contents("https://api.inaturalist.org/v1/observations
        ?taxon_id=42391&per_page=200&order=desc&order_by=created_at&only_id=true")),

    //calculate number of pages in  total_results and convert to a table of page values
    pages = Number.Round(Source[ total_results] / Source[ per_page],0),
    pageList = {1..pages},
    pageTable = Table.FromList(pageList, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    pageTable_renamed = Table.RenameColumns(pageTable,{{"Column1", "page"}}),
    pageTable_final = Table.TransformColumnTypes(pageTable_renamed,{{"page",type text}})
in
    pageTable_final

This produces a simple table of numbers:

query results
/images/Data%20Visualization%20at%20the%20USDA/CDL_Cropscape.jpg

3. From here we can use Invoke Custom Function in the designer and select the function query from Step 1.

invoke custom function

Now we have all of the api data from the iNaturalist observations api in one Power BI table.


iNaturalist Observations by Taxon ID - Power BI - with paging

iNaturalist APIs
iNaturalist Observations - Power BI
Paging REST API results in Power BI

, , — Nov 7, 2024