Ehsan Mirsaeedi
Ehsan Mirsaeedi

Reputation: 7592

Getting tags associated with an API in Azure API Management

Is there a way to get tags that are associated with an API through Powershell?

The Get-AzApiManagementApi command returns the list of APIs, but tags are not included in its response.

Upvotes: 1

Views: 1469

Answers (2)

Joy Wang
Joy Wang

Reputation: 42143

The command Get-AzApiManagementApi will not return the tags of each API, the workaround is to use Get-AzResource.

Try the script as below, it returns tags of each API.

$ResourceGroupName = "<resource-group-name>"
$APImg = "<API-Management-service-name>"
$ApiMgmtContext = New-AzApiManagementContext -ResourceGroupName $ResourceGroupName -ServiceName $APImg
$Apis = Get-AzApiManagementApi -Context $ApiMgmtContext
foreach($Api in $Apis){
    $ApiId = $Api.ApiId
    $ApiName = $Api.Name
    $tags = (Get-AzResource -ResourceGroupName $ResourceGroupName -ResourceType Microsoft.ApiManagement/service/apis/tags -ResourceName "$APImg/$ApiId" -ApiVersion 2018-01-01).Name
    Write-Host "Tags of" $ApiName : $tags
}

enter image description here

Upvotes: 3

DixitArora-MSFT
DixitArora-MSFT

Reputation: 1811

From Powershell Try this . You can also get this from resource explorer .

Get-AzureRmResource -ResourceGroupName Integration-Resources -ResourceType Microsoft.ApiManagement/service/tags -ResourceName "integration-common/test" -ApiVersion 2018-01-01

By using Rest API , you can get it Tag - Get By Api https://learn.microsoft.com/en-us/rest/api/apimanagement/2019-01-01/tag/getbyapi

You can also follow this GitHub Issue for reference. https://github.com/MicrosoftDocs/azure-docs/issues/21817

Upvotes: 0

Related Questions