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 <CkHttpW.h>
#include <CkJsonObjectW.h>

void ChilkatSample(void)
    {
    bool success = false;

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

    CkHttpW http;

    // Load an OAuth2 access token previously fetched by this example:  Get Azure OAuth2 Access Token
    CkJsonObjectW jsonToken;
    success = jsonToken.LoadFile(L"qa_data/tokens/azureToken.json");
    // Assuming success..
    http.put_AuthToken(jsonToken.stringOf(L"access_token"));
    wprintf(L"AuthToken: %s\n",http.authToken());

    http.put_Accept(L"application/json");

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

    const wchar_t *jsonResp = http.quickGetStr(url);
    if (http.get_LastMethodSuccess() != true) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

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

    CkJsonObjectW json;
    json.Load(jsonResp);
    json.put_EmitCompact(false);
    wprintf(L"%s\n",json.emit());

    if (http.get_LastStatus() != 200) {
        wprintf(L"Failed.\n");
        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"
    //       }
    //     }
    //   ]
    // }
    // 

    int i;
    int count_i;
    const wchar_t *skuName = 0;
    const wchar_t *skuTier = 0;
    const wchar_t *kind = 0;
    const wchar_t *id = 0;
    const wchar_t *name = 0;
    const wchar_t *v_type = 0;
    const wchar_t *location = 0;
    const wchar_t *propertiesNetworkAclsBypass = 0;
    const wchar_t *propertiesNetworkAclsDefaultAction = 0;
    bool propertiesSupportsHttpsTrafficOnly;
    bool propertiesEncryptionServicesFileEnabled;
    const wchar_t *propertiesEncryptionServicesFileLastEnabledTime = 0;
    bool propertiesEncryptionServicesBlobEnabled;
    const wchar_t *propertiesEncryptionServicesBlobLastEnabledTime = 0;
    const wchar_t *propertiesEncryptionKeySource = 0;
    const wchar_t *propertiesProvisioningState = 0;
    const wchar_t *propertiesCreationTime = 0;
    const wchar_t *propertiesPrimaryEndpointsBlob = 0;
    const wchar_t *propertiesPrimaryEndpointsQueue = 0;
    const wchar_t *propertiesPrimaryEndpointsTable = 0;
    const wchar_t *propertiesPrimaryEndpointsFile = 0;
    const wchar_t *propertiesPrimaryLocation = 0;
    const wchar_t *propertiesStatusOfPrimary = 0;

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