Search code examples
azure-devopsazure-pipelinesazure-cli

Why does az cli not return primary key in the powershell Get-AzApiManagementSubscription query? Is there a way?


Why does az cli not return PrimaryKey in the powershell Get-AzApiManagementSubscription query? Is there a way? See below, both the Primary and Secondary private keys are empty. Is it a special permission I require perhaps?

PS /Users/me> Get-AzApiManagementSubscription -Context $apimContext                                                     

SubscriptionId    : {obfuscated}
UserId            : 1
OwnerId           : /subscriptions/{obfuscated}/resourceGroups/my-test/providers/Microsoft.ApiManagement/service/my-apim-test/users/1
ProductId         : starter
Scope             : /subscriptions/{obfuscated}/resourceGroups/my-test/providers/Microsoft.ApiManagement/service/my-apim-test/products/starter
Name              : 
State             : Active
CreatedDate       : 4/23/2022 12:28:31 AM
StartDate         : 
ExpirationDate    : 
EndDate           : 
NotificationDate  : 
PrimaryKey        : 
SecondaryKey      : 
StateComment      : 
AllowTracing      : True
Id                : /subscriptions/{obfuscated}/resourceGroups/my-test/providers/Microsoft.ApiManagement/service/my-apim-test/subscriptions/{obfuscated}
ResourceGroupName : my-test
ServiceName       : my-apim-test

Solution

  • To get the Primary key and secondary key of subscriptions available in the Azure APIM Instance using the cmdlet is:

    $apimContext = New-AzApiManagementContext -ResourceGroupName "Api-Default-East-US" -ServiceName "contoso"
    Get-AzApiManagementSubscriptionKey -Context $apimContext -SubscriptionId "0123456789"
    

    enter image description here

    Result:

    enter image description here

    In the above cmdlet, Subscription Id is the Id of APIM Subscription like Starter, Unlimited, and Built-in all access.

    enter image description here