Forum Discussion
timalex
Aug 17, 2023Copper Contributor
Is it possible to filter API GET calls to Azure SQL
I have a need to find all DBs that are NOT within an elastic pool so that i can report on them to maintain costs. Therefore i want to filter my GET call so that it filters out any result set where na...
DEWithNick
Dec 17, 2023Copper Contributor
timalex. Yes, it's possible to do it. You can use the Microsoft Graph REST API POST request:
"https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2021-03-01"
In the request body, you can filter really easy for what you want. To only return databases and not elastic pools:
{
"subscriptions": [
"YOURSUBSCRIPTIONID"
],
"query": "Resources | where type in~ (\"microsoft.sql/servers/databases\") | where type !in~ (\"microsoft.sql/servers/elasticpools\")"
}
To drill down into a specific resource group vs the whole subscription:
"query": "Resources | where resourceGroup in~ (\"YOURRESOURCEGROUPNAME\") | where type in~ (\"microsoft.sql/servers/databases\") | where type !in~ (\"microsoft.sql/servers/elasticpools\")"
See these links for additional info:
-https://learn.microsoft.com/en-us/azure/governance/resource-graph/first-query-rest-api
-https://learn.microsoft.com/en-us/azure/governance/resource-graph/concepts/query-language
Hope this helps!