Forum Discussion
ChadC
7 years agoFrequent Visitor
Check if JSON Attribute Exists
Hi, I'm working with a paginated API. The initial fetch will return a JSON payload like: {
"data": [
...
],
"links": {
"next": "https://api.outreach.io/api/v2/prospects?page[lim...
- 7 years ago
I'd try to use
try ... otherwise ...
syntax to catch errors, see more here
https://blog.gbrueckl.at/2013/12/error-handling-in-power-query/
Stachu
7 years agoCommunity Champion
I'd try to use
try ... otherwise ...
syntax to catch errors, see more here
https://blog.gbrueckl.at/2013/12/error-handling-in-power-query/
- ChadC7 years agoFrequent Visitor
Thanks Stachu , that was what I was looking for!
Updated function:
GetPage = (Index as number, Scope as text, Offset as number) => let // Calculate the offset. _offset = Number.ToText(Index * LimitPerPage + Offset), // Try to fetch a JSON payload. If an error occurs, return a JSON document with an empty "data" attribute. JSON = try GetJSON(api_source_uri & Scope & "?page[limit]=" & strLimitPerPage & "&page[offset]=" & _offset) otherwise Json.Document("{""data"": []}"), // Get the ""data"" attribute of the JSON document. Page = JSON[data] in Page;