Sample code for 30+ languages & platforms
Objective-C 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 Objective-C Downloads

Objective-C
#import <CkoStringBuilder.h>
#import <CkoJsonObject.h>
#import <NSString.h>
#import <CkoHttp.h>
#import <CkoHttpResponse.h>
#import <CkoUrl.h>

BOOL success = NO;

CkoStringBuilder *stringCompare = [[CkoStringBuilder alloc] init];
//  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.
CkoJsonObject *token = [[CkoJsonObject alloc] init];
token.Strict = YES;
success = [token LoadFile: @"qa_data/tokens/azureToken.json"];
if (success != YES) {
    NSLog(@"%@",@"Could not load the private Azure Resource Manager token file.");
    return;
}

if (([[token JsonTypeOf: @"access_token"] intValue] != 1) || ([token StringOfEquals: @"access_token" value: @"" caseSensitive: YES] == YES)) {
    NSLog(@"%@",@"A nonempty access_token string is required.");
    return;
}

//  Use your subscription ID as a string. The all-zero value is only a placeholder.
NSString *subscriptionId = @"00000000-0000-0000-0000-000000000000";
CkoHttp *http = [[CkoHttp alloc] init];
http.AuthToken = [token StringOf: @"access_token"];
http.Accept = @"application/json";
http.RequireSslCertVerify = YES;
http.FollowRedirects = NO;
http.ConnectTimeout = [NSNumber numberWithInt:30];
http.ReadTimeout = [NSNumber numberWithInt:60];
success = [http SetUrlVar: @"subscriptionId" value: subscriptionId];
if (success != YES) {
    NSLog(@"%@",@"Could not encode subscription ID.");
    return;
}

CkoHttpResponse *response = [[CkoHttpResponse alloc] init];
CkoJsonObject *result = [[CkoJsonObject alloc] init];
result.Strict = YES;
CkoUrl *parsed = [[CkoUrl alloc] init];

//  Choose an EXISTING resource group and a globally unique 3-24 character name
//  containing only lowercase letters and digits. Choose a supported Azure region.
NSString *resourceGroupName = @"my-resource-group";
NSString *accountName = @"youruniquestorageaccount";
NSString *location = @"eastus";
success = [http SetUrlVar: @"resourceGroupName" value: resourceGroupName];
if (success != YES) {
    NSLog(@"%@",@"Could not encode resource group.");
    return;
}

success = [http SetUrlVar: @"accountName" value: accountName];
if (success != YES) {
    NSLog(@"%@",@"Could not encode account name.");
    return;
}

NSString *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.
NSString *operationUrl = @"";
BOOL operationUsesStatus = NO;
//  When resuming, first wait for the Retry-After interval from the prior response.
NSString *retryAfter = @"";

