Sample code for 30+ languages & platforms
Java

Azure List Storage Accounts

See more Azure Storage Accounts Examples

Demonstrates how to list Azure storage accounts.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.JsonObject;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example requires the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        Http http = new Http();

        // Load an OAuth2 access token previously fetched by this example:  Get Azure OAuth2 Access Token
        JsonObject jsonToken = new JsonObject();
        jsonToken.loadFile("qa_data/tokens/azureToken.json");
        // Assuming success..
        http.setAuthToken(jsonToken.stringOf("access_token"));
        System.out.println("AuthToken: " + http.getAuthToken());

        http.setAccept("application/json");

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

        String jsonResp;
        try {
            jsonResp = http.quickGetStr(url);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        System.out.println("Response Status Code: " + http.getLastStatus());

        JsonObject json = new JsonObject();
        json.load(jsonResp);
        json.setEmitCompact(false);
        System.out.println(json.emit());

        if (http.getLastStatus() != 200) {
            System.out.println("Failed.");
            return;
        }

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

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

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