Sample code for 30+ languages & platforms
Tcl

Azure List Storage Accounts

See more Azure Storage Accounts Examples

Demonstrates how to list Azure storage accounts.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

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

set http [new_CkHttp]

# Load an OAuth2 access token previously fetched by this example:  Get Azure OAuth2 Access Token
set jsonToken [new_CkJsonObject]

set success [CkJsonObject_LoadFile $jsonToken "qa_data/tokens/azureToken.json"]
# Assuming success..
CkHttp_put_AuthToken $http [CkJsonObject_stringOf $jsonToken "access_token"]
puts "AuthToken: [CkHttp_authToken $http]"

CkHttp_put_Accept $http "application/json"

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

set jsonResp [CkHttp_quickGetStr $http $url]
if {[CkHttp_get_LastMethodSuccess $http] != 1} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkJsonObject $jsonToken
    exit
}

puts "Response Status Code: [CkHttp_get_LastStatus $http]"

set json [new_CkJsonObject]

CkJsonObject_Load $json $jsonResp
CkJsonObject_put_EmitCompact $json 0
puts [CkJsonObject_emit $json]

if {[CkHttp_get_LastStatus $http] != 200} then {
    puts "Failed."
    delete_CkHttp $http
    delete_CkJsonObject $jsonToken
    delete_CkJsonObject $json
    exit
}

# 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"
#       }
#     }
#   ]
# }
# 

set i 0
set count_i [CkJsonObject_SizeOfArray $json "value"]
while {$i < $count_i} {
    CkJsonObject_put_I $json $i
    set skuName [CkJsonObject_stringOf $json "value[i].sku.name"]
    set skuTier [CkJsonObject_stringOf $json "value[i].sku.tier"]
    set kind [CkJsonObject_stringOf $json "value[i].kind"]
    set id [CkJsonObject_stringOf $json "value[i].id"]
    set name [CkJsonObject_stringOf $json "value[i].name"]
    set v_type [CkJsonObject_stringOf $json "value[i].type"]
    set location [CkJsonObject_stringOf $json "value[i].location"]
    set propertiesNetworkAclsBypass [CkJsonObject_stringOf $json "value[i].properties.networkAcls.bypass"]
    set propertiesNetworkAclsDefaultAction [CkJsonObject_stringOf $json "value[i].properties.networkAcls.defaultAction"]
    set propertiesSupportsHttpsTrafficOnly [CkJsonObject_BoolOf $json "value[i].properties.supportsHttpsTrafficOnly"]
    set propertiesEncryptionServicesFileEnabled [CkJsonObject_BoolOf $json "value[i].properties.encryption.services.file.enabled"]
    set propertiesEncryptionServicesFileLastEnabledTime [CkJsonObject_stringOf $json "value[i].properties.encryption.services.file.lastEnabledTime"]
    set propertiesEncryptionServicesBlobEnabled [CkJsonObject_BoolOf $json "value[i].properties.encryption.services.blob.enabled"]
    set propertiesEncryptionServicesBlobLastEnabledTime [CkJsonObject_stringOf $json "value[i].properties.encryption.services.blob.lastEnabledTime"]
    set propertiesEncryptionKeySource [CkJsonObject_stringOf $json "value[i].properties.encryption.keySource"]
    set propertiesProvisioningState [CkJsonObject_stringOf $json "value[i].properties.provisioningState"]
    set propertiesCreationTime [CkJsonObject_stringOf $json "value[i].properties.creationTime"]
    set propertiesPrimaryEndpointsBlob [CkJsonObject_stringOf $json "value[i].properties.primaryEndpoints.blob"]
    set propertiesPrimaryEndpointsQueue [CkJsonObject_stringOf $json "value[i].properties.primaryEndpoints.queue"]
    set propertiesPrimaryEndpointsTable [CkJsonObject_stringOf $json "value[i].properties.primaryEndpoints.table"]
    set propertiesPrimaryEndpointsFile [CkJsonObject_stringOf $json "value[i].properties.primaryEndpoints.file"]
    set propertiesPrimaryLocation [CkJsonObject_stringOf $json "value[i].properties.primaryLocation"]
    set propertiesStatusOfPrimary [CkJsonObject_stringOf $json "value[i].properties.statusOfPrimary"]
    set i [expr $i + 1]
}

delete_CkHttp $http
delete_CkJsonObject $jsonToken
delete_CkJsonObject $json