Forum Discussion
Canvas LMS pagingation problem
- 1 year ago
I found another thread on this forum with similar problem.
Solved: Retrieving headers from API response using Value.M...
The Power Query Web.Contents() function only returns a subset of the header which does include the Link field 😞
Hi,gancw1 .I am glad to help you.
According to the error message
“We were unable to convert a binary type value to a record type”, the problem may be in the GetNextPageUrl function!
You may need to check your data types!
Perhaps the Value.Metadata Function can help you:
Value.Metadata - Power BI Online Training
below is my suggestions:
Checking the Return Value of Web.Contents: Make sure that the response returned by Web.Contents is in the format you expect. You can check the contents of Web.Contents by outputting its results while debugging. For example:
Response = Web.Contents(url, [
Headers = [
Authorization = "Bearer " & ApiToken
]
]),
ResponseJson = try Json.Document(Response) otherwise null
2. Try to modify your original code (please make a backup of your original code before modification to avoid data loss)
GetAllPages = (url as text) as table =>
let
InitialPage = GetPage(url),
FetchPages = List.Generate(
() => [CurrentUrl = url, CurrentPage = InitialPage],
each [CurrentUrl] <> null,
each [
Response = Web.Contents([CurrentUrl]),
ResponseHeaders = Value.Metadata(Response),
CurrentUrl = GetNextPageUrl(ResponseHeaders),
CurrentPage = if [CurrentUrl] <> null then GetPage([CurrentUrl]) else null
],
each [CurrentPage]
),
AllPages = Table.Combine(FetchPages)
in
AllPages
The modified code adds the following section:
ResponseHeaders = Value.Metadata(Response),
Convert the result of Web.Contents to a record type and pass it to the GetNextPageUrl function.
I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks