Azure Storage Accounts: Delete a Storage Account (Destructive)
See more Azure Storage Accounts Examples
Deletes an entire storage account and its stored data. The default is inspection only: GET and display the target. Set deleteAccount=true only after selecting the correct account and completing the required backup/retention process. Blob soft delete is not protection against account deletion.
Handles DELETE 200 and 204 without parsing an empty body. A preflight GET failure stops the example; a 204 after that GET can result if another caller already deleted the account. Account read/delete permissions are required. Locks and policy restrictions are reported rather than bypassed. Reconcile an uncertain transport outcome by reading the account instead of assuming deletion failed.
These calls manage Azure resources at management.azure.com. They do not upload or download stored data. Supply a current Microsoft Entra access token for Azure Resource Manager in private qa_data/tokens/azureToken.json, with a nonempty access_token string. For v2 client credentials, request https://management.azure.com/.default; obtain a new token when it expires. A storage account key, SAS, Microsoft Graph token, or Storage data-plane token is not an ARM token. Never print the token or commit its file.
Azure RBAC must grant the caller the required management actions at the appropriate scope. An app registration alone does not grant resource access. Management permissions and blob/file data permissions are distinct. These examples target public Azure; sovereign clouds require the corresponding authority, ARM endpoint, token audience, and continuation-host validation.
Chilkat Unicode C++ Downloads
#include <CkJsonObjectW.h>
#include <CkHttpW.h>
#include <CkHttpResponseW.h>
#include <CkUrlW.h>
void ChilkatSample(void)
{
bool success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global.UnlockBundle for sample code.
// This is Azure Resource Manager (the management plane), not a blob data request.
// Load an unexpired Microsoft Entra token whose audience is Azure Resource Manager.
// For the v2 token endpoint, request scope https://management.azure.com/.default.
// Keep the token file private and out of source control and public web directories.
CkJsonObjectW token;
token.put_Strict(true);
success = token.LoadFile(L"qa_data/tokens/azureToken.json");
if (success != true) {
wprintf(L"Could not load the private Azure Resource Manager token file.\n");
return;
}
if ((token.JsonTypeOf(L"access_token") != 1) || (token.StringOfEquals(L"access_token",L"",true) == true)) {
wprintf(L"A nonempty access_token string is required.\n");
return;
}
// Use your subscription ID as a string. The all-zero value is only a placeholder.
const wchar_t *subscriptionId = L"00000000-0000-0000-0000-000000000000";
CkHttpW http;
http.put_AuthToken(token.stringOf(L"access_token"));
http.put_Accept(L"application/json");
http.put_RequireSslCertVerify(true);
http.put_FollowRedirects(false);
http.put_ConnectTimeout(30);
http.put_ReadTimeout(60);
success = http.SetUrlVar(L"subscriptionId",subscriptionId);
if (success != true) {
wprintf(L"Could not encode subscription ID.\n");
return;
}
CkHttpResponseW response;
CkJsonObjectW result;
result.put_Strict(true);
CkUrlW parsed;
const wchar_t *resourceGroupName = L"my-resource-group";
success = http.SetUrlVar(L"resourceGroupName",resourceGroupName);
if (success != true) {
wprintf(L"Could not encode resource group.\n");
return;
}
const wchar_t *accountName = L"youruniquestorageaccount";
success = http.SetUrlVar(L"accountName",accountName);
if (success != true) {
wprintf(L"Could not encode account name.\n");
return;
}
const wchar_t *resourceUrl = L"https://management.azure.com/subscriptions/{$subscriptionId}/resourceGroups/{$resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{$accountName}?api-version=2026-09-01";
success = http.HttpNoBody(L"GET",resourceUrl,response);
if (response.get_StatusCode() == 0) {
wprintf(L"No HTTP response. Inspect LastErrorText privately; it may contain credentials.\n");
return;
}
if ((response.get_StatusCode() != 200)) {
wprintf(L"HTTP status: %d\n",response.get_StatusCode());
wprintf(L"Request ID: %s\n",response.getHeaderField(L"x-ms-request-id"));
wprintf(L"Retry-After: %s\n",response.getHeaderField(L"Retry-After"));
// Inspect the error body privately. Do not log tokens, headers, or full responses.
// For 401 check the token/audience; for 403 check Azure RBAC and policy.
// Honor Retry-After for 429 and use bounded backoff for transient failures.
return;
}
if (success != true) {
wprintf(L"The HTTP response could not be read completely.\n");
return;
}
success = result.Load(response.bodyStr());
if (success != true) {
wprintf(L"Expected a well-formed JSON response.\n");
return;
}
if (result.JsonTypeOf(L"id") != 1) {
wprintf(L"Missing or invalid id.\n");
return;
}
if (result.JsonTypeOf(L"name") != 1) {
wprintf(L"Missing or invalid name.\n");
return;
}
wprintf(L"Account selected for deletion: %s\n",result.stringOf(L"name"));
wprintf(L"Resource ID: %s\n",result.stringOf(L"id"));
wprintf(L"Location: %s\n",result.stringOf(L"location"));
// DESTRUCTIVE: deletes the account and the data it contains.
// Review this output and complete your backup/retention process first.
bool deleteAccount = false;
if (deleteAccount != true) {
wprintf(L"Inspection only. Set deleteAccount to true to delete this account.\n");
return;
}
success = http.HttpNoBody(L"DELETE",resourceUrl,response);
if (response.get_StatusCode() == 0) {
wprintf(L"No HTTP response. Inspect LastErrorText privately; it may contain credentials.\n");
return;
}
if ((response.get_StatusCode() != 200) && (response.get_StatusCode() != 204)) {
wprintf(L"HTTP status: %d\n",response.get_StatusCode());
wprintf(L"Request ID: %s\n",response.getHeaderField(L"x-ms-request-id"));
wprintf(L"Retry-After: %s\n",response.getHeaderField(L"Retry-After"));
// Inspect the error body privately. Do not log tokens, headers, or full responses.
// For 401 check the token/audience; for 403 check Azure RBAC and policy.
// Honor Retry-After for 429 and use bounded backoff for transient failures.
return;
}
if (success != true) {
wprintf(L"The HTTP response could not be read completely.\n");
return;
}
// No JSON body is required. A 204 means the account does not exist.
wprintf(L"Storage account deleted or already absent.\n");
// If a transport error occurs, GET the account to reconcile the outcome.
// Resource locks and Azure Policy can block deletion; do not remove them silently.
}