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.
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 *accountName = L"youruniquestorageaccount";
CkJsonObjectW request;
request.UpdateString(L"name",accountName);
request.UpdateString(L"type",L"Microsoft.Storage/storageAccounts");
success = http.HttpJson(L"POST",L"https://management.azure.com/subscriptions/{$subscriptionId}/providers/Microsoft.Storage/checkNameAvailability?api-version=2026-09-01",request,L"application/json",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"nameAvailable") != 5) {
wprintf(L"Missing or invalid nameAvailable.\n");
return;
}
if (result.BoolOf(L"nameAvailable") == true) {
wprintf(L"Name is currently available: %s\n",accountName);
}
else {
// Invalid and AlreadyExists are application outcomes, not HTTP failures.
wprintf(L"Name is unavailable. Reason: %s\n",result.stringOf(L"reason"));
wprintf(L"Details: %s\n",result.stringOf(L"message"));
}
// Availability is not a reservation. Creation can still race another caller.
}