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 Visual Basic 6.0 Downloads
Dim success As Long
success = 0
Dim stringCompare As New ChilkatStringBuilder
' 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.
Dim token As New ChilkatJsonObject
token.Strict = 1
success = token.LoadFile("qa_data/tokens/azureToken.json")
If (success <> 1) Then
Debug.Print "Could not load the private Azure Resource Manager token file."
Exit Sub
End If
If ((token.JsonTypeOf("access_token") <> 1) Or (token.StringOfEquals("access_token","",1) = 1)) Then
Debug.Print "A nonempty access_token string is required."
Exit Sub
End If
' Use your subscription ID as a string. The all-zero value is only a placeholder.
Dim subscriptionId As String
subscriptionId = "00000000-0000-0000-0000-000000000000"
Dim http As New ChilkatHttp
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
Debug.Print "Could not encode subscription ID."
Exit Sub
End If
Dim response As New ChilkatHttpResponse
Dim result As New ChilkatJsonObject
result.Strict = 1
Dim parsed As New ChilkatUrl
' Choose an EXISTING resource group and a globally unique 3-24 character name
' containing only lowercase letters and digits. Choose a supported Azure region.
Dim resourceGroupName As String
resourceGroupName = "my-resource-group"
Dim accountName As String
accountName = "youruniquestorageaccount"
Dim location As String
location = "eastus"
success = http.SetUrlVar("resourceGroupName",resourceGroupName)
If (success <> 1) Then
Debug.Print "Could not encode resource group."
Exit Sub
End If
success = http.SetUrlVar("accountName",accountName)
If (success <> 1) Then
Debug.Print "Could not encode account name."
Exit Sub
End If
Dim resourceUrl As String
resourceUrl = "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.
Dim operationUrl As String
operationUrl = ""
Dim operationUsesStatus As Long
operationUsesStatus = 0
' When resuming, first wait for the Retry-After interval from the prior response.
Dim retryAfter As String
retryAfter = ""
success = stringCompare.SetString(operationUrl)
Dim stringMatch1 As Long
stringMatch1 = stringCompare.ContentsEqual("",1)
If (stringMatch1 = 1) Then
Dim request As New ChilkatJsonObject
success = request.UpdateString("location",location)
success = request.UpdateString("kind","StorageV2")
success = request.UpdateString("sku.name","Standard_LRS")
success = request.UpdateString("properties.accessTier","Hot")
success = request.UpdateBool("properties.supportsHttpsTrafficOnly",1)
success = request.UpdateString("properties.minimumTlsVersion","TLS1_2")
success = request.UpdateBool("properties.allowBlobPublicAccess",0)
' 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("PUT",resourceUrl,request,"application/json",response)
' If transport fails, inspect this resource before deciding to submit again;
' Azure may already have accepted the PUT.
If (response.StatusCode = 0) Then
Debug.Print "No HTTP response. Inspect LastErrorText privately; it may contain credentials."
Exit Sub
End If
If ((response.StatusCode <> 200) And (response.StatusCode <> 202)) Then
Debug.Print "HTTP status: " & response.StatusCode
Debug.Print "Request ID: " & response.GetHeaderField("x-ms-request-id")
Debug.Print "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.
Exit Sub
End If
If (success <> 1) Then
Debug.Print "The HTTP response could not be read completely."
Exit Sub
End If
If (response.StatusCode = 202) Then
' An accepted operation can have an EMPTY body. Do not try to parse it.
operationUrl = response.GetHeaderField("Azure-AsyncOperation")
success = stringCompare.SetString(operationUrl)
Dim stringMatch2 As Long
stringMatch2 = stringCompare.ContentsEqual("",1)
If (stringMatch2 <> 1) Then
operationUsesStatus = 1
Else
operationUrl = response.GetHeaderField("Location")
End If
success = stringCompare.SetString(operationUrl)
Dim stringMatch3 As Long
stringMatch3 = stringCompare.ContentsEqual("",1)
If (stringMatch3 = 1) Then
Debug.Print "Accepted, but no monitor URL was returned. Check the resource; do not assume success."
Exit Sub
End If
retryAfter = response.GetHeaderField("Retry-After")
End If
End If
success = stringCompare.SetString(operationUrl)
Dim stringMatch4 As Long
stringMatch4 = stringCompare.ContentsEqual("",1)
If (stringMatch4 <> 1) Then
success = parsed.ParseUrl(operationUrl)
If (success <> 1) Then
Debug.Print "Missing or invalid continuation URL."
Exit Sub
End If
success = stringCompare.SetString(parsed.Scheme)
Dim stringMatch5 As Long
stringMatch5 = stringCompare.ContentsEqual("https",1)
success = stringCompare.SetString(parsed.Host)
Dim stringMatch6 As Long
stringMatch6 = stringCompare.ContentsEqual("management.azure.com",1)
success = stringCompare.SetString(parsed.Login)
Dim stringMatch7 As Long
stringMatch7 = stringCompare.ContentsEqual("",1)
success = stringCompare.SetString(parsed.Password)
Dim stringMatch8 As Long
stringMatch8 = stringCompare.ContentsEqual("",1)
success = stringCompare.SetString(parsed.Frag)
Dim stringMatch9 As Long
stringMatch9 = stringCompare.ContentsEqual("",1)
If ((stringMatch5 <> 1) Or (stringMatch6 <> 1) Or (parsed.Port <> 443) Or (stringMatch7 <> 1) Or (stringMatch8 <> 1) Or (stringMatch9 <> 1)) Then
Debug.Print "Unexpected continuation URL; refusing to send the access token."
Exit Sub
End If
Debug.Print "Operation URL (save for resuming): " & operationUrl
Debug.Print "operationUsesStatus: " & operationUsesStatus
Dim retryText As New ChilkatStringBuilder
Dim retryNumber As New ChilkatStringBuilder
Dim attempt As Long
attempt = 0
Dim complete As Long
complete = 0
Do While ((attempt < 30) And (complete <> 1))
' 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.
Dim waitSeconds As Long
waitSeconds = 5
success = stringCompare.SetString(retryAfter)
Dim stringMatch10 As Long
stringMatch10 = stringCompare.ContentsEqual("",1)
If (stringMatch10 <> 1) Then
success = retryText.SetString(retryAfter)
success = retryText.Trim()
waitSeconds = retryText.IntValue
retryNumber.Clear
success = retryNumber.AppendInt(waitSeconds)
If ((retryText.ContentsEqual(retryNumber.GetAsString(),1) <> 1) Or (waitSeconds < 0) Or (waitSeconds > 60)) Then
' Do not shorten a long server-requested delay. Save the operation
' URL above and resume later; an HTTP-date needs a scheduler too.
Debug.Print "Polling paused. Resume after Retry-After: " & retryAfter
Exit Sub
End If
End If
If (waitSeconds = 0) Then
waitSeconds = 1
End If
http.SleepMs waitSeconds * 1000
success = http.HttpNoBody("GET",operationUrl,response)
If (response.StatusCode = 0) Then
Debug.Print "No HTTP response. Inspect LastErrorText privately; it may contain credentials."
Exit Sub
End If
If ((response.StatusCode <> 200) And (response.StatusCode <> 202) And (response.StatusCode <> 204)) Then
Debug.Print "HTTP status: " & response.StatusCode
Debug.Print "Request ID: " & response.GetHeaderField("x-ms-request-id")
Debug.Print "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.
Exit Sub
End If
If (success <> 1) Then
Debug.Print "The HTTP response could not be read completely."
Exit Sub
End If
attempt = attempt + 1
retryAfter = response.GetHeaderField("Retry-After")
If (operationUsesStatus = 1) Then
success = result.Load(response.BodyStr)
If (success <> 1) Then
Debug.Print "Expected a well-formed JSON response."
Exit Sub
End If
If ((result.JsonTypeOf("status") <> 1) Or (result.StringOfEquals("status","",1) = 1)) Then
Debug.Print "Expected a nonempty operation status."
Exit Sub
End If
If ((result.StringOfEquals("status","Failed",1) = 1) Or (result.StringOfEquals("status","Canceled",1) = 1)) Then
Debug.Print "Provisioning did not succeed: " & result.StringOf("status")
Debug.Print "Error code: " & result.StringOf("error.code")
Exit Sub
End If
complete = result.StringOfEquals("status","Succeeded",1)
Else
' Location: 202 is still pending; 200/204 completes the monitor request.
' Get the resource below to confirm its provisioningState.
complete = response.StatusCode <> 202
End If
Loop
If (complete <> 1) Then
Debug.Print "Polling limit reached; provisioning may still be running."
Debug.Print "Resume using the saved operation URL. Retry-After: " & retryAfter
Exit Sub
End If
End If
' Read the final resource for both immediate and asynchronous completion.
success = http.HttpNoBody("GET",resourceUrl,response)
If (response.StatusCode = 0) Then
Debug.Print "No HTTP response. Inspect LastErrorText privately; it may contain credentials."
Exit Sub
End If
If ((response.StatusCode <> 200)) Then
Debug.Print "HTTP status: " & response.StatusCode
Debug.Print "Request ID: " & response.GetHeaderField("x-ms-request-id")
Debug.Print "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.
Exit Sub
End If
If (success <> 1) Then
Debug.Print "The HTTP response could not be read completely."
Exit Sub
End If
success = result.Load(response.BodyStr)
If (success <> 1) Then
Debug.Print "Expected a well-formed JSON response."
Exit Sub
End If
If (result.StringOfEquals("properties.provisioningState","Succeeded",1) <> 1) Then
Debug.Print "Account is not confirmed ready. Provisioning state: " & result.StringOf("properties.provisioningState")
' If pending, GET this resource later; do not repeat PUT just to check status.
Exit Sub
End If
If ((result.JsonTypeOf("id") <> 1) Or (result.StringOfEquals("id","",1) = 1)) Then
Debug.Print "Expected the provisioned account's resource ID."
Exit Sub
End If
Debug.Print "Storage account provisioning succeeded."
Debug.Print "Resource ID: " & result.StringOf("id")
Debug.Print "Name: " & result.StringOf("name")
Debug.Print "Blob endpoint: " & result.StringOf("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.