Sample code for 30+ languages & platforms
Unicode C++ Requires Chilkat v11.6.0+

Azure Storage Accounts: List Storage Accounts in a Resource Group

See more Azure Storage Accounts Examples

Lists accounts in one existing resource group. Requires account read permission at the appropriate scope. Follows opaque continuation URLs without rewriting their query strings and handles empty pages, repeated links, and incomplete results. Resource IDs remain strings; no account keys are requested.

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 Unicode C++ Downloads

Unicode C++
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>
#include <CkHttpW.h>
#include <CkHttpResponseW.h>
#include <CkUrlW.h>
#include <CkHashtableW.h>
#include <CkJsonArrayW.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkStringBuilderW stringCompare;
    //  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.
    CkJsonObjectW token;
    token.put_Strict(true);
    success = token.LoadFile(L"qa_data/tokens/azureToken.json");
    if (success != true) {
        wprintf(L"Could not load the private Azure Resource Manager token file.\n");
        return;
    }

    if ((token.JsonTypeOf(L"access_token") != 1) || (token.StringOfEquals(L"access_token",L"",true) == true)) {
        wprintf(L"A nonempty access_token string is required.\n");
        return;
    }

    //  Use your subscription ID as a string. The all-zero value is only a placeholder.
    const wchar_t *subscriptionId = L"00000000-0000-0000-0000-000000000000";
    CkHttpW http;
    http.put_AuthToken(token.stringOf(L"access_token"));
    http.put_Accept(L"application/json");
    http.put_RequireSslCertVerify(true);
    http.put_FollowRedirects(false);
    http.put_ConnectTimeout(30);
    http.put_ReadTimeout(60);
    success = http.SetUrlVar(L"subscriptionId",subscriptionId);
    if (success != true) {
        wprintf(L"Could not encode subscription ID.\n");
        return;
    }

    CkHttpResponseW response;
    CkJsonObjectW result;
    result.put_Strict(true);
    CkUrlW parsed;
    const wchar_t *resourceGroupName = L"my-resource-group";
    success = http.SetUrlVar(L"resourceGroupName",resourceGroupName);
    if (success != true) {
        wprintf(L"Could not encode resource group.\n");
        return;
    }

    //  Http substitutes and URL-encodes {$subscriptionId} in this first request.
    const wchar_t *requestUrl = L"https://management.azure.com/subscriptions/{$subscriptionId}/resourceGroups/{$resourceGroupName}/providers/Microsoft.Storage/storageAccounts?api-version=2026-09-01";
    CkHashtableW seen;
    CkJsonArrayW accounts;
    CkJsonObjectW account;
    bool morePages = true;
    int page = 0;
    int total = 0;
    while ((morePages == true)) {
        //  A limit and a repeated-link check protect against an endless continuation loop.
        if (page >= 1000) {
            wprintf(L"Page limit reached. Listing is incomplete; resume from: %s\n",requestUrl);
            return;
        }

        if (seen.Contains(requestUrl) == true) {
            wprintf(L"Repeated continuation URL; listing is incomplete.\n");
            return;
        }

        success = seen.AddStr(requestUrl,L"seen");
        if (success != true) {
            wprintf(L"Could not record the continuation URL.\n");
            return;
        }

        success = http.HttpNoBody(L"GET",requestUrl,response);
        if (response.get_StatusCode() == 0) {
            wprintf(L"No HTTP response. Inspect LastErrorText privately; it may contain credentials.\n");
            return;
        }

        if ((response.get_StatusCode() != 200)) {
            wprintf(L"HTTP status: %d\n",response.get_StatusCode());
            wprintf(L"Request ID: %s\n",response.getHeaderField(L"x-ms-request-id"));
            wprintf(L"Retry-After: %s\n",response.getHeaderField(L"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 != true) {
            wprintf(L"The HTTP response could not be read completely.\n");
            return;
        }

        success = result.Load(response.bodyStr());
        if (success != true) {
            wprintf(L"Expected a well-formed JSON response.\n");
            return;
        }

        if (result.JsonTypeOf(L"value") != 4) {
            wprintf(L"Expected a value array of storage accounts.\n");
            return;
        }

        success = result.ArrayOf2(L"value",accounts);
        if (success != true) {
            wprintf(L"Could not read the storage account array.\n");
            return;
        }

        int i = 0;
        while ((i < accounts.get_Size())) {
            success = accounts.ObjectAt2(i,account);
            if (success != true) {
                wprintf(L"Invalid storage account entry.\n");
                return;
            }

            if ((account.JsonTypeOf(L"id") != 1) || (account.JsonTypeOf(L"name") != 1)) {
                wprintf(L"Expected a storage account ID and name.\n");
                return;
            }

            //  ARM resource IDs are strings, not numbers. Save id for later management calls.
            wprintf(L"Name: %s\n",account.stringOf(L"name"));
            wprintf(L"Resource ID: %s\n",account.stringOf(L"id"));
            wprintf(L"Location: %s\n",account.stringOf(L"location"));
            wprintf(L"Kind: %s\n",account.stringOf(L"kind"));
            wprintf(L"SKU: %s\n",account.stringOf(L"sku.name"));
            wprintf(L"Provisioning state: %s\n",account.stringOf(L"properties.provisioningState"));
            //  Endpoint availability depends on account kind and provisioning state.
            if (account.JsonTypeOf(L"properties.primaryEndpoints.blob") == 1) {
                wprintf(L"Blob endpoint: %s\n",account.stringOf(L"properties.primaryEndpoints.blob"));
            }

            total = total + 1;
            i = i + 1;
        }

        page = page + 1;
        morePages = false;
        if (result.HasMember(L"nextLink") == true) {
            if ((result.IsNullOf(L"nextLink") != true) && (result.JsonTypeOf(L"nextLink") != 1)) {
                wprintf(L"Invalid nextLink; listing is incomplete.\n");
                return;
            }

            if ((result.JsonTypeOf(L"nextLink") == 1) && (result.StringOfEquals(L"nextLink",L"",true) != true)) {
                requestUrl = result.stringOf(L"nextLink");
                success = parsed.ParseUrl(requestUrl);
                if (success != true) {
                    wprintf(L"Missing or invalid continuation URL.\n");
                    return;
                }

                stringCompare.SetString(parsed.scheme());
                bool stringMatch1 = stringCompare.ContentsEqual(L"https",true);
                stringCompare.SetString(parsed.host());
                bool stringMatch2 = stringCompare.ContentsEqual(L"management.azure.com",true);
                stringCompare.SetString(parsed.login());
                bool stringMatch3 = stringCompare.ContentsEqual(L"",true);
                stringCompare.SetString(parsed.password());
                bool stringMatch4 = stringCompare.ContentsEqual(L"",true);
                stringCompare.SetString(parsed.frag());
                bool stringMatch5 = stringCompare.ContentsEqual(L"",true);
                if ((stringMatch1 != true) || (stringMatch2 != true) || (parsed.get_Port() != 443) || (stringMatch3 != true) || (stringMatch4 != true) || (stringMatch5 != true)) {
                    wprintf(L"Unexpected continuation URL; refusing to send the access token.\n");
                    return;
                }

                //  The server owns nextLink. Keep its query intact; do not add api-version.
                //  Continue even if the current page contained no accounts.
                morePages = true;
            }

        }

    }

    wprintf(L"Listing complete. Storage accounts: %d\n",total);
    }