Home > OS >  Fetch Azure API Management subscription key using azure cli
Fetch Azure API Management subscription key using azure cli

Time:10-06

I am trying to get the subscription keys for my products as well as default subscription key using cli. I have gone through the documentation https://docs.microsoft.com/en-us/cli/azure/apim/api?view=azure-cli-latest , but right now I don't see any commands to get me the subscription key.

While I can see there are powershell way of getting it, we run the tasks in ubuntu pipeline, and the commands listed below is not working in the linux agent. It says Set-AzContext is not a known command

$subscriptionId = "id"
$RG = "rg"
$service = "apim-name"

Set-AzContext -Subscription $subscriptionId 

$apimContext = New-AzApiManagementContext -ResourceGroupName $RG -ServiceName $service

Get-AzApiManagementSubscriptionKey -Context $apimContext -SubscriptionId "master"

Update I am able to fetch the details through powershell task for Azure in the DevOps pipeline. If there is no option in azure cli I will use this as a workaround.

CodePudding user response:

Currently it is not possible to fetch subscription key using AZ CLI commands. The PowerShell command used is the correct way to go. Just in case if it helps another way to get the subscription key is by using Management API call

  • Related