Chaining API Queries to populate a Table Panel

Essentially I have an API endpoint that works with Resource IDs instead of friendly names, but from an end-user perspective, this isn’t helpful.

I have a variable populated with various application names, i.e.

App1, App2, App3 etc.

However, in order to get related information out of the API, I need to first query the API with the friendly name, to get its ResourceID. Once I have the ResourceID, I can then make an API call to get the info I need.

Now, I have a panel using the InfinitySource plugin, that queries the API with an example ResourceID. This works, but is there a way to then link this to the variable mentioned above, that contains friendly names.

i.e. When the user selects a friendly name from the dropdown, it would need to make an API call first to get the ResourceID, store it, then make another API call to get the information I actually want displayed in the table panel.

1 Like

You could (theoretically) create a resourceId variable that would depend on the friendly name. But maybe the friendly name and resourceId are in one-to-one relationship? If you knew them in advance, you could create a custom variable that would map them?

I have a SQL table with applications and resource IDs, i.e. a column for each. How could I use that in this instance?

Hey, If you have mapping available in one of the tables in MySQL. I would suggest to use mixed-datasource.

  • For the query A, use inifinity datasource. For the query B use MySQL datasource.
  • In the transformation, apply “Join” transformation on “Inner” or “Left Join”

In this example screenshot, I’ve a fake api which gives me let’s say book id, and other fields.
Now, I’ve another MySql table which has mapping of book_id and book_title.
I joined both of the queries, using Join transformation.

Join Transformation:

1 Like

Thanks but this isn’t entirely what I’m after.

Ultimately I have an API query like this to populate a table with info;

GET https://API/getAlerts?ResourceID=123456789

I have a variable in Grafana, presented as a dropdown, that contains a list of applications;

App1, App2, App3

In order to perform the API request, I first need to make an API call like this;

GET https://API/getResourceID?FriendlyName=App1

This then allows me to make the call to the API with a ResourceID to get the information I need.

Is there a way in Grafana I can first make the API call with the FriendlyName, using the varaible that the user chooses from the dropdown, and then use that result in another API call to populate the table panel?

Do you have the datasource with this database? Can you create a variable of type query that would return FriendlyName, ResourceID in one query? If so, you can create a variable with __text and __value fields, in which __text represents what users see and __value what is being passed. So with that you would have one variable - users will be picking friendly names and the variable will evaluate to resourceID

1 Like

to add to what @dawiddebowski said, you can go even further and dynamically create the url for the resourcedId as the __value in a variable called apps

select FriendlyName as __text, 
concat('https://API/getResourceID?FriendlyName=',FriendlyName) as __value
from Kimchee

Then have a second hidden variable for resources that uses infinity datasource and feeds it the $apps:value variable

and
then your core data source would use $resources variable to fetch your data to populate your table. It is what Vikas Jumar was alluding to maybe?