Forum Discussion
Calling a REST API with two parameters, please help
- 3 years ago
Ok after havign a break for a few hours and coming back to it I think i just worked it out 🙂
= Table.AddColumn(#"Changed Type", "Table", each (List.Generate(()=> [Result = try fCourseEnrollments([id],1) otherwise null, Page=1], each [Result]<>null, each [Result= try fCourseEnrollments([id],[Page]+1) otherwise null, Page=[Page]+1], each [Result]))) - 3 years ago
Sorry n007jl yes that worked fine.
This is essentially saying add one to the page parameter each time until you get back null results.= Table.AddColumn(#"Changed Type", "Table", each (List.Generate(()=> [Result = try fCourseEnrollments([id],1) otherwise null, Page=1], each [Result]<>null, each [Result= try fCourseEnrollments([id],[Page]+1) otherwise null, Page=[Page]+1], each [Result])))However this only works if you API takes page as a parameter.
Which you can see iun the last line of the function here:
= (CourseID as text, Page as number) as table=> let Source = Json.Document(Web.Contents("https://[removed].instructure.com", [RelativePath ="/api/v1/courses/"&(CourseID)&"/enrollments?access_token=[removed]&page="&Number.ToText(Page)])),You can test this by running the API in a browser. So open a browser and go to something like hxxp://[url]/api/[apiname]?access_token=[accesstoken]&page=2
If that doesnt work then your API probably uses a different method to get additional pages. I have hit one now where the link to the next page is sent back in the header of the request. I can not for the life of me figure out how to make that one work.
WayneSingh/Wayne74 , did you actually get it to work. I did what you did but I am only see data from the first page from the invoked function.
Sorry n007jl yes that worked fine.
This is essentially saying add one to the page parameter each time until you get back null results.
= Table.AddColumn(#"Changed Type", "Table", each
(List.Generate(()=> [Result = try fCourseEnrollments([id],1) otherwise null, Page=1], each [Result]<>null, each [Result= try fCourseEnrollments([id],[Page]+1) otherwise null, Page=[Page]+1], each [Result])))However this only works if you API takes page as a parameter.
Which you can see iun the last line of the function here:
= (CourseID as text, Page as number) as table=>
let
Source = Json.Document(Web.Contents("https://[removed].instructure.com",
[RelativePath ="/api/v1/courses/"&(CourseID)&"/enrollments?access_token=[removed]&page="&Number.ToText(Page)])),
You can test this by running the API in a browser. So open a browser and go to something like hxxp://[url]/api/[apiname]?access_token=[accesstoken]&page=2
If that doesnt work then your API probably uses a different method to get additional pages. I have hit one now where the link to the next page is sent back in the header of the request. I can not for the life of me figure out how to make that one work.