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 Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0
' 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.
set token = Server.CreateObject("Chilkat.JsonObject")
token.Strict = 1
success = token.LoadFile("qa_data/tokens/azureToken.json")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not load the private Azure Resource Manager token file.") & "</pre>"
Response.End
End If
If ((token.JsonTypeOf("access_token") <> 1) Or (token.StringOfEquals("access_token","",1) = 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "A nonempty access_token string is required.") & "</pre>"
Response.End
End If
' Use your subscription ID as a string. The all-zero value is only a placeholder.
subscriptionId = "00000000-0000-0000-0000-000000000000"
set http = Server.CreateObject("Chilkat.Http")
http.AuthToken = token.StringOf("access_token")
http.Accept = "application/json"
http.RequireSslCertVerify = 1
http.FollowRedirects = 0
http.ConnectTimeout = 30
http.ReadTimeout = 60
success = http.SetUrlVar("subscriptionId",subscriptionId)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not encode subscription ID.") & "</pre>"
Response.End
End If
ERROR: ASP example cannot use request or response as a variable name.
set result = Server.CreateObject("Chilkat.JsonObject")
result.Strict = 1
set parsed = Server.CreateObject("Chilkat.Url")
resourceGroupName = "my-resource-group"
success = http.SetUrlVar("resourceGroupName",resourceGroupName)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not encode resource group.") & "</pre>"
Response.End
End If
accountName = "youruniquestorageaccount"
success = http.SetUrlVar("accountName",accountName)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not encode account name.") & "</pre>"
Response.End
End If
resourceUrl = "https://management.azure.com/subscriptions/{$subscriptionId}/resourceGroups/{$resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{$accountName}?api-version=2026-09-01"
success = http.HttpNoBody("GET",resourceUrl,response)
If (response.StatusCode = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( "No HTTP response. Inspect LastErrorText privately; it may contain credentials.") & "</pre>"
Response.End
End If
If ((response.StatusCode <> 200)) Then
Response.Write "<pre>" & Server.HTMLEncode( "HTTP status: " & response.StatusCode) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "Request ID: " & response.GetHeaderField("x-ms-request-id")) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "Retry-After: " & response.GetHeaderField("Retry-After")) & "</pre>"
' 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.
Response.End
End If
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "The HTTP response could not be read completely.") & "</pre>"
Response.End
End If
success = result.Load(response.BodyStr)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Expected a well-formed JSON response.") & "</pre>"
Response.End
End If
If (result.JsonTypeOf("id") <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Missing or invalid id.") & "</pre>"
Response.End
End If
If (result.JsonTypeOf("name") <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Missing or invalid name.") & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "Account selected for deletion: " & result.StringOf("name")) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "Resource ID: " & result.StringOf("id")) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "Location: " & result.StringOf("location")) & "</pre>"
' DESTRUCTIVE: deletes the account and the data it contains.
' Review this output and complete your backup/retention process first.
deleteAccount = 0
If (deleteAccount <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Inspection only. Set deleteAccount to true to delete this account.") & "</pre>"
Response.End
End If
success = http.HttpNoBody("DELETE",resourceUrl,response)
If (response.StatusCode = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( "No HTTP response. Inspect LastErrorText privately; it may contain credentials.") & "</pre>"
Response.End
End If
If ((response.StatusCode <> 200) And (response.StatusCode <> 204)) Then
Response.Write "<pre>" & Server.HTMLEncode( "HTTP status: " & response.StatusCode) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "Request ID: " & response.GetHeaderField("x-ms-request-id")) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "Retry-After: " & response.GetHeaderField("Retry-After")) & "</pre>"
' 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.
Response.End
End If
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "The HTTP response could not be read completely.") & "</pre>"
Response.End
End If
' No JSON body is required. A 204 means the account does not exist.
Response.Write "<pre>" & Server.HTMLEncode( "Storage account deleted or already absent.") & "</pre>"
' 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.
%>
</body>
</html>