cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Keerthi_505
Frequent Visitor

Dynamically calling of API

Hello,


I need to dynamically call API based on table column value.

 

Table 1:

 

Id

TokenID

1

ABCD

2

EFGH

3

PQRS

5

XYZ

 

We need to gather amount information from API against each ID and TokenID.


for example : API – [Https://api.com&id=1&TokenID=ABCD]Https://api.com&id=1&TokenID=ABCD) will return lets say 100.

 

With help of M Query we need to call API as:

 

Id

TokenID

API

1

ABCD

[https://api.com&id=2&tokenid=abcd/]Https://api.com&id=2&TokenID=ABCD

2

EFGH

[https://api.com&id=2&tokenid=efgh/]Https://api.com&id=2&TokenID=EFGH

3

PQRS

[https://api.com&id=3&tokenid=pqrs/]Https://api.com&id=3&TokenID=PQRS

4

XYZ

[https://api.com&id=4&tokenid=xyz/]Https://api.com&id=4&TokenID=XYZ

 

This API will return Amount value and the expected output should be like-

 

Output:

 

Id

TokenID

Amount

1

ABCD

100

2

EFGH

200

3

PQRS

300

4

XYZ

400

 

 

Request you to please help here  who have worked with API.

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @Keerthi_505 

See this PBIX file for a working example.

You can create a function and call the API from inside that, passing in the ID and TokenID for each row.

The code within the function looks something like this

Source = Web.BrowserContents("https://website.com/id="&id&"&tokenid="&tokenid)

And for each row you have code that calls the function like this

= Table.AddColumn(#"Changed Type", "API Call", each APICall(Text.From([Id]), [TokenID]))

You will of course need to enter the correct website address in the function to reach your API.

You also make no mention of needing authentication to the API so no code for this is included.

Regards

Phil



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

6 REPLIES 6
PhilipTreacy
Super User
Super User

Hi @Keerthi_505 

Please supply your file/code so I can see what you are trying.  You can change the  URL to your API before you do this.

I'm still not clear if you need to use a username and password or some other type of authorization to access your API.  Do you?

regards

Phil



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!


Thanks @PhilipTreacy , 

It is working good now

PhilipTreacy
Super User
Super User

Hi @Keerthi_505 

After you entered the address of the website you want to connect to, you'd have received this warning

1-editcred.png

 

When you cliked on the Edit Credentials button you'd have seen this box

2basic.png

 

There are several options here, the top one being Anonymous, meaning connect to the website without a username and password.

Did you choose a different option and enter a username and password?

Typically if an API uses authentication, but only allows Anonymous connections, you have to supply the username and password in the connection attempt to the API/website.

This is why in my initial reply I mentioned that you havdn't said whether or not you need to authenticate (supply a username and password) to access the API.

If you do, I can provide the code needed to do this. Please advise.

Regards

Phil



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!


Hi @PhilipTreacy 

 

Previously I was able to call API into Power bi through web.

I cleared the permissions in datasource settings after that I am not able to call a Single row.

I am getting the following error.

Keerthi_505_1-1632727916981.png

I haven't given any credentials here but still it is showing couldn't authenticate credentials.

Pl help me how to resolve the issue. 

 

Regards,

Keerthi

 

PhilipTreacy
Super User
Super User

Hi @Keerthi_505 

See this PBIX file for a working example.

You can create a function and call the API from inside that, passing in the ID and TokenID for each row.

The code within the function looks something like this

Source = Web.BrowserContents("https://website.com/id="&id&"&tokenid="&tokenid)

And for each row you have code that calls the function like this

= Table.AddColumn(#"Changed Type", "API Call", each APICall(Text.From([Id]), [TokenID]))

You will of course need to enter the correct website address in the function to reach your API.

You also make no mention of needing authentication to the API so no code for this is included.

Regards

Phil



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

Hi Philip,

 I am getting the following error while calling API

An error occurred in the ‘’ query. DataSource.Error: Web.BrowserContents currently supports only anonymous credentials

 

Regards,

Keerthi

Helpful resources

Announcements
PBI_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!