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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
rosscortb
Post Patron
Post Patron

Help using API's

Hello

 

So, API's totally baffle me, could do with some help.

I am never sure whether to use getdata, then is it web, json, and then there if several options, signing in, providing key that never seems to work.

So, first, do I use Desktop or Service as the options seems to be there for desktop but what I 've read so suggest Service?

 

Request URL which is the hello world

https://gcc.azure-api.net/echo/resource[?param1][&param2]

after that there is this

api.PNG

 

 

 

 

 

What do I do next?

Ross

3 REPLIES 3
v-xicai
Community Support
Community Support

Hi @rosscortb   ,

 

Do the suggestions from engineers make sense? If so, kindly mark the proper reply as a solution to help others having the similar issue and close the case. If not, let me know and I'll try to help you further.

 

Best regards

Amy

Hello @v-xicai

I understand most of the answer, I think the issue I have is understanding the practical steps to getting the info.

Thanks
Ross

lbendlin
Super User
Super User

Web APIs work on two main principles

 

1. GET - you have a URL that may contain parameters. You use Web.Contents with the URL and get your data back from that server. Oftentimes the response is in JSON format that you then need to parse. You can run these steps separately or pipe them together. As you mentioned sometimes these servers require you to authenticate or to add othe header information.

 

 

...
    URL = "http://xxx/tstat",
    headers = [#"Content-Type"="application/json"],
    web = Web.Contents(URL,  Headers = headers, ManualStatusHandling = {404, 400}]),
    result = Json.Document(web),
    #"Converted to Table" = Record.ToTable(result)
...

 

 

2. PUT - this is when you have secret data like a password that you don't want to send in clear text, or commands and data that you want to send TO the API server.  That requires you to prepare the payload, and put it in the request body.  An example is here

 

 

... 
    URL = "http://xxx/tstat",
    headers = [#"Content-Type"="application/json"],
    data = Json.FromValue([tmode = 2,t_cool = Setpoint,hold = 0]),
    web = Web.Contents(URL, [ Content = data, Headers = headers, ManualStatusHandling = {404, 400}]),
    result = Json.Document(web),
    #"Converted to Table" = Record.ToTable(result)
...

 

 

You see that there's no way to specify GET or PUT - instead the presence of a non-empty Content will automatically change the method from GET to PUT. The Json.FromValue part here has a lot of pixie dust - not only does it convert the parameters into usable format but it also binary encodes the payload.

 

This all happens in Power Query which works the same on the Power BI desktop and on the service (when you refresh your dataset it will run all the included Power Query scripts).

 

Your example is a GET request with a URL that has some dynamic parameters. You can concatenate the URL string yourself, or use the Query= function to swap your parameter values in as needed.

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.