Secret Power Of Web.Contents PQ Function: URL Parameter – Part 2

If you haven’t checked the different parameters of Web.Contents function, then please check them from MSDN.

In this post, we are going to see how to use URL Parameter.

Before going further if want to have a clear idea of API Call different ways of sending data please check this short video.

And our first example is very simple.

Only URL Example.pq Code:

let
  Source  = Web.Contents("http://ip.jsontest.com/"), 
  Custom1 = fxJsonBinaryToTable(Source, false, "|")
in
  Custom1

In this example, we are just calling to find out about our IP address.

Here is the response snapshot of this API Call.

If you are scratching your head about what this fxJsonBinaryToTable is then please check part 1 post of this series.

Next, we are going to see another example. In that example, we have prepared the URL by concatenating the query parameter(If you don’t know what is query parameter then please check the video mentioned earlier)

Query Param Concatenated In URL.pq Code:

let
  URL              = "https://datausa.io/api/data?drilldowns=Nation&measures=Population", 
  Source           = Web.Contents(URL), 
  ConvertedToTable = fxJsonBinaryToTable(Source, false, "|")
in
  ConvertedToTable

Whatever you see after “?” in the URL is basically query parameters. It’s key-value pair. For this example “drilldowns” is the query param name and “Nation” is the value for that query param.

Similarly “measures “is the query param name and “Population” is the value.

There is a better way to do this and we will learn them in the upcoming part.

Here is the sample response of this code

So you can prepare the URL by concatenating the query param. And then call the API. But a cleaner approach is to use the Query option. We are going to see that in the upcoming post.

This is all for this part. If you have any suggestions/questions feel free to comment.

Subscribe to Blog via Email

Enter your email to subscribe to this blog and receive notifications of new posts by email.

You may also like

Please login to Continue Reading