Skip to Main Content

Working with the WebAPI tile – tips & tricks

Regardless of the SquaredUp product you use, the WebAPI tile is very useful when it comes to connecting to external data sources and showing them in your dashboards. It brings you closer to that single pane of glass dashboarding dream that we all have, which is why it is also one of our most used tiles!

Check out this video for a quick tour our WebAPI tile, or read on for some handy tips and tricks.

Since the WebAPI tile works with APIs (shocker!), and there are all kinds of APIs out there that use different authentication methods and respond with data of different formats, it sometimes becomes a little trickier to surface the data that you want from the response you have received. In this post, I will share some tips and tricks to dig in for the data that you want from some of the common API response formats.

Note that SquaredUp only works with a JSON response payload, so all the examples we have here are responses of JSON type. I have a repository of sample APIs that we use to make sample dashboards so that is what I’m going to be using for this. The data in there may not be ‘real’, but the formats are very similar to what you’d receive in real world.

First off, I personally like Postman for API testing and seeing the response I get from an API. It’s very easy to use, easy on the eyes, and you can chalk out the data and the corresponding key path etc. very easily from here.

Let’s start with a simple one. Consider the JSON response like the one below:

Here we have a single high-level path under which we have all the values that this API returns. All I have to do in this case is pop in that URL in the HTTP section of the tile and the response data section will populate with the data that this API returns.

Note that we have received some output as the result at the bottom, and some values are just a string of [Object Object] right now, but that’s only because we haven’t selected the ‘key path’ yet. So let’s do that.

Since all the data is at the ‘same level’ under the main path ‘incidents’, we’ll specify that as our key path.

And voila! All the key-value pairs under this path are now in our dashboard! Simple as that. Now to select only a sub-set of these columns, simply go into the ‘grid columns’ section and hide the ones that you don’t want.

You can also rename the columns to something more fitting. And that’s it, we’re done.

Let’s move on to something a little more interesting.

I have the following endpoint that gives me a nested response:

Note that I have three high-level paths here – transactions, summary_alt, and summary. Let’s say the data I want is from summary. So that will become my key path in this case.

Now in the dashboard we have the JSON objects again. To populate this, we need to traverse further and pinpoint the tile to the key-value pairs.

Move on to ‘grid columns’ and hit the edit button. The list of available properties should be displayed to you, simply select the one you’re after.

And there you go; you now have the values!

Let’s try another response format, this time with a deeper key path.

Let’s try to extract the values under the cpu property from this response. Since these are numerical values, let’s plot it as a graph this time.

The key path will be the same – performance, because this is the level where I have access to the metrics.cpuproperty for all my records.

There’s a section in this tile called 'data mapping’ where you can specify what values you want to select to plot on the graph against selected objects.

Of course, we’re plotting the cpu metric values against the object name in this case. There are three key-value pairs for the cpu – average, minimum, and maximum. Let’s pick the average value grouped by all my servers.

To access the properties against each box, simply click on the moustache picker button on the right {{}}:

I’m telling the tile here to group the graph by property {{}}, which is where the name of the server is exposed, against the metric {{metrics.cpu.average}}. And this is what it produces:

Exactly what I wanted to do! Awesome, that was easy.

Now finally, let’s try a response that has arrays in it – these are a little tricky to work with. Let’s say you have a response like the below:

Note that in the response we have an array of key-value pairs (each record enclosed in the box). And say we want to only display the value from a specific record. So how do I go about this? If I choose the grid, it’ll give me the list of amount values for all the records:

But this is not what I’m after. So how do we choose the exact record that we want to access from the array?

The trick is to now specify the number of the record where you want to get the data from. Say the data we want is from the 3rd record, so we will add .2 to the key path to tell the tile where exactly to look (count starts from 0). Also, since this is a single numerical value, let’s go for the scalar tile format this time.

So our path in this case will be transactions.2.amount:

And there it is, the single scalar value that I wanted to display!

Lastly, let’s add in a unit (USD) and round it off to the nearest number, and we’re done!

If the value you need is in a nested array path, you can do that too. Just keep traversing deeper into the array by appending the number of that record in the sequence. For example, a key path of results.2.4.number will fetch me the value of number, from 5th object of the array which in itself is 3rd in a larger array of results under the path results. Simple, right? ?

And that’s it for now folks. Hope this helped to answer some of the questions in your mind. If you need more help with anything relating to SquaredUp, feel free to reach out to us.

Happy dashboarding! ?