Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

Combining API Call with two functions (including pagination)

Hi,

I am trying to call an API in Power BI and have run into a roadblock.

 The API parameters only allow 1 site to be entered, so I have created Function 1 and invoked it on a site table (using site email as @hostEmail). But it is only returning 100 records per site.

Following a tutorial, I created Function 2 for pagination (record count unknown) and invoked it on a List query to loop and get all records, but it only works for 1 site.

 

Is it possible to get the pagination working in Function 1?

 

All Site Call - Function 1

-----------------------------------------

(hostEmail as any) => let

    Source = Json.Document(Web.Contents("https://webexapis.com/v1/" & "meetings"

      &"?&hostEmail="&(hostEmail)
      [Headers=[Authorization=List.Min(#"Refresh Token (POST)")]])),

    #"Converted to Table" = Table.FromRecords({Source}),
   #"Removed Columns" = Table.RemoveColumns(#"Inserted Minutes",{"Custom"})

in

    #"Removed Columns"
-----------------------------------------

 

Pagination 

Query using Function 2

-----------------------------------------

= List.Generate(()=>

[Result = try MeetingwOffset(100) otherwise null, Offset=100],

each [Result] <>null,

each [Result= try MeetingwOffset([Offset]+100) otherwise null, Offset=[Offset]+100],

each [Result])

-----------------------------------------

 

Function 2

-----------------------------------------

(Offset as number)=>let

    Source = Json.Document(Web.Contents("https://webexapis.com/v1/" & "meetings"

    &"?hostEmail=AAA"

     &"&max=100&offset="&Number.ToText(Offset),

    [Headers=[Authorization=List.Min(#"Refresh Token (POST)")]])),

    #"Converted to Table" = Table.FromRecords({Source}),

    #"Removed Columns" = Table.RemoveColumns(#"Inserted Minutes",{"Custom"})

in

    #"Removed Columns"

-----------------------------------------

 

Thank you for your help in advance.

3 Replies

  • ImkeF's avatar
    ImkeF
    Community Champion

    Hi Anonymous ,
    cannot see anything wrong with your function.
    Did you try the URL that is created through another tool like Postman or Power Automate to see if the correct results are returned?
    Might be actually an isse on how the URL is structured.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi ImkeF

      Both functions work separately, but I need to combine them into a single function so I can apply the function against the site table and have it paginate. 

      I would be grateful for your advice.

      Thanks, Bianca

  • ImkeF's avatar
    ImkeF
    Community Champion

    Hi Anonymous ,
    not sure I fully understand, but wouldn't you have t make the site dynamic like in the first function?:

     

    (Offset as number, hostEmail as text)=>let

        Source = Json.Document(Web.Contents("https://webexapis.com/v1/" & "meetings"

        &"?hostEmail="&(hostEmail)

         &"&max=100&offset="&Number.ToText(Offset),

        [Headers=[Authorization=List.Min(#"Refresh Token (POST)")]])),

        #"Converted to Table" = Table.FromRecords({Source}),

        #"Removed Columns" = Table.RemoveColumns(#"Inserted Minutes",{"Custom"})

    in

        #"Removed Columns"

    --------------------------------