cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jonnokc098 Occasional Visitor
Occasional Visitor

Dynamic Nested API Calls

Hello, 

 

I am wondering if it is possible to dynamically pull in data from a web API. 

 

Because of how the API is structure I am not able to pull in the data I need in one call. 

 

The top level of the API URL is structure like "http://url/api/rawData"

 

The top level is important because it includes the output of different versions available. The real data I need to access is located at the following URL level... "http://url/api/rawData/[LocationID]/[VersionID]/Data"

 

I know the location ID, but the VersionID is different and new versions are added all the time. 

 

Is there a way I can use the top level URL to get all the different LocationIDs and VersionIDs from within and then somehow loop through either all of them or say the 5 most recent (highest version ID numbers) to get the data from them? Or is it possible to somehow create a report that would allow the user to set which version(s) they are interested in and then initiate the call(s)?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Dynamic Nested API Calls

Yes, that's all possible.

 

You transform the record or whatever is returned from the first call to a table, sort and filter to your desired selections and then add a column to that table that makes the subsequent calls to pull the detail-data. This will return a column with the results from all calls that you can simply expand. No loops required.

 

If your first result is a (Json) record, you might find this article helpful to get you started: http://www.thebiccountant.com/2017/08/30/how-to-open-a-complex-json-record-in-power-bi-and-power-que...

 

Kind regards,

Imke Feldmann

http://www.thebiccountant.com/

 

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




9 REPLIES 9
Super User
Super User

Re: Dynamic Nested API Calls

Yes, that's all possible.

 

You transform the record or whatever is returned from the first call to a table, sort and filter to your desired selections and then add a column to that table that makes the subsequent calls to pull the detail-data. This will return a column with the results from all calls that you can simply expand. No loops required.

 

If your first result is a (Json) record, you might find this article helpful to get you started: http://www.thebiccountant.com/2017/08/30/how-to-open-a-complex-json-record-in-power-bi-and-power-que...

 

Kind regards,

Imke Feldmann

http://www.thebiccountant.com/

 

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




yak Frequent Visitor
Frequent Visitor

Re: Dynamic Nested API Calls

Hi @imke,

 

Can you please help me understand how to make the API calls dynamically from the list obtained after the first API call.

 

Thanks,

Yakshana

 

 

Super User
Super User

Re: Dynamic Nested API Calls

It works as I said above: Transform the list into a table and add a column, referencing the relevant items from your list (that's now your first column).

Provided your list contains the key elements that you need for further calls.

 

If you're struggling with that, please paste your code and pic from your list.

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




Highlighted
asaha3 Frequent Visitor
Frequent Visitor

Re: Dynamic Nested API Calls

Hi Imke,

 

Capture.PNG

 

This is how the JSON looks like and this is my API query: http://aws.com/repositories/intropath/custom/intropath-twohops?person=Justin%20Lipton

 

I am trying to make the name in the end dynamic. Any idea what to do from here on ?

 

Many thanks!

Super User
Super User

Re: Dynamic Nested API Calls

Sure: You add a column with this formula:

 

"http://awsonejefgdb1d.aws.jefco.com:10035/repositories/intropath/custom/intropath-twohops?person=" & Text.BetweenDelimiters([Column1], """", """")

Then remove the rows with errors.

 

If you want to refresh this in the service, you have to adjust you code a bit like described here:

http://blog.datainspirations.com/2018/02/17/dynamic-web-contents-and-power-bi-refresh-errors/

 

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




asaha3 Frequent Visitor
Frequent Visitor

Re: Dynamic Nested API Calls

Hi Imke,

 

This is my dynamic query. I am trying to refresh this in Power BI service.

 

Json.Document(Web.Contents("http://awsonejefgdb1d.aws.jefco.com:10035/repositories/intropath/custom/intropath-twohops?person="&[...""))

 

As per your article this is what I did. Its not working. Not sure where I got wrong. 

 

Json.Document(Web.Contents("http://awsonejefgdb1d.aws.jefco.com:10035/repositories/intropath/custom/intropath-twohops?",
[Query = [person=""&[Name.1]&"%20"&[Name.2]&""]])))

 

Many thanks!

Super User
Super User

Re: Dynamic Nested API Calls

Pls try this:

 

Json.Document(Web.Contents("http://awsonejefgdb1d.aws.jefco.com:10035/repositories/intropath/custom/intropath-twohops", [Query = [person=[Name.1]&" "&[Name.2]]]))

 

or this:

 

Json.Document(Web.Contents("http://awsonejefgdb1d.aws.jefco.com:10035/repositories/intropath/custom/intropath-twohops", [Query = [person=[Name.1]&"%20"&[Name.2]]]))

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




asaha3 Frequent Visitor
Frequent Visitor

Re: Dynamic Nested API Calls

The first query worked..Genius!

yak Frequent Visitor
Frequent Visitor

Re: Dynamic Nested API Calls

Hi @imke

 

I managed to get the list from the first API call and created a parameter with the list of values. Then created a function to invoke the parameters.

 

Then created a invoke custom function which returned the data in the table format.

 

But when I expand the table and apply the changes, I get this error:

 

[Expression.Error] We cannot convert the value null to type Text. 

 

Please let me know what needs to be changed.

 

Thanks