Sample code for 30+ languages & platforms
Lianja

Azure List Storage Accounts

See more Azure Storage Accounts Examples

Demonstrates how to list Azure storage accounts.

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

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

loHttp = createobject("CkHttp")

// Load an OAuth2 access token previously fetched by this example:  Get Azure OAuth2 Access Token
loJsonToken = createobject("CkJsonObject")
llSuccess = loJsonToken.LoadFile("qa_data/tokens/azureToken.json")
// Assuming success..
loHttp.AuthToken = loJsonToken.StringOf("access_token")
? "AuthToken: " + loHttp.AuthToken

loHttp.Accept = "application/json"

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

lcJsonResp = loHttp.QuickGetStr(lcUrl)
if (loHttp.LastMethodSuccess <> .T.) then
    ? loHttp.LastErrorText
    release loHttp
    release loJsonToken
    return
endif

? "Response Status Code: " + str(loHttp.LastStatus)

loJson = createobject("CkJsonObject")
loJson.Load(lcJsonResp)
loJson.EmitCompact = .F.
? loJson.Emit()

if (loHttp.LastStatus <> 200) then
    ? "Failed."
    release loHttp
    release loJsonToken
    release loJson
    return
endif

// 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
lnCount_i = loJson.SizeOfArray("value")
do while i < lnCount_i
    loJson.I = i
    lcSkuName = loJson.StringOf("value[i].sku.name")
    lcSkuTier = loJson.StringOf("value[i].sku.tier")
    lcKind = loJson.StringOf("value[i].kind")
    lcId = loJson.StringOf("value[i].id")
    lcName = loJson.StringOf("value[i].name")
    lcV_type = loJson.StringOf("value[i].type")
    lcLocation = loJson.StringOf("value[i].location")
    lcPropertiesNetworkAclsBypass = loJson.StringOf("value[i].properties.networkAcls.bypass")
    lcPropertiesNetworkAclsDefaultAction = loJson.StringOf("value[i].properties.networkAcls.defaultAction")
    llPropertiesSupportsHttpsTrafficOnly = loJson.BoolOf("value[i].properties.supportsHttpsTrafficOnly")
    llPropertiesEncryptionServicesFileEnabled = loJson.BoolOf("value[i].properties.encryption.services.file.enabled")
    lcPropertiesEncryptionServicesFileLastEnabledTime = loJson.StringOf("value[i].properties.encryption.services.file.lastEnabledTime")
    llPropertiesEncryptionServicesBlobEnabled = loJson.BoolOf("value[i].properties.encryption.services.blob.enabled")
    lcPropertiesEncryptionServicesBlobLastEnabledTime = loJson.StringOf("value[i].properties.encryption.services.blob.lastEnabledTime")
    lcPropertiesEncryptionKeySource = loJson.StringOf("value[i].properties.encryption.keySource")
    lcPropertiesProvisioningState = loJson.StringOf("value[i].properties.provisioningState")
    lcPropertiesCreationTime = loJson.StringOf("value[i].properties.creationTime")
    lcPropertiesPrimaryEndpointsBlob = loJson.StringOf("value[i].properties.primaryEndpoints.blob")
    lcPropertiesPrimaryEndpointsQueue = loJson.StringOf("value[i].properties.primaryEndpoints.queue")
    lcPropertiesPrimaryEndpointsTable = loJson.StringOf("value[i].properties.primaryEndpoints.table")
    lcPropertiesPrimaryEndpointsFile = loJson.StringOf("value[i].properties.primaryEndpoints.file")
    lcPropertiesPrimaryLocation = loJson.StringOf("value[i].properties.primaryLocation")
    lcPropertiesStatusOfPrimary = loJson.StringOf("value[i].properties.statusOfPrimary")
    i = i + 1
enddo


release loHttp
release loJsonToken
release loJson