Sample code for 30+ languages & platforms
Unicode C

Azure Create Storage Account

See more Azure Storage Accounts Examples

Demonstrates how to create an Azure storage account.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttpW http;
    HCkJsonObjectW jsonToken;
    HCkJsonObjectW jsonRequestBody;
    const wchar_t *url;
    HCkHttpResponseW resp;
    HCkJsonObjectW json;
    const wchar_t *skuName;
    const wchar_t *skuTier;
    const wchar_t *kind;
    const wchar_t *id;
    const wchar_t *name;
    const wchar_t *v_type;
    const wchar_t *location;
    const wchar_t *propertiesNetworkAclsBypass;
    const wchar_t *propertiesNetworkAclsDefaultAction;
    BOOL propertiesSupportsHttpsTrafficOnly;
    BOOL propertiesEncryptionServicesFileEnabled;
    const wchar_t *propertiesEncryptionServicesFileLastEnabledTime;
    BOOL propertiesEncryptionServicesBlobEnabled;
    const wchar_t *propertiesEncryptionServicesBlobLastEnabledTime;
    const wchar_t *propertiesEncryptionKeySource;
    const wchar_t *propertiesAccessTier;
    const wchar_t *propertiesProvisioningState;
    const wchar_t *propertiesCreationTime;
    const wchar_t *propertiesPrimaryEndpointsDfs;
    const wchar_t *propertiesPrimaryEndpointsWeb;
    const wchar_t *propertiesPrimaryEndpointsBlob;
    const wchar_t *propertiesPrimaryEndpointsQueue;
    const wchar_t *propertiesPrimaryEndpointsTable;
    const wchar_t *propertiesPrimaryEndpointsFile;
    const wchar_t *propertiesPrimaryLocation;
    const wchar_t *propertiesStatusOfPrimary;
    const wchar_t *propertiesSecondaryLocation;
    const wchar_t *propertiesStatusOfSecondary;
    int i;
    int count_i;

    success = FALSE;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttpW_Create();

    // Load an OAuth2 access token previously fetched by this example:  Get Azure OAuth2 Access Token
    jsonToken = CkJsonObjectW_Create();
    success = CkJsonObjectW_LoadFile(jsonToken,L"qa_data/tokens/azureToken.json");
    // Assuming success..
    CkHttpW_putAuthToken(http,CkJsonObjectW_stringOf(jsonToken,L"access_token"));
    wprintf(L"AuthToken: %s\n",CkHttpW_authToken(http));

    CkHttpW_putAccept(http,L"application/json");

    // Create the following JSON:

    // {
    //   "sku": {
    //     "name": "Standard_GRS"
    //   },
    //   "kind": "StorageV2",
    //   "location": "eastus2",
    // }

    // Use this online tool to generate the code from sample JSON: 
    // Generate Code to Create JSON

    jsonRequestBody = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(jsonRequestBody,L"sku.name",L"Standard_GRS");
    CkJsonObjectW_UpdateString(jsonRequestBody,L"kind",L"StorageV2");
    CkJsonObjectW_UpdateString(jsonRequestBody,L"location",L"eastus2");

    url = L"https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}?api-version=2018-02-01";

    resp = CkHttpResponseW_Create();
    success = CkHttpW_HttpJson(http,L"PUT",url,jsonRequestBody,L"application/json",resp);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(jsonToken);
        CkJsonObjectW_Dispose(jsonRequestBody);
        CkHttpResponseW_Dispose(resp);
        return;
    }

    wprintf(L"Response Status Code: %d\n",CkHttpResponseW_getStatusCode(resp));

    json = CkJsonObjectW_Create();
    CkJsonObjectW_Load(json,CkHttpResponseW_bodyStr(resp));
    CkJsonObjectW_putEmitCompact(json,FALSE);
    wprintf(L"%s\n",CkJsonObjectW_emit(json));

    if (CkHttpResponseW_getStatusCode(resp) >= 300) {
        wprintf(L"Failed.\n");
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(jsonToken);
        CkJsonObjectW_Dispose(jsonRequestBody);
        CkHttpResponseW_Dispose(resp);
        CkJsonObjectW_Dispose(json);
        return;
    }

    // Successful requests to create a new account return a 202 status code with an empty response body. The storage account is created asynchronously. 
    // If the account already exists or is being provisioned, the request response has a 200 return code with the configuration of the existing storage account in the response body.
    if (CkHttpResponseW_getStatusCode(resp) == 202) {
        wprintf(L"Azure-AsyncOperation: %s\n",CkHttpResponseW_getHeaderField(resp,L"Azure-AsyncOperation"));
    }

    if (CkHttpResponseW_getStatusCode(resp) == 200) {

        // Parse a response like this:

        // 	{
        // 	  "sku": {
        // 	    "name": "Standard_GRS",
        // 	    "tier": "Standard"
        // 	  },
        // 	  "kind": "StorageV2",
        // 	  "id": "/subscriptions/6c42643b-ebef-45f0-b917-b3583b84a57f/resourceGroups/gChilkat/providers/Microsoft.Storage/storageAccounts/chilkatsoftware",
        // 	  "name": "chilkatsoftware",
        // 	  "type": "Microsoft.Storage/storageAccounts",
        // 	  "location": "eastus2",
        // 	  "tags": {},
        // 	  "properties": {
        // 	    "networkAcls": {
        // 	      "bypass": "AzureServices",
        // 	      "virtualNetworkRules": [
        // 	      ],
        // 	      "ipRules": [
        // 	      ],
        // 	      "defaultAction": "Allow"
        // 	    },
        // 	    "supportsHttpsTrafficOnly": false,
        // 	    "encryption": {
        // 	      "services": {
        // 	        "file": {
        // 	          "enabled": true,
        // 	          "lastEnabledTime": "2019-05-14T22:18:33.2246670Z"
        // 	        },
        // 	        "blob": {
        // 	          "enabled": true,
        // 	          "lastEnabledTime": "2019-05-14T22:18:33.2246670Z"
        // 	        }
        // 	      },
        // 	      "keySource": "Microsoft.Storage"
        // 	    },
        // 	    "accessTier": "Hot",
        // 	    "provisioningState": "Succeeded",
        // 
        // 	    "creationTime": "2019-05-14T22:18:33.1309165Z",
        // 	    "primaryEndpoints": {
        // 	      "dfs": "https://chilkatsoftware.dfs.core.windows.net/",
        // 	      "web": "https://chilkatsoftware.z20.web.core.windows.net/",
        // 	      "blob": "https://chilkatsoftware.blob.core.windows.net/",
        // 	      "queue": "https://chilkatsoftware.queue.core.windows.net/",
        // 	      "table": "https://chilkatsoftware.table.core.windows.net/",
        // 	      "file": "https://chilkatsoftware.file.core.windows.net/"
        // 	    },
        // 	    "primaryLocation": "eastus2",
        // 	    "statusOfPrimary": "available",
        // 	    "secondaryLocation": "centralus",
        // 	    "statusOfSecondary": "available"
        // 	  }
        // 	}

        // Use this online tool to generate parsing code from sample JSON: 
        // Generate Parsing Code from JSON

        skuName = CkJsonObjectW_stringOf(json,L"sku.name");
        skuTier = CkJsonObjectW_stringOf(json,L"sku.tier");
        kind = CkJsonObjectW_stringOf(json,L"kind");
        id = CkJsonObjectW_stringOf(json,L"id");
        name = CkJsonObjectW_stringOf(json,L"name");
        v_type = CkJsonObjectW_stringOf(json,L"type");
        location = CkJsonObjectW_stringOf(json,L"location");
        propertiesNetworkAclsBypass = CkJsonObjectW_stringOf(json,L"properties.networkAcls.bypass");
        propertiesNetworkAclsDefaultAction = CkJsonObjectW_stringOf(json,L"properties.networkAcls.defaultAction");
        propertiesSupportsHttpsTrafficOnly = CkJsonObjectW_BoolOf(json,L"properties.supportsHttpsTrafficOnly");
        propertiesEncryptionServicesFileEnabled = CkJsonObjectW_BoolOf(json,L"properties.encryption.services.file.enabled");
        propertiesEncryptionServicesFileLastEnabledTime = CkJsonObjectW_stringOf(json,L"properties.encryption.services.file.lastEnabledTime");
        propertiesEncryptionServicesBlobEnabled = CkJsonObjectW_BoolOf(json,L"properties.encryption.services.blob.enabled");
        propertiesEncryptionServicesBlobLastEnabledTime = CkJsonObjectW_stringOf(json,L"properties.encryption.services.blob.lastEnabledTime");
        propertiesEncryptionKeySource = CkJsonObjectW_stringOf(json,L"properties.encryption.keySource");
        propertiesAccessTier = CkJsonObjectW_stringOf(json,L"properties.accessTier");
        propertiesProvisioningState = CkJsonObjectW_stringOf(json,L"properties.provisioningState");
        propertiesCreationTime = CkJsonObjectW_stringOf(json,L"properties.creationTime");
        propertiesPrimaryEndpointsDfs = CkJsonObjectW_stringOf(json,L"properties.primaryEndpoints.dfs");
        propertiesPrimaryEndpointsWeb = CkJsonObjectW_stringOf(json,L"properties.primaryEndpoints.web");
        propertiesPrimaryEndpointsBlob = CkJsonObjectW_stringOf(json,L"properties.primaryEndpoints.blob");
        propertiesPrimaryEndpointsQueue = CkJsonObjectW_stringOf(json,L"properties.primaryEndpoints.queue");
        propertiesPrimaryEndpointsTable = CkJsonObjectW_stringOf(json,L"properties.primaryEndpoints.table");
        propertiesPrimaryEndpointsFile = CkJsonObjectW_stringOf(json,L"properties.primaryEndpoints.file");
        propertiesPrimaryLocation = CkJsonObjectW_stringOf(json,L"properties.primaryLocation");
        propertiesStatusOfPrimary = CkJsonObjectW_stringOf(json,L"properties.statusOfPrimary");
        propertiesSecondaryLocation = CkJsonObjectW_stringOf(json,L"properties.secondaryLocation");
        propertiesStatusOfSecondary = CkJsonObjectW_stringOf(json,L"properties.statusOfSecondary");
    }

    wprintf(L"Success.\n");


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(jsonToken);
    CkJsonObjectW_Dispose(jsonRequestBody);
    CkHttpResponseW_Dispose(resp);
    CkJsonObjectW_Dispose(json);

    }