Showing results for 
Search instead for 
Did you mean: 
Floater New Member
New Member

M language and Nested API calls


I am populating a table based on a API call code below 

    Source = Json.Document(Web.Contents("https://xxxxxxxxxxxxxxxx/scenarios.json", [Headers=[Authorization="Token token=""xxxxxxxxxxxxxxxxxxxxxxx"""]])),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"id", "title", "scenario_type", "date_started", "date_finished", "responses", "full_csv_url", "recipients", "notes"}, {"", "Column1.title", "Column1.scenario_type", "Column1.date_started", "Column1.date_finished", "Column1.responses", "Column1.full_csv_url", "Column1.recipients", "Column1.notes"}),
    #"Sorted Rows" = Table.Sort(#"Expanded Column1",{{"Column1.date_started", Order.Ascending}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Sorted Rows",{{"Column1.date_started", type datetime}}),
    #"Sorted Rows1" = Table.Sort(#"Changed Type",{{"Column1.date_started", Order.Ascending}}),
    #"Renamed Columns" = Table.RenameColumns(#"Sorted Rows1",{{"", "ID"}, {"Column1.title", "Title"}, {"Column1.scenario_type", "Scenario_Type"}, {"Column1.date_started", "Date_Started"}, {"Column1.date_finished", "Date_Finished"}, {"Column1.responses", "Responses"}, {"Column1.full_csv_url", "Scenario_API_URL"}, {"Column1.recipients", "Recipients"}, {"Column1.notes", "Notes"}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Scenario_API_URL", type text}, {"Date_Finished", type datetime}, {"Scenario_Type", type text}, {"Title", type text}, {"Recipients", Int64.Type}})
    #"Changed Type1"

the output of the table will have 200-300 rows (scenarios) and a column called Scenario_API_URL stores the string which is URL address for the nested API call which will return details about the selected scenario.


I wrote a function called scenariograbber

let scenariograbber=(url)=>
        Source = Csv.Document(Web.Contents(url, [Headers=[Authorization="Token token=""xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"""]]))

which it will return the result if I invoke the function manually and enter one of the URLs retruned by the first result set.


I want to combaine all the sub API calles as one table!

would appreciate your help


Super User
Super User

Re: M language and Nested API calls

Invoking the masterful @ImkeF who is the master of M code.

I have book! Learn Power BI from Packt

Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

Super User
Super User

Re: M language and Nested API calls

Hi @Floater

you should execute your first query and then create a new column where you call the function (for each row/URL). That way you get it all in one table.


But if you want to refresh it in the service, your function has to be modified a bit:

The video in there also shows how to add a function to a table like yours.


Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

Imke Feldmann

How to integrate M-code into your solution -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Community Highlights

Community Highlights

Find out what's new in the Power BI Community!

Summit North America

Power Platform Summit North America

Register by September 5 to save $200

Virtual Launch Event

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Users Online
Currently online: 298 members 3,859 guests
Please welcome our newest community members: