Sample code for 30+ languages & platforms
C# Requires Chilkat v11.6.0+

Azure Storage Accounts: Check Storage Account Name Availability

See more Azure Storage Accounts Examples

Checks a proposed globally unique account name before creation. Account names contain 3-24 lowercase letters or digits. HTTP 200 can mean either available or unavailable: inspect nameAvailable and, when false, reason and message. The check does not reserve a name or validate region/SKU availability.

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.

Microsoft API reference

Chilkat C# Downloads

C#
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.
Chilkat.JsonObject token = new Chilkat.JsonObject();
token.Strict = true;
success = token.LoadFile("qa_data/tokens/azureToken.json");
if (success != true) {
    Debug.WriteLine("Could not load the private Azure Resource Manager token file.");
    return;
}

if ((token.JsonTypeOf("access_token") != 1) || (token.StringOfEquals("access_token","",true) == true)) {
    Debug.WriteLine("A nonempty access_token string is required.");
    return;
}

//  Use your subscription ID as a string. The all-zero value is only a placeholder.
string subscriptionId = "00000000-0000-0000-0000-000000000000";
Chilkat.Http http = new Chilkat.Http();
http.AuthToken = token.StringOf("access_token");
http.Accept = "application/json";
http.RequireSslCertVerify = true;
http.FollowRedirects = false;
http.ConnectTimeout = 30;
http.ReadTimeout = 60;
success = http.SetUrlVar("subscriptionId",subscriptionId);
if (success != true) {
    Debug.WriteLine("Could not encode subscription ID.");
    return;
}

Chilkat.HttpResponse response = new Chilkat.HttpResponse();
Chilkat.JsonObject result = new Chilkat.JsonObject();
result.Strict = true;
Chilkat.Url parsed = new Chilkat.Url();
string accountName = "youruniquestorageaccount";
Chilkat.JsonObject request = new Chilkat.JsonObject();
request.UpdateString("name",accountName);
request.UpdateString("type","Microsoft.Storage/storageAccounts");
success = http.HttpJson("POST","https://management.azure.com/subscriptions/{$subscriptionId}/providers/Microsoft.Storage/checkNameAvailability?api-version=2026-09-01",request,"application/json",response);
if (response.StatusCode == 0) {
    Debug.WriteLine("No HTTP response. Inspect LastErrorText privately; it may contain credentials.");
    return;
}

if ((response.StatusCode != 200)) {
    Debug.WriteLine("HTTP status: " + Convert.ToString(response.StatusCode));
    Debug.WriteLine("Request ID: " + response.GetHeaderField("x-ms-request-id"));
    Debug.WriteLine("Retry-After: " + response.GetHeaderField("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) {
    Debug.WriteLine("The HTTP response could not be read completely.");
    return;
}

success = result.Load(response.BodyStr);
if (success != true) {
    Debug.WriteLine("Expected a well-formed JSON response.");
    return;
}

if (result.JsonTypeOf("nameAvailable") != 5) {
    Debug.WriteLine("Missing or invalid nameAvailable.");
    return;
}

if (result.BoolOf("nameAvailable") == true) {
    Debug.WriteLine("Name is currently available: " + accountName);
}
else {
    //  Invalid and AlreadyExists are application outcomes, not HTTP failures.
    Debug.WriteLine("Name is unavailable. Reason: " + result.StringOf("reason"));
    Debug.WriteLine("Details: " + result.StringOf("message"));
}

//  Availability is not a reservation. Creation can still race another caller.