Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

Loop over API and another Query

Dears, 

 

I need your help please, i have a student table that has IDs in a Query1 and this id i will use it to call the API to get the token for each student at the same time i will loop over these Student IDs to generat all tokens and store them in one table to use later. 

 

student.PNG

 

let
url = "https://api.Student/xxxxxxxxx",
body = "{""Studentref"" :""XXXXXXXXX"", ""StudentID"" :839349,""grant_type"" : ""Student_credentials""}",
Source = Json.Document(Web.Contents(url, [Headers=[Method="POST", #"Content-Type"="application/json", Accept="application/json"], Content=Text.ToBinary(body)]))
in
Source

 

Thanks in advance

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @Anonymous 

Without access to the API I can't verify this code works, but this is syntactically correct and will loop through each Student ID and make a POST request to the url.

  Sample PBIX file here.

 

let
    url = "https://api.student/xxxxxxxxx",
    
    GetAPI = (StudentID) => 
    let
        body = "{""Studentref"" :""XXXXXXXXX"", ""StudentID"" :"& StudentID &",""grant_type"" : ""Student_credentials""}",
        json = Json.Document(Web.Contents(url, [Headers=[ #"Content-Type"="application/json", Accept="application/json"], Content=Text.ToBinary(body)]))
    in 
        json,

    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI0MjY0UorViVZyAvKMjUyMDcE8ZyAPKGViDOa5AHmmJsZGEJ4rWJ+JmblSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Student = _t, StudentID = _t]),
    #"Added Custom" = Table.AddColumn(Source, "JSON", each GetAPI([StudentID]))
in
    #"Added Custom"

 

Regards

Phil


If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

3 REPLIES 3
PhilipTreacy
Super User
Super User

Hi @Anonymous 

That Source = step is created by Power BI when I entered your sample data into my PBI Desktop to create the source table.

You shoud create your own table of Student/Stuent ID and then import that into PBI so that your Source step loads that table.

Regards

Phil


If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


PhilipTreacy
Super User
Super User

Hi @Anonymous 

Without access to the API I can't verify this code works, but this is syntactically correct and will loop through each Student ID and make a POST request to the url.

  Sample PBIX file here.

 

let
    url = "https://api.student/xxxxxxxxx",
    
    GetAPI = (StudentID) => 
    let
        body = "{""Studentref"" :""XXXXXXXXX"", ""StudentID"" :"& StudentID &",""grant_type"" : ""Student_credentials""}",
        json = Json.Document(Web.Contents(url, [Headers=[ #"Content-Type"="application/json", Accept="application/json"], Content=Text.ToBinary(body)]))
    in 
        json,

    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI0MjY0UorViVZyAvKMjUyMDcE8ZyAPKGViDOa5AHmmJsZGEJ4rWJ+JmblSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Student = _t, StudentID = _t]),
    #"Added Custom" = Table.AddColumn(Source, "JSON", each GetAPI([StudentID]))
in
    #"Added Custom"

 

Regards

Phil


If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

Thank you so much Philip, I will go through it  and i have combined the file and i want to generate the 

binary text, but how i can get the Binary.FromText?

 

Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI0MjY0UorViVZyAvKMjUyMDcE8ZyAPKGViDOa5AHmmJsZGEJ4rWJ+JmblSbCwA", BinaryEncoding.Base64), Compression.Deflate))

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.