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.
Chilkat Delphi DLL Downloads
var
success: Boolean;
stringCompare: HCkStringBuilder;
token: HCkJsonObject;
subscriptionId: PWideChar;
http: HCkHttp;
response: HCkHttpResponse;
result: HCkJsonObject;
parsed: HCkUrl;
resourceGroupName: PWideChar;
requestUrl: PWideChar;
seen: HCkHashtable;
accounts: HCkJsonArray;
account: HCkJsonObject;
morePages: Boolean;
page: Integer;
total: Integer;
i: Integer;
stringMatch1: Boolean;
stringMatch2: Boolean;
stringMatch3: Boolean;
stringMatch4: Boolean;
stringMatch5: Boolean;
begin
success := False;
stringCompare := CkStringBuilder_Create();
// 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.
token := CkJsonObject_Create();
CkJsonObject_putStrict(token,True);
success := CkJsonObject_LoadFile(token,'qa_data/tokens/azureToken.json');
if (success <> True) then
begin
Memo1.Lines.Add('Could not load the private Azure Resource Manager token file.');
Exit;
end;
if ((CkJsonObject_JsonTypeOf(token,'access_token') <> 1) or (CkJsonObject_StringOfEquals(token,'access_token','',True) = True)) then
begin
Memo1.Lines.Add('A nonempty access_token string is required.');
Exit;
end;
// Use your subscription ID as a string. The all-zero value is only a placeholder.
subscriptionId := '00000000-0000-0000-0000-000000000000';
http := CkHttp_Create();
CkHttp_putAuthToken(http,CkJsonObject__stringOf(token,'access_token'));
CkHttp_putAccept(http,'application/json');
CkHttp_putRequireSslCertVerify(http,True);
CkHttp_putFollowRedirects(http,False);
CkHttp_putConnectTimeout(http,30);
CkHttp_putReadTimeout(http,60);
success := CkHttp_SetUrlVar(http,'subscriptionId',subscriptionId);
if (success <> True) then
begin
Memo1.Lines.Add('Could not encode subscription ID.');
Exit;
end;
response := CkHttpResponse_Create();
result := CkJsonObject_Create();
CkJsonObject_putStrict(result,True);
parsed := CkUrl_Create();
resourceGroupName := 'my-resource-group';
success := CkHttp_SetUrlVar(http,'resourceGroupName',resourceGroupName);
if (success <> True) then
begin
Memo1.Lines.Add('Could not encode resource group.');
Exit;
end;
// Http substitutes and URL-encodes {$subscriptionId} in this first request.
requestUrl := 'https://management.azure.com/subscriptions/{$subscriptionId}/resourceGroups/{$resourceGroupName}/providers/Microsoft.Storage/storageAccounts?api-version=2026-09-01';
seen := CkHashtable_Create();
accounts := CkJsonArray_Create();
account := CkJsonObject_Create();
morePages := True;
page := 0;
total := 0;
while (morePages = True) do
begin
// A limit and a repeated-link check protect against an endless continuation loop.
if (page >= 1000) then
begin
Memo1.Lines.Add('Page limit reached. Listing is incomplete; resume from: ' + requestUrl);
Exit;
end;
if (CkHashtable_Contains(seen,requestUrl) = True) then
begin
Memo1.Lines.Add('Repeated continuation URL; listing is incomplete.');
Exit;
end;
success := CkHashtable_AddStr(seen,requestUrl,'seen');
if (success <> True) then
begin
Memo1.Lines.Add('Could not record the continuation URL.');
Exit;
end;
success := CkHttp_HttpNoBody(http,'GET',requestUrl,response);
if (CkHttpResponse_getStatusCode(response) = 0) then
begin
Memo1.Lines.Add('No HTTP response. Inspect LastErrorText privately; it may contain credentials.');
Exit;
end;
if ((CkHttpResponse_getStatusCode(response) <> 200)) then
begin
Memo1.Lines.Add('HTTP status: ' + IntToStr(CkHttpResponse_getStatusCode(response)));
Memo1.Lines.Add('Request ID: ' + CkHttpResponse__getHeaderField(response,'x-ms-request-id'));
Memo1.Lines.Add('Retry-After: ' + CkHttpResponse__getHeaderField(response,'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.
Exit;
end;
if (success <> True) then
begin
Memo1.Lines.Add('The HTTP response could not be read completely.');
Exit;
end;
success := CkJsonObject_Load(result,CkHttpResponse__bodyStr(response));
if (success <> True) then
begin
Memo1.Lines.Add('Expected a well-formed JSON response.');
Exit;
end;
if (CkJsonObject_JsonTypeOf(result,'value') <> 4) then
begin
Memo1.Lines.Add('Expected a value array of storage accounts.');
Exit;
end;
success := CkJsonObject_ArrayOf2(result,'value',accounts);
if (success <> True) then
begin
Memo1.Lines.Add('Could not read the storage account array.');
Exit;
end;
i := 0;
while (i < CkJsonArray_getSize(accounts)) do
begin
success := CkJsonArray_ObjectAt2(accounts,i,account);
if (success <> True) then
begin
Memo1.Lines.Add('Invalid storage account entry.');
Exit;
end;
if ((CkJsonObject_JsonTypeOf(account,'id') <> 1) or (CkJsonObject_JsonTypeOf(account,'name') <> 1)) then
begin
Memo1.Lines.Add('Expected a storage account ID and name.');
Exit;
end;
// ARM resource IDs are strings, not numbers. Save id for later management calls.
Memo1.Lines.Add('Name: ' + CkJsonObject__stringOf(account,'name'));
Memo1.Lines.Add('Resource ID: ' + CkJsonObject__stringOf(account,'id'));
Memo1.Lines.Add('Location: ' + CkJsonObject__stringOf(account,'location'));
Memo1.Lines.Add('Kind: ' + CkJsonObject__stringOf(account,'kind'));
Memo1.Lines.Add('SKU: ' + CkJsonObject__stringOf(account,'sku.name'));
Memo1.Lines.Add('Provisioning state: ' + CkJsonObject__stringOf(account,'properties.provisioningState'));
// Endpoint availability depends on account kind and provisioning state.
if (CkJsonObject_JsonTypeOf(account,'properties.primaryEndpoints.blob') = 1) then
begin
Memo1.Lines.Add('Blob endpoint: ' + CkJsonObject__stringOf(account,'properties.primaryEndpoints.blob'));
end;
total := total + 1;
i := i + 1;
end;
page := page + 1;
morePages := False;
if (CkJsonObject_HasMember(result,'nextLink') = True) then
begin
if ((CkJsonObject_IsNullOf(result,'nextLink') <> True) and (CkJsonObject_JsonTypeOf(result,'nextLink') <> 1)) then
begin
Memo1.Lines.Add('Invalid nextLink; listing is incomplete.');
Exit;
end;
if ((CkJsonObject_JsonTypeOf(result,'nextLink') = 1) and (CkJsonObject_StringOfEquals(result,'nextLink','',True) <> True)) then
begin
requestUrl := CkJsonObject__stringOf(result,'nextLink');
success := CkUrl_ParseUrl(parsed,requestUrl);
if (success <> True) then
begin
Memo1.Lines.Add('Missing or invalid continuation URL.');
Exit;
end;
CkStringBuilder_SetString(stringCompare,CkUrl__scheme(parsed));
stringMatch1 := CkStringBuilder_ContentsEqual(stringCompare,'https',True);
CkStringBuilder_SetString(stringCompare,CkUrl__host(parsed));
stringMatch2 := CkStringBuilder_ContentsEqual(stringCompare,'management.azure.com',True);
CkStringBuilder_SetString(stringCompare,CkUrl__login(parsed));
stringMatch3 := CkStringBuilder_ContentsEqual(stringCompare,'',True);
CkStringBuilder_SetString(stringCompare,CkUrl__password(parsed));
stringMatch4 := CkStringBuilder_ContentsEqual(stringCompare,'',True);
CkStringBuilder_SetString(stringCompare,CkUrl__frag(parsed));
stringMatch5 := CkStringBuilder_ContentsEqual(stringCompare,'',True);
if ((stringMatch1 <> True) or (stringMatch2 <> True) or (CkUrl_getPort(parsed) <> 443) or (stringMatch3 <> True) or (stringMatch4 <> True) or (stringMatch5 <> True)) then
begin
Memo1.Lines.Add('Unexpected continuation URL; refusing to send the access token.');
Exit;
end;
// The server owns nextLink. Keep its query intact; do not add api-version.
// Continue even if the current page contained no accounts.
morePages := True;
end;
end;
end;
Memo1.Lines.Add('Listing complete. Storage accounts: ' + IntToStr(total));
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(token);
CkHttp_Dispose(http);
CkHttpResponse_Dispose(response);
CkJsonObject_Dispose(result);
CkUrl_Dispose(parsed);
CkHashtable_Dispose(seen);
CkJsonArray_Dispose(accounts);
CkJsonObject_Dispose(account);