Sample code for 30+ languages & platforms
Unicode C

Azure List Storage Accounts

See more Azure Storage Accounts Examples

Demonstrates how to list Azure storage accounts.

Chilkat Unicode C Downloads

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

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttpW http;
    HCkJsonObjectW jsonToken;
    const wchar_t *url;
    const wchar_t *jsonResp;
    HCkJsonObjectW json;
    int i;
    int count_i;
    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 *propertiesProvisioningState;
    const wchar_t *propertiesCreationTime;
    const wchar_t *propertiesPrimaryEndpointsBlob;
    const wchar_t *propertiesPrimaryEndpointsQueue;
    const wchar_t *propertiesPrimaryEndpointsTable;
    const wchar_t *propertiesPrimaryEndpointsFile;
    const wchar_t *propertiesPrimaryLocation;
    const wchar_t *propertiesStatusOfPrimary;

    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");

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

    jsonResp = CkHttpW_quickGetStr(http,url);
    if (CkHttpW_getLastMethodSuccess(http) != TRUE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(jsonToken);
        return;
    }

    wprintf(L"Response Status Code: %d\n",CkHttpW_getLastStatus(http));

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

    if (CkHttpW_getLastStatus(http) != 200) {
        wprintf(L"Failed.\n");
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(jsonToken);
        CkJsonObjectW_Dispose(json);
        return;
    }

    // Sample output...
    // (See the parsing code below..)
    // 
    // Use this online tool to generate parsing code from sample JSON: 
    // Generate Parsing Code from JSON

    // {
    //   "value": [
    //     {
    //       "sku": {
    //         "name": "Standard_LRS",
    //         "tier": "Standard"
    //       },
    //       "kind": "Storage",
    //       "id": "/subscriptions/6c42643b-ebef-45e0-b917-b3583b84a57f/resourceGroups/gchilkat/providers/Microsoft.Storage/storageAccounts/chilkat",
    //       "name": "chilkat",
    //       "type": "Microsoft.Storage/storageAccounts",
    //       "location": "eastus",
    //       "tags": {},
    //       "properties": {
    //         "networkAcls": {
    //           "bypass": "AzureServices",
    //           "virtualNetworkRules": [
    //           ],
    //           "ipRules": [
    //           ],
    //           "defaultAction": "Allow"
    //         },
    //         "supportsHttpsTrafficOnly": true,
    //         "encryption": {
    //           "services": {
    //             "file": {
    //               "enabled": true,
    //               "lastEnabledTime": "2017-12-28T11:02:10.6840887Z"
    //             },
    //             "blob": {
    //               "enabled": true,
    //               "lastEnabledTime": "2017-12-28T11:02:10.6840887Z"
    //             }
    //           },
    //           "keySource": "Microsoft.Storage"
    //         },
    //         "provisioningState": "Succeeded",
    //         "creationTime": "2016-04-18T22:57:36.5377065Z",
    //         "primaryEndpoints": {
    //           "blob": "https://chilkat.blob.core.windows.net/",
    //           "queue": "https://chilkat.queue.core.windows.net/",
    //           "table": "https://chilkat.table.core.windows.net/",
    //           "file": "https://chilkat.file.core.windows.net/"
    //         },
    //         "primaryLocation": "eastus",
    //         "statusOfPrimary": "available"
    //       }
    //     }
    //   ]
    // }
    // 

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(json,L"value");
    while (i < count_i) {
        CkJsonObjectW_putI(json,i);
        skuName = CkJsonObjectW_stringOf(json,L"value[i].sku.name");
        skuTier = CkJsonObjectW_stringOf(json,L"value[i].sku.tier");
        kind = CkJsonObjectW_stringOf(json,L"value[i].kind");
        id = CkJsonObjectW_stringOf(json,L"value[i].id");
        name = CkJsonObjectW_stringOf(json,L"value[i].name");
        v_type = CkJsonObjectW_stringOf(json,L"value[i].type");
        location = CkJsonObjectW_stringOf(json,L"value[i].location");
        propertiesNetworkAclsBypass = CkJsonObjectW_stringOf(json,L"value[i].properties.networkAcls.bypass");
        propertiesNetworkAclsDefaultAction = CkJsonObjectW_stringOf(json,L"value[i].properties.networkAcls.defaultAction");
        propertiesSupportsHttpsTrafficOnly = CkJsonObjectW_BoolOf(json,L"value[i].properties.supportsHttpsTrafficOnly");
        propertiesEncryptionServicesFileEnabled = CkJsonObjectW_BoolOf(json,L"value[i].properties.encryption.services.file.enabled");
        propertiesEncryptionServicesFileLastEnabledTime = CkJsonObjectW_stringOf(json,L"value[i].properties.encryption.services.file.lastEnabledTime");
        propertiesEncryptionServicesBlobEnabled = CkJsonObjectW_BoolOf(json,L"value[i].properties.encryption.services.blob.enabled");
        propertiesEncryptionServicesBlobLastEnabledTime = CkJsonObjectW_stringOf(json,L"value[i].properties.encryption.services.blob.lastEnabledTime");
        propertiesEncryptionKeySource = CkJsonObjectW_stringOf(json,L"value[i].properties.encryption.keySource");
        propertiesProvisioningState = CkJsonObjectW_stringOf(json,L"value[i].properties.provisioningState");
        propertiesCreationTime = CkJsonObjectW_stringOf(json,L"value[i].properties.creationTime");
        propertiesPrimaryEndpointsBlob = CkJsonObjectW_stringOf(json,L"value[i].properties.primaryEndpoints.blob");
        propertiesPrimaryEndpointsQueue = CkJsonObjectW_stringOf(json,L"value[i].properties.primaryEndpoints.queue");
        propertiesPrimaryEndpointsTable = CkJsonObjectW_stringOf(json,L"value[i].properties.primaryEndpoints.table");
        propertiesPrimaryEndpointsFile = CkJsonObjectW_stringOf(json,L"value[i].properties.primaryEndpoints.file");
        propertiesPrimaryLocation = CkJsonObjectW_stringOf(json,L"value[i].properties.primaryLocation");
        propertiesStatusOfPrimary = CkJsonObjectW_stringOf(json,L"value[i].properties.statusOfPrimary");
        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(jsonToken);
    CkJsonObjectW_Dispose(json);

    }