Azure Storage Accounts: Create an Account and Monitor Provisioning
See more Azure Storage Accounts Examples
Creates a general-purpose v2 account using direct Chilkat.Http calls and API version 2026-09-01, then monitors provisioning. This operation can create billable resources and can update an existing account at the same resource ID. Review the target and body before running it.
Set the subscription, an existing resource group, a globally unique account name (3-24 lowercase letters or digits), and a supported region. Register Microsoft.Storage for the subscription if necessary. The caller needs account write/read permissions and permission to monitor the operation at resource-group scope. Azure policy, quota, resource locks, and SKU availability can also affect the request.
The sample selects StorageV2, Standard_LRS, and the Hot tier. It requires HTTPS, sets the account's minimum TLS version to 1.2, and disables anonymous blob access. This does not configure private networking or disable Shared Key authentication; choose those policies separately for the intended clients. The minimum-TLS property controls storage clients, not the TLS protocol negotiated by Chilkat.Http.
HTTP 202 means accepted, not ready. The code prefers Azure-AsyncOperation when present, otherwise uses Location, honors integer Retry-After delays, and verifies the final resource state. Polling is bounded. Long or non-integer delays pause the sample for later resumption. Save the printed URL, monitor type, and retry interval; set operationUrl and operationUsesStatus to resume without another PUT. In production, persist this state and schedule polling without blocking the UI.
A timeout after submitting the PUT does not prove that Azure rejected it. Inspect the target resource before submitting again. On polling failures or time limits, resume monitoring instead of creating another request. See tracking asynchronous Azure operations.
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 <CkStringBuilderW.h>
#include <CkJsonObjectW.h>
#include <CkHttpW.h>
#include <CkHttpResponseW.h>
#include <CkUrlW.h>
void ChilkatSample(void)
{
bool success = false;
CkStringBuilderW stringCompare;
// 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;
// Choose an EXISTING resource group and a globally unique 3-24 character name
// containing only lowercase letters and digits. Choose a supported Azure region.
const wchar_t *resourceGroupName = L"my-resource-group";
const wchar_t *accountName = L"youruniquestorageaccount";
const wchar_t *location = L"eastus";
success = http.SetUrlVar(L"resourceGroupName",resourceGroupName);
if (success != true) {
wprintf(L"Could not encode resource group.\n");
return;
}
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";
// To resume monitoring, paste the operation URL printed by an earlier run here.
// Also set operationUsesStatus to the printed value (Azure-AsyncOperation=true,
// Location=false). A nonempty operationUrl skips the PUT completely.
const wchar_t *operationUrl = L"";
bool operationUsesStatus = false;
// When resuming, first wait for the Retry-After interval from the prior response.
const wchar_t *retryAfter = L"";
stringCompare.SetString(operationUrl);
bool stringMatch1 = stringCompare.ContentsEqual(L"",true);
if (stringMatch1 == true) {
CkJsonObjectW request;
request.UpdateString(L"location",location);
request.UpdateString(L"kind",L"StorageV2");
request.UpdateString(L"sku.name",L"Standard_LRS");
request.UpdateString(L"properties.accessTier",L"Hot");
request.UpdateBool(L"properties.supportsHttpsTrafficOnly",true);
request.UpdateString(L"properties.minimumTlsVersion",L"TLS1_2");
request.UpdateBool(L"properties.allowBlobPublicAccess",false);
// This PUT can UPDATE an existing account at this resource ID.
// Review the target and settings first. Creating storage can incur charges.
success = http.HttpJson(L"PUT",resourceUrl,request,L"application/json",response);
// If transport fails, inspect this resource before deciding to submit again;
// Azure may already have accepted the PUT.
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() != 202)) {
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;
}
if (response.get_StatusCode() == 202) {
// An accepted operation can have an EMPTY body. Do not try to parse it.
operationUrl = response.getHeaderField(L"Azure-AsyncOperation");
stringCompare.SetString(operationUrl);
bool stringMatch2 = stringCompare.ContentsEqual(L"",true);
if (stringMatch2 != true) {
operationUsesStatus = true;
}
else {
operationUrl = response.getHeaderField(L"Location");
}
stringCompare.SetString(operationUrl);
bool stringMatch3 = stringCompare.ContentsEqual(L"",true);
if (stringMatch3 == true) {
wprintf(L"Accepted, but no monitor URL was returned. Check the resource; do not assume success.\n");
return;
}
retryAfter = response.getHeaderField(L"Retry-After");
}
}
stringCompare.SetString(operationUrl);
bool stringMatch4 = stringCompare.ContentsEqual(L"",true);
if (stringMatch4 != true) {
success = parsed.ParseUrl(operationUrl);
if (success != true) {
wprintf(L"Missing or invalid continuation URL.\n");
return;
}
stringCompare.SetString(parsed.scheme());
bool stringMatch5 = stringCompare.ContentsEqual(L"https",true);
stringCompare.SetString(parsed.host());
bool stringMatch6 = stringCompare.ContentsEqual(L"management.azure.com",true);
stringCompare.SetString(parsed.login());
bool stringMatch7 = stringCompare.ContentsEqual(L"",true);
stringCompare.SetString(parsed.password());
bool stringMatch8 = stringCompare.ContentsEqual(L"",true);
stringCompare.SetString(parsed.frag());
bool stringMatch9 = stringCompare.ContentsEqual(L"",true);
if ((stringMatch5 != true) || (stringMatch6 != true) || (parsed.get_Port() != 443) || (stringMatch7 != true) || (stringMatch8 != true) || (stringMatch9 != true)) {
wprintf(L"Unexpected continuation URL; refusing to send the access token.\n");
return;
}
wprintf(L"Operation URL (save for resuming): %s\n",operationUrl);
wprintf(L"operationUsesStatus: %d\n",operationUsesStatus);
CkStringBuilderW retryText;
CkStringBuilderW retryNumber;
int attempt = 0;
bool complete = false;
while (((attempt < 30) && (complete != true))) {
// Bound the example's polling. A desktop UI should schedule this work in
// the background. A production worker should persist the URL and next poll time.
int waitSeconds = 5;
stringCompare.SetString(retryAfter);
bool stringMatch10 = stringCompare.ContentsEqual(L"",true);
if (stringMatch10 != true) {
retryText.SetString(retryAfter);
retryText.Trim();
waitSeconds = retryText.get_IntValue();
retryNumber.Clear();
retryNumber.AppendInt(waitSeconds);
if ((retryText.ContentsEqual(retryNumber.getAsString(),true) != true) || (waitSeconds < 0) || (waitSeconds > 60)) {
// Do not shorten a long server-requested delay. Save the operation
// URL above and resume later; an HTTP-date needs a scheduler too.
wprintf(L"Polling paused. Resume after Retry-After: %s\n",retryAfter);
return;
}
}
if (waitSeconds == 0) {
waitSeconds = 1;
}
http.SleepMs(waitSeconds * 1000);
success = http.HttpNoBody(L"GET",operationUrl,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() != 202) && (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;
}
attempt = attempt + 1;
retryAfter = response.getHeaderField(L"Retry-After");
if (operationUsesStatus == true) {
success = result.Load(response.bodyStr());
if (success != true) {
wprintf(L"Expected a well-formed JSON response.\n");
return;
}
if ((result.JsonTypeOf(L"status") != 1) || (result.StringOfEquals(L"status",L"",true) == true)) {
wprintf(L"Expected a nonempty operation status.\n");
return;
}
if ((result.StringOfEquals(L"status",L"Failed",true) == true) || (result.StringOfEquals(L"status",L"Canceled",true) == true)) {
wprintf(L"Provisioning did not succeed: %s\n",result.stringOf(L"status"));
wprintf(L"Error code: %s\n",result.stringOf(L"error.code"));
return;
}
complete = result.StringOfEquals(L"status",L"Succeeded",true);
}
else {
// Location: 202 is still pending; 200/204 completes the monitor request.
// Get the resource below to confirm its provisioningState.
complete = response.get_StatusCode() != 202;
}
}
if (complete != true) {
wprintf(L"Polling limit reached; provisioning may still be running.\n");
wprintf(L"Resume using the saved operation URL. Retry-After: %s\n",retryAfter);
return;
}
}
// Read the final resource for both immediate and asynchronous completion.
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.StringOfEquals(L"properties.provisioningState",L"Succeeded",true) != true) {
wprintf(L"Account is not confirmed ready. Provisioning state: %s\n",result.stringOf(L"properties.provisioningState"));
// If pending, GET this resource later; do not repeat PUT just to check status.
return;
}
if ((result.JsonTypeOf(L"id") != 1) || (result.StringOfEquals(L"id",L"",true) == true)) {
wprintf(L"Expected the provisioned account's resource ID.\n");
return;
}
wprintf(L"Storage account provisioning succeeded.\n");
wprintf(L"Resource ID: %s\n",result.stringOf(L"id"));
wprintf(L"Name: %s\n",result.stringOf(L"name"));
wprintf(L"Blob endpoint: %s\n",result.stringOf(L"properties.primaryEndpoints.blob"));
// Provisioning success does not grant blob/file data access. Configure data-plane
// roles and the account's network policy separately for the application that uses it.
}