Sample code for 30+ languages & platforms
Lua

Azure List Storage Accounts

See more Azure Storage Accounts Examples

Demonstrates how to list Azure storage accounts.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

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

local http = chilkat.Http.new()

-- Load an OAuth2 access token previously fetched by this example:  Get Azure OAuth2 Access Token
local jsonToken = chilkat.JsonObject.new()
local success = jsonToken:load_file("qa_data/tokens/azureToken.json")
-- Assuming success..
http.auth_token = jsonToken:string_of("access_token")
print("AuthToken: " .. http.auth_token)

http.accept = "application/json"

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

local jsonResp = http:quick_get_str(url)
if not http.last_method_success then
    print(http.last_error_text)
    return
end

print("Response Status Code: " .. http.last_status)

local json = chilkat.JsonObject.new()
json:load(jsonResp)
json.emit_compact = false
print(json:emit())

if http.last_status ~= 200 then
    print("Failed.")
    return
end

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

local skuName = ""
local skuTier = ""
local kind = ""
local id = ""
local name = ""
local v_type = ""
local location = ""
local propertiesNetworkAclsBypass = ""
local propertiesNetworkAclsDefaultAction = ""
local propertiesSupportsHttpsTrafficOnly = false
local propertiesEncryptionServicesFileEnabled = false
local propertiesEncryptionServicesFileLastEnabledTime = ""
local propertiesEncryptionServicesBlobEnabled = false
local propertiesEncryptionServicesBlobLastEnabledTime = ""
local propertiesEncryptionKeySource = ""
local propertiesProvisioningState = ""
local propertiesCreationTime = ""
local propertiesPrimaryEndpointsBlob = ""
local propertiesPrimaryEndpointsQueue = ""
local propertiesPrimaryEndpointsTable = ""
local propertiesPrimaryEndpointsFile = ""
local propertiesPrimaryLocation = ""
local propertiesStatusOfPrimary = ""

local i = 0
local count_i = json:size_of_array("value")
while i < count_i do
    json.i = i
    skuName = json:string_of("value[i].sku.name")
    skuTier = json:string_of("value[i].sku.tier")
    kind = json:string_of("value[i].kind")
    id = json:string_of("value[i].id")
    name = json:string_of("value[i].name")
    v_type = json:string_of("value[i].type")
    location = json:string_of("value[i].location")
    propertiesNetworkAclsBypass = json:string_of("value[i].properties.networkAcls.bypass")
    propertiesNetworkAclsDefaultAction = json:string_of("value[i].properties.networkAcls.defaultAction")
    propertiesSupportsHttpsTrafficOnly = json:bool_of("value[i].properties.supportsHttpsTrafficOnly")
    propertiesEncryptionServicesFileEnabled = json:bool_of("value[i].properties.encryption.services.file.enabled")
    propertiesEncryptionServicesFileLastEnabledTime = json:string_of("value[i].properties.encryption.services.file.lastEnabledTime")
    propertiesEncryptionServicesBlobEnabled = json:bool_of("value[i].properties.encryption.services.blob.enabled")
    propertiesEncryptionServicesBlobLastEnabledTime = json:string_of("value[i].properties.encryption.services.blob.lastEnabledTime")
    propertiesEncryptionKeySource = json:string_of("value[i].properties.encryption.keySource")
    propertiesProvisioningState = json:string_of("value[i].properties.provisioningState")
    propertiesCreationTime = json:string_of("value[i].properties.creationTime")
    propertiesPrimaryEndpointsBlob = json:string_of("value[i].properties.primaryEndpoints.blob")
    propertiesPrimaryEndpointsQueue = json:string_of("value[i].properties.primaryEndpoints.queue")
    propertiesPrimaryEndpointsTable = json:string_of("value[i].properties.primaryEndpoints.table")
    propertiesPrimaryEndpointsFile = json:string_of("value[i].properties.primaryEndpoints.file")
    propertiesPrimaryLocation = json:string_of("value[i].properties.primaryLocation")
    propertiesStatusOfPrimary = json:string_of("value[i].properties.statusOfPrimary")
    i = i + 1
end