Forum Discussion
REST API Data Source refreshes in Desktop but not in Service
- 3 years ago
Hi All
Many thanks Imke for helping me resolve this. Working code below.
let // Build the URL for the API call #"Header" = Binary.ToText(Text.ToBinary(#"User Email" & ":" & #"API Token")), mainURL = "https://auvikapi.eu1.my.auvik.com/v1/inventory/device/info", startQuery = [#"page[first]" = "50"], /* Description: Fetches one page of data url - URL to fetch data Output Parameter: ret - record consisting of two elements retData - data for current page retNext - URL for next page */ getOnePage = (query) as record => let // Get the specified URL and parse the JSON response devicePage = Json.Document( Web.Contents( mainURL, [ Query = query, Headers = [ #"Authorization" = "Basic " & #"Header", #"content-type" = "application/json" ] ] ) ), // Extract the data and links fields and return it deviceData = try devicePage[data] otherwise null, next = try devicePage[links][next] otherwise null, ret = [retData = deviceData, retNext = next] in ret, // Fetch each page until there are no more pages by following the next link. Append subsequent pages. deviceList = List.Generate( // Fetch the first page () => [ret = getOnePage(startQuery)], // Stop when there is no more data each try [ret][retData] <> null otherwise false, // Get the next page using the next link - numbers in the query parameters must be formatted as text, hence the gymnastics each [ ret = getOnePage( Record.FromTable( Table.TransformColumnTypes( Record.ToTable(Uri.Parts([ret][retNext])[Query]), {{"Value", type text}} ) ) ) ], // Return only the data each [ret][retData] ), Custom1 = deviceList in Custom1
Hi Grant_Reid ,
looks like you are on the right track. Try the changes below.
Your solution didn't use the parameter in the function and therefore the same query has been executed again and again in the List.Generate operation.
- Grant_Reid3 years agoFrequent Visitor
Hi All
Many thanks Imke for helping me resolve this. Working code below.
let // Build the URL for the API call #"Header" = Binary.ToText(Text.ToBinary(#"User Email" & ":" & #"API Token")), mainURL = "https://auvikapi.eu1.my.auvik.com/v1/inventory/device/info", startQuery = [#"page[first]" = "50"], /* Description: Fetches one page of data url - URL to fetch data Output Parameter: ret - record consisting of two elements retData - data for current page retNext - URL for next page */ getOnePage = (query) as record => let // Get the specified URL and parse the JSON response devicePage = Json.Document( Web.Contents( mainURL, [ Query = query, Headers = [ #"Authorization" = "Basic " & #"Header", #"content-type" = "application/json" ] ] ) ), // Extract the data and links fields and return it deviceData = try devicePage[data] otherwise null, next = try devicePage[links][next] otherwise null, ret = [retData = deviceData, retNext = next] in ret, // Fetch each page until there are no more pages by following the next link. Append subsequent pages. deviceList = List.Generate( // Fetch the first page () => [ret = getOnePage(startQuery)], // Stop when there is no more data each try [ret][retData] <> null otherwise false, // Get the next page using the next link - numbers in the query parameters must be formatted as text, hence the gymnastics each [ ret = getOnePage( Record.FromTable( Table.TransformColumnTypes( Record.ToTable(Uri.Parts([ret][retNext])[Query]), {{"Value", type text}} ) ) ) ], // Return only the data each [ret][retData] ), Custom1 = deviceList in Custom1- Anonymous2 years agoNot applicable
Hi,
Thanks for providing the working code, it's helped me out already. Sadly I've been pulling out my hairs on this additional error I'm getting and can't seem to get rid of...
When applying the same corrections and trying to refresh in Power BI Online, I get the following error message: The 'Column1' column does not exist in the rowset. Table: Device Inventory.
When trying to debug this, it seems like the refresh starts failing from the following step onwards:
// Convert the list into a table deviceListTable = Table.FromList(deviceList, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
This is the exact step where your code ends: it renames deviceList to Custom1 and that's it. This gives me the following result in Power BI Desktop:
The first next step is the one above, where a list is converted into a table, and Power BI Desktop automatically names the only column in this new table 'Column1'.
It's this 'Column1' the Power BI Online refresh eventually fails upon.
However, for the table to give the necessary fields and data, this step and quite some other additional steps are needed, as specified in your original post.
Does that mean you haven't applied any subsequent steps to the query after defining the Custom1 step? How did this eventually work for you in the end?
Is there anyone who encountered the same problem already?
Thanks for all feedback!
Kind regards 🙂
nsfe