Sample code for 30+ languages & platforms
Xojo Plugin Requires Chilkat v11.6.0+

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.

Microsoft API reference

Chilkat Xojo Plugin Downloads

Xojo Plugin
Dim success As Boolean
success = False

Dim stringCompare As New Chilkat.StringBuilder
//  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 Chilkat.JsonObject
token.Strict = True
success = token.LoadFile("qa_data/tokens/azureToken.json")
If (success <> True) Then
    System.DebugLog("Could not load the private Azure Resource Manager token file.")
    Return
End If

If ((token.JsonTypeOf("access_token") <> 1) Or (token.StringOfEquals("access_token","",True) = True)) Then
    System.DebugLog("A nonempty access_token string is required.")
    Return
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 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) Then
    System.DebugLog("Could not encode subscription ID.")
    Return
End If

Dim response As New Chilkat.HttpResponse
Dim result As New Chilkat.JsonObject
result.Strict = True
Dim parsed As New Chilkat.Url

//  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 <> True) Then
    System.DebugLog("Could not encode resource group.")
    Return
End If

success = http.SetUrlVar("accountName",accountName)
If (success <> True) Then
    System.DebugLog("Could not encode account name.")
    Return
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 Boolean
operationUsesStatus = False
//  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 Boolean
stringMatch1 = stringCompare.ContentsEqual("",True)
If (stringMatch1 = True) Then
    Dim request As New Chilkat.JsonObject
    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",True)
    success = request.UpdateString("properties.minimumTlsVersion","TLS1_2")
    success = request.UpdateBool("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("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
        System.DebugLog("No HTTP response. Inspect LastErrorText privately; it may contain credentials.")
        Return
    End If

    If ((response.StatusCode <> 200) And (response.StatusCode <> 202)) Then
        System.DebugLog("HTTP status: " + Str(response.StatusCode))
        System.DebugLog("Request ID: " + response.GetHeaderField("x-ms-request-id"))
        System.DebugLog("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
    End If

    If (success <> True) Then
        System.DebugLog("The HTTP response could not be read completely.")
        Return
    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 Boolean
        stringMatch2 = stringCompare.ContentsEqual("",True)
        If (stringMatch2 <> True) Then
            operationUsesStatus = True
        Else
            operationUrl = response.GetHeaderField("Location")
        End If

        success = stringCompare.SetString(operationUrl)
        Dim stringMatch3 As Boolean
        stringMatch3 = stringCompare.ContentsEqual("",True)
        If (stringMatch3 = True) Then
            System.DebugLog("Accepted, but no monitor URL was returned. Check the resource; do not assume success.")
            Return
        End If

        retryAfter = response.GetHeaderField("Retry-After")
    End If

End If

success = stringCompare.SetString(operationUrl)
Dim stringMatch4 As Boolean
stringMatch4 = stringCompare.ContentsEqual("",True)
If (stringMatch4 <> True) Then
    success = parsed.ParseUrl(operationUrl)
    If (success <> True) Then
        System.DebugLog("Missing or invalid continuation URL.")
        Return
    End If

    success = stringCompare.SetString(parsed.Scheme)
    Dim stringMatch5 As Boolean
    stringMatch5 = stringCompare.ContentsEqual("https",True)
    success = stringCompare.SetString(parsed.Host)
    Dim stringMatch6 As Boolean
    stringMatch6 = stringCompare.ContentsEqual("management.azure.com",True)
    success = stringCompare.SetString(parsed.Login)
    Dim stringMatch7 As Boolean
    stringMatch7 = stringCompare.ContentsEqual("",True)
    success = stringCompare.SetString(parsed.Password)
    Dim stringMatch8 As Boolean
    stringMatch8 = stringCompare.ContentsEqual("",True)
    success = stringCompare.SetString(parsed.Frag)
    Dim stringMatch9 As Boolean
    stringMatch9 = stringCompare.ContentsEqual("",True)
    If ((stringMatch5 <> True) Or (stringMatch6 <> True) Or (parsed.Port <> 443) Or (stringMatch7 <> True) Or (stringMatch8 <> True) Or (stringMatch9 <> True)) Then
        System.DebugLog("Unexpected continuation URL; refusing to send the access token.")
        Return
    End If

    System.DebugLog("Operation URL (save for resuming): " + operationUrl)
    System.DebugLog("operationUsesStatus: " + Str(operationUsesStatus))
    Dim retryText As New Chilkat.StringBuilder
    Dim retryNumber As New Chilkat.StringBuilder
    Dim attempt As Int32
    attempt = 0
    Dim complete As Boolean
    complete = False
    While ((attempt < 30) And (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.
        Dim waitSeconds As Int32
        waitSeconds = 5
        success = stringCompare.SetString(retryAfter)
        Dim stringMatch10 As Boolean
        stringMatch10 = stringCompare.ContentsEqual("",True)
        If (stringMatch10 <> True) Then
            success = retryText.SetString(retryAfter)
            success = retryText.Trim()
            waitSeconds = retryText.IntValue
            retryNumber.Clear 
            success = retryNumber.AppendInt(waitSeconds)
            If ((retryText.ContentsEqual(retryNumber.GetAsString(),True) <> True) 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.
                System.DebugLog("Polling paused. Resume after Retry-After: " + retryAfter)
                Return
            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
            System.DebugLog("No HTTP response. Inspect LastErrorText privately; it may contain credentials.")
            Return
        End If

        If ((response.StatusCode <> 200) And (response.StatusCode <> 202) And (response.StatusCode <> 204)) Then
            System.DebugLog("HTTP status: " + Str(response.StatusCode))
            System.DebugLog("Request ID: " + response.GetHeaderField("x-ms-request-id"))
            System.DebugLog("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
        End If

        If (success <> True) Then
            System.DebugLog("The HTTP response could not be read completely.")
            Return
        End If

        attempt = attempt + 1
        retryAfter = response.GetHeaderField("Retry-After")
        If (operationUsesStatus = True) Then
            success = result.Load(response.BodyStr)
            If (success <> True) Then
                System.DebugLog("Expected a well-formed JSON response.")
                Return
            End If

            If ((result.JsonTypeOf("status") <> 1) Or (result.StringOfEquals("status","",True) = True)) Then
                System.DebugLog("Expected a nonempty operation status.")
                Return
            End If

            If ((result.StringOfEquals("status","Failed",True) = True) Or (result.StringOfEquals("status","Canceled",True) = True)) Then
                System.DebugLog("Provisioning did not succeed: " + result.StringOf("status"))
                System.DebugLog("Error code: " + result.StringOf("error.code"))
                Return
            End If

            complete = result.StringOfEquals("status","Succeeded",True)
        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

    Wend
    If (complete <> True) Then
        System.DebugLog("Polling limit reached; provisioning may still be running.")
        System.DebugLog("Resume using the saved operation URL. Retry-After: " + retryAfter)
        Return
    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
    System.DebugLog("No HTTP response. Inspect LastErrorText privately; it may contain credentials.")
    Return
End If

If ((response.StatusCode <> 200)) Then
    System.DebugLog("HTTP status: " + Str(response.StatusCode))
    System.DebugLog("Request ID: " + response.GetHeaderField("x-ms-request-id"))
    System.DebugLog("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
End If

If (success <> True) Then
    System.DebugLog("The HTTP response could not be read completely.")
    Return
End If

success = result.Load(response.BodyStr)
If (success <> True) Then
    System.DebugLog("Expected a well-formed JSON response.")
    Return
End If

If (result.StringOfEquals("properties.provisioningState","Succeeded",True) <> True) Then
    System.DebugLog("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.
    Return
End If

If ((result.JsonTypeOf("id") <> 1) Or (result.StringOfEquals("id","",True) = True)) Then
    System.DebugLog("Expected the provisioned account's resource ID.")
    Return
End If

System.DebugLog("Storage account provisioning succeeded.")
System.DebugLog("Resource ID: " + result.StringOf("id"))
System.DebugLog("Name: " + result.StringOf("name"))
System.DebugLog("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.