Azure rest apis to ListKeys of classic storage acc

2020-05-01 08:54发布

问题:

I wanted to retrieve the access keys of classic storage account. I found this online

POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/listKeys?api-version=2016-12-01

But this is not applicable for classic storage account. When I replace the Microsoft.Storage to Microsoft.ClassicStorage, it throws the following error

{
    "error": {
        "code": "InvalidRequestUri",
        "message": "The request uri is invalid. The requested path '/subscriptions/{subscriptionID}/resourceGroups/{myresourcegroup}/providers/Microsoft.ClassicStorage/storageAccounts/{myStorageAccount}/listKeys' is not found."
    }
}

NOTE: I am using Application permissions not delegated.

回答1:

For classic storage accounts, the documented way to list keys is using Service Management API (unfortunately I am not able to find the documentation).

You can get the keys for a classic storage accounts using ARM API as well however it is not supported and Microsoft may remove that API completely anytime. To do so, simply use the following URL:

https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ClassicStorage/storageAccounts/{accountName}/listKeys?api-version=2015-06-01

It is also recommended that you convert your classic storage accounts to ARM storage accounts if possible.