[stringCompare SetString: operationUrl];
BOOL stringMatch1 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (stringMatch1 == YES) {
    CkoJsonObject *request = [[CkoJsonObject alloc] init];
    [request UpdateString: @"location" value: location];
    [request UpdateString: @"kind" value: @"StorageV2"];
    [request UpdateString: @"sku.name" value: @"Standard_LRS"];
    [request UpdateString: @"properties.accessTier" value: @"Hot"];
    [request UpdateBool: @"properties.supportsHttpsTrafficOnly" value: YES];
    [request UpdateString: @"properties.minimumTlsVersion" value: @"TLS1_2"];
    [request UpdateBool: @"properties.allowBlobPublicAccess" value: NO];

    //  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" url: resourceUrl json: request contentType: @"application/json" response: response];
    //  If transport fails, inspect this resource before deciding to submit again;
    //  Azure may already have accepted the PUT.
    if ([response.StatusCode intValue] == 0) {
        NSLog(@"%@",@"No HTTP response. Inspect LastErrorText privately; it may contain credentials.");
        return;
    }

    if (([response.StatusCode intValue] != 200) && ([response.StatusCode intValue] != 202)) {
        NSLog(@"%@%d",@"HTTP status: ",[response.StatusCode intValue]);
        NSLog(@"%@%@",@"Request ID: ",[response GetHeaderField: @"x-ms-request-id"]);
        NSLog(@"%@%@",@"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 != YES) {
        NSLog(@"%@",@"The HTTP response could not be read completely.");
        return;
    }

    if ([response.StatusCode intValue] == 202) {
        //  An accepted operation can have an EMPTY body. Do not try to parse it.
        operationUrl = [response GetHeaderField: @"Azure-AsyncOperation"];
        [stringCompare SetString: operationUrl];
        BOOL stringMatch2 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
        if (stringMatch2 != YES) {
            operationUsesStatus = YES;
        }
        else {
            operationUrl = [response GetHeaderField: @"Location"];
        }

        [stringCompare SetString: operationUrl];
        BOOL stringMatch3 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
        if (stringMatch3 == YES) {
            NSLog(@"%@",@"Accepted, but no monitor URL was returned. Check the resource; do not assume success.");
            return;
        }

        retryAfter = [response GetHeaderField: @"Retry-After"];
    }

}

[stringCompare SetString: operationUrl];
BOOL stringMatch4 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (stringMatch4 != YES) {
    success = [parsed ParseUrl: operationUrl];
    if (success != YES) {
        NSLog(@"%@",@"Missing or invalid continuation URL.");
        return;
    }

    [stringCompare SetString: parsed.Scheme];
    BOOL stringMatch5 = [stringCompare ContentsEqual: @"https" caseSensitive: YES];
    [stringCompare SetString: parsed.Host];
    BOOL stringMatch6 = [stringCompare ContentsEqual: @"management.azure.com" caseSensitive: YES];
    [stringCompare SetString: parsed.Login];
    BOOL stringMatch7 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
    [stringCompare SetString: parsed.Password];
    BOOL stringMatch8 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
    [stringCompare SetString: parsed.Frag];
    BOOL stringMatch9 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
    if ((stringMatch5 != YES) || (stringMatch6 != YES) || ([parsed.Port intValue] != 443) || (stringMatch7 != YES) || (stringMatch8 != YES) || (stringMatch9 != YES)) {
        NSLog(@"%@",@"Unexpected continuation URL; refusing to send the access token.");
        return;
    }

    NSLog(@"%@%@",@"Operation URL (save for resuming): ",operationUrl);
    NSLog(@"%@%d",@"operationUsesStatus: ",operationUsesStatus);
    CkoStringBuilder *retryText = [[CkoStringBuilder alloc] init];
    CkoStringBuilder *retryNumber = [[CkoStringBuilder alloc] init];
    int attempt = 0;
    BOOL complete = NO;
    while (((attempt < 30) && (complete != YES))) {
        //  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: @"" caseSensitive: YES];
        if (stringMatch10 != YES) {
            [retryText SetString: retryAfter];
            [retryText Trim];
            waitSeconds = [retryText.IntValue intValue];
            [retryNumber Clear];
            [retryNumber AppendInt: [NSNumber numberWithInt: waitSeconds]];
            if (([retryText ContentsEqual: [retryNumber GetAsString] caseSensitive: YES] != YES) || (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.
                NSLog(@"%@%@",@"Polling paused. Resume after Retry-After: ",retryAfter);
                return;
            }

        }

        if (waitSeconds == 0) {
            waitSeconds = 1;
        }

        [http SleepMs: [NSNumber numberWithInt: (waitSeconds * 1000)]];
        success = [http HttpNoBody: @"GET" url: operationUrl response: response];
        if ([response.StatusCode intValue] == 0) {
            NSLog(@"%@",@"No HTTP response. Inspect LastErrorText privately; it may contain credentials.");
            return;
        }

        if (([response.StatusCode intValue] != 200) && ([response.StatusCode intValue] != 202) && ([response.StatusCode intValue] != 204)) {
            NSLog(@"%@%d",@"HTTP status: ",[response.StatusCode intValue]);
            NSLog(@"%@%@",@"Request ID: ",[response GetHeaderField: @"x-ms-request-id"]);
            NSLog(@"%@%@",@"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 != YES) {
            NSLog(@"%@",@"The HTTP response could not be read completely.");
            return;
        }

        attempt = attempt + 1;
        retryAfter = [response GetHeaderField: @"Retry-After"];
        if (operationUsesStatus == YES) {
            success = [result Load: response.BodyStr];
            if (success != YES) {
                NSLog(@"%@",@"Expected a well-formed JSON response.");
                return;
            }

            if (([[result JsonTypeOf: @"status"] intValue] != 1) || ([result StringOfEquals: @"status" value: @"" caseSensitive: YES] == YES)) {
                NSLog(@"%@",@"Expected a nonempty operation status.");
                return;
            }

            if (([result StringOfEquals: @"status" value: @"Failed" caseSensitive: YES] == YES) || ([result StringOfEquals: @"status" value: @"Canceled" caseSensitive: YES] == YES)) {
                NSLog(@"%@%@",@"Provisioning did not succeed: ",[result StringOf: @"status"]);
                NSLog(@"%@%@",@"Error code: ",[result StringOf: @"error.code"]);
                return;
            }

            complete = [result StringOfEquals: @"status" value: @"Succeeded" caseSensitive: YES];
        }
        else {
            //  Location: 202 is still pending; 200/204 completes the monitor request.
            //  Get the resource below to confirm its provisioningState.
            complete = [response.StatusCode intValue] != 202;
        }

    }

    if (complete != YES) {
        NSLog(@"%@",@"Polling limit reached; provisioning may still be running.");
        NSLog(@"%@%@",@"Resume using the saved operation URL. Retry-After: ",retryAfter);
        return;
    }

}

//  Read the final resource for both immediate and asynchronous completion.
success = [http HttpNoBody: @"GET" url: resourceUrl response: response];
if ([response.StatusCode intValue] == 0) {
    NSLog(@"%@",@"No HTTP response. Inspect LastErrorText privately; it may contain credentials.");
    return;
}

if (([response.StatusCode intValue] != 200)) {
    NSLog(@"%@%d",@"HTTP status: ",[response.StatusCode intValue]);
    NSLog(@"%@%@",@"Request ID: ",[response GetHeaderField: @"x-ms-request-id"]);
    NSLog(@"%@%@",@"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 != YES) {
    NSLog(@"%@",@"The HTTP response could not be read completely.");
    return;
}

success = [result Load: response.BodyStr];
if (success != YES) {
    NSLog(@"%@",@"Expected a well-formed JSON response.");
    return;
}

if ([result StringOfEquals: @"properties.provisioningState" value: @"Succeeded" caseSensitive: YES] != YES) {
    NSLog(@"%@%@",@"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;
}

if (([[result JsonTypeOf: @"id"] intValue] != 1) || ([result StringOfEquals: @"id" value: @"" caseSensitive: YES] == YES)) {
    NSLog(@"%@",@"Expected the provisioned account's resource ID.");
    return;
}

NSLog(@"%@",@"Storage account provisioning succeeded.");
NSLog(@"%@%@",@"Resource ID: ",[result StringOf: @"id"]);
NSLog(@"%@%@",@"Name: ",[result StringOf: @"name"]);
NSLog(@"%@%@",@"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.