title: Unable to regenerate storage key with Azure Management API
body: <p>I can't use /regenerateKey [1] to regenerate keys for a Storage Account with the Azure Management API.</p>
  
  <p>I'm using the following code in JavaScript (the resource has the subscription removed)</p>
  
  <pre class="lang-js prettyprint-override"><code>const { ClientSecretCredential } = require('@azure/identity');
  const { SecretClient } = require('@azure/keyvault-secrets');
  const MSRestAzure = require('ms-rest-azure');
  
  const keyVaultName = process.env.KEY_VAULT_NAME;
  const KVUri = `https://${keyVaultName}.vault.azure.net`;
  
  const credential = new ClientSecretCredential(
    process.env.AZURE_TENANT_ID,
    process.env.AZURE_CLIENT_ID,
    process.env.AZURE_CLIENT_SECRET,
  );
  
  const vault = new SecretClient(KVUri, credential);
  
  function getCreds() {
    return new Promise((res, rej) =&gt; {
      MSRestAzure.loginWithServicePrincipalSecret(
        process.env.AZURE_CLIENT_ID,
        process.env.AZURE_CLIENT_SECRET,
        process.env.AZURE_TENANT_ID,
        (err, creds) =&gt; {
          if (err) {
            rej(err);
            return;
          }
          res(creds);
        },
      );
    });
  }
  
  const getResourceUrl = (resource, action) =&gt; `https://management.azure.com${resource}/${action}?api-version=2019-04-01`;
  const resource = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myRg/providers/Microsoft.Storage/storageAccounts/MyStore
  
  
  const creds = await getCreds();
  const client = new MSRestAzure.AzureServiceClient(creds);
  
  const regenUrl = getResourceUrl(resource, 'regenerateKey');
  
  await client.sendRequest({ method: 'POST', url: regenUrl }).then(console.log);
  </code></pre>
  
  <p>I'm getting an <code>UnexpectedException</code> response -</p>
  
  <pre><code>{
      "error": {
          "code": "UnexpectedException",
          "message": "The server was unable to complete your request."
      }
  }
  </code></pre>
  
  <p>The Client ID/Secret belongs to an app registration that has access to the storage account, as well as Contributor and Storage Account Key Operator over that subscription.</p>
  
  <p>I'm lead to think that I've not formed the request properly.</p>