Forum Discussion

Wayne74's avatar
Wayne74
Icon for Helper I rankHelper I
3 years ago
Solved

Calling a REST API with two parameters, please help

Hi, UPD: I think I worked it out.  Check my reply (yes same person, different account.  I didnt check that first :D). UPD2: Can confirm that worked.   Firstly let me say I am still very new to Po...
  • WayneSingh's avatar
    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])))
  • Wayne74's avatar
    Wayne74
    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.