Power Query and the Kobo Toolbox API: Using Web.Contents() to filter data returned to Excel

The NGO I am working for has a need to connect their Project Managers to Kobo Needs Assessment Survey data directly through Excel. This is easy enough. However, this Survey contains thousands of submissions/data rows and the time taken to refresh the connection is too long as each row must be downloaded to Excel before being filtered.

The KOBO Rest API does allow for queries to filter requests https://kc.humanitarianresponse.info/api/v1/datadholki and I have achieved the desired results in POSTMAN.

I understand it is possible to use the Advanced Editor in Power Query with the Web.Contents() function to filter and achieve the desired effect, however I have thus far failed in writing the correct syntax. Could anybody have a look and tell me what I’m doing wrong?

The query that works correctly in POSTMAN (when using a Header/Authorization token):

https://kc.humanitarianresponse.info/api/v1/data/814220?query={"$and": [{"assessor_details/date_of_assessment": {"$gte": "2021-08-01"}},{"assessor_details/date_of_assessment": {"$lt": "2021-09-01"}}] }

The Power Query Advanced Editor Syntax that doesn’t cause an error, but doesn’t actually filter anything!:

let
Source = Json.Document(Web.Contents("https://kc.humanitarianresponse.info/api/v1/data/814220",[Query="{“”$and“”: [{“”assessor_details/date_of_assessment“”: {“”$gte“”: “”2021-08-01“”}},{“”assessor_details/date_of_assessment“”: {“”$lt“”: “”2021-09-01“”}}] }",Headers=[Authorization="token XXXXXXX"]])),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error)
in
    #"Converted to Table"

Welcome to the community, @anaina342! Would you mind trying the v2 to see if should help:

1 Like