Sample code for 30+ languages & platforms
C

Azure List Storage Accounts

See more Azure Storage Accounts Examples

Demonstrates how to list Azure storage accounts.

Chilkat C Downloads

C
#include <C_CkHttp.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttp http;
    HCkJsonObject jsonToken;
    const char *url;
    const char *jsonResp;
    HCkJsonObject json;
    int i;
    int count_i;
    const char *skuName;
    const char *skuTier;
    const char *kind;
    const char *id;
    const char *name;
    const char *v_type;
    const char *location;
    const char *propertiesNetworkAclsBypass;
    const char *propertiesNetworkAclsDefaultAction;
    BOOL propertiesSupportsHttpsTrafficOnly;
    BOOL propertiesEncryptionServicesFileEnabled;
    const char *propertiesEncryptionServicesFileLastEnabledTime;
    BOOL propertiesEncryptionServicesBlobEnabled;
    const char *propertiesEncryptionServicesBlobLastEnabledTime;
    const char *propertiesEncryptionKeySource;
    const char *propertiesProvisioningState;
    const char *propertiesCreationTime;
    const char *propertiesPrimaryEndpointsBlob;
    const char *propertiesPrimaryEndpointsQueue;
    const char *propertiesPrimaryEndpointsTable;
    const char *propertiesPrimaryEndpointsFile;
    const char *propertiesPrimaryLocation;
    const char *propertiesStatusOfPrimary;

    success = FALSE;

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

    http = CkHttp_Create();

    //  Load an OAuth2 access token previously fetched by this example:  Get Azure OAuth2 Access Token
    jsonToken = CkJsonObject_Create();
    success = CkJsonObject_LoadFile(jsonToken,"qa_data/tokens/azureToken.json");
    //  Assuming success..
    CkHttp_putAuthToken(http,CkJsonObject_stringOf(jsonToken,"access_token"));
    printf("AuthToken: %s\n",CkHttp_authToken(http));

    CkHttp_putAccept(http,"application/json");

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

    jsonResp = CkHttp_quickGetStr(http,url);
    if (CkHttp_getLastMethodSuccess(http) != TRUE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(jsonToken);
        return;
    }

    printf("Response Status Code: %d\n",CkHttp_getLastStatus(http));

    json = CkJsonObject_Create();
    CkJsonObject_Load(json,jsonResp);
    CkJsonObject_putEmitCompact(json,FALSE);
    printf("%s\n",CkJsonObject_emit(json));

    if (CkHttp_getLastStatus(http) != 200) {
        printf("Failed.\n");
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(jsonToken);
        CkJsonObject_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 = CkJsonObject_SizeOfArray(json,"value");
    while (i < count_i) {
        CkJsonObject_putI(json,i);
        skuName = CkJsonObject_stringOf(json,"value[i].sku.name");
        skuTier = CkJsonObject_stringOf(json,"value[i].sku.tier");
        kind = CkJsonObject_stringOf(json,"value[i].kind");
        id = CkJsonObject_stringOf(json,"value[i].id");
        name = CkJsonObject_stringOf(json,"value[i].name");
        v_type = CkJsonObject_stringOf(json,"value[i].type");
        location = CkJsonObject_stringOf(json,"value[i].location");
        propertiesNetworkAclsBypass = CkJsonObject_stringOf(json,"value[i].properties.networkAcls.bypass");
        propertiesNetworkAclsDefaultAction = CkJsonObject_stringOf(json,"value[i].properties.networkAcls.defaultAction");
        propertiesSupportsHttpsTrafficOnly = CkJsonObject_BoolOf(json,"value[i].properties.supportsHttpsTrafficOnly");
        propertiesEncryptionServicesFileEnabled = CkJsonObject_BoolOf(json,"value[i].properties.encryption.services.file.enabled");
        propertiesEncryptionServicesFileLastEnabledTime = CkJsonObject_stringOf(json,"value[i].properties.encryption.services.file.lastEnabledTime");
        propertiesEncryptionServicesBlobEnabled = CkJsonObject_BoolOf(json,"value[i].properties.encryption.services.blob.enabled");
        propertiesEncryptionServicesBlobLastEnabledTime = CkJsonObject_stringOf(json,"value[i].properties.encryption.services.blob.lastEnabledTime");
        propertiesEncryptionKeySource = CkJsonObject_stringOf(json,"value[i].properties.encryption.keySource");
        propertiesProvisioningState = CkJsonObject_stringOf(json,"value[i].properties.provisioningState");
        propertiesCreationTime = CkJsonObject_stringOf(json,"value[i].properties.creationTime");
        propertiesPrimaryEndpointsBlob = CkJsonObject_stringOf(json,"value[i].properties.primaryEndpoints.blob");
        propertiesPrimaryEndpointsQueue = CkJsonObject_stringOf(json,"value[i].properties.primaryEndpoints.queue");
        propertiesPrimaryEndpointsTable = CkJsonObject_stringOf(json,"value[i].properties.primaryEndpoints.table");
        propertiesPrimaryEndpointsFile = CkJsonObject_stringOf(json,"value[i].properties.primaryEndpoints.file");
        propertiesPrimaryLocation = CkJsonObject_stringOf(json,"value[i].properties.primaryLocation");
        propertiesStatusOfPrimary = CkJsonObject_stringOf(json,"value[i].properties.statusOfPrimary");
        i = i + 1;
    }



    CkHttp_Dispose(http);
    CkJsonObject_Dispose(jsonToken);
    CkJsonObject_Dispose(json);

    }