Sample code for 30+ languages & platforms
Java

Azure Create Storage Account

See more Azure Storage Accounts Examples

Demonstrates how to create an Azure storage account.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.HttpResponse;
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");

        // Create the following JSON:

        // {
        //   "sku": {
        //     "name": "Standard_GRS"
        //   },
        //   "kind": "StorageV2",
        //   "location": "eastus2",
        // }

        // Use this online tool to generate the code from sample JSON:
        // Generate Code to Create JSON

        JsonObject jsonRequestBody = new JsonObject();
        jsonRequestBody.updateString("sku.name", "Standard_GRS");
        jsonRequestBody.updateString("kind", "StorageV2");
        jsonRequestBody.updateString("location", "eastus2");

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

        HttpResponse resp = new HttpResponse();
        try {
            http.httpJson("PUT", url, jsonRequestBody, "application/json", resp);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        System.out.println("Response Status Code: " + resp.getStatusCode());

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

        if (resp.getStatusCode() >= 300) {
            System.out.println("Failed.");
            return;
        }

        // Successful requests to create a new account return a 202 status code with an empty response body. The storage account is created asynchronously.
        // If the account already exists or is being provisioned, the request response has a 200 return code with the configuration of the existing storage account in the response body.
        if (resp.getStatusCode() == 202) {
            System.out.println("Azure-AsyncOperation: " + resp.getHeaderField("Azure-AsyncOperation"));
        }

        if (resp.getStatusCode() == 200) {
            // Parse a response like this:

            //     {
            //       "sku": {
            //         "name": "Standard_GRS",
            //         "tier": "Standard"
            //       },
            //       "kind": "StorageV2",
            //       "id": "/subscriptions/6c42643b-ebef-45f0-b917-b3583b84a57f/resourceGroups/gChilkat/providers/Microsoft.Storage/storageAccounts/chilkatsoftware",
            //       "name": "chilkatsoftware",
            //       "type": "Microsoft.Storage/storageAccounts",
            //       "location": "eastus2",
            //       "tags": {},
            //       "properties": {
            //         "networkAcls": {
            //           "bypass": "AzureServices",
            //           "virtualNetworkRules": [
            //           ],
            //           "ipRules": [
            //           ],
            //           "defaultAction": "Allow"
            //         },
            //         "supportsHttpsTrafficOnly": false,
            //         "encryption": {
            //           "services": {
            //             "file": {
            //               "enabled": true,
            //               "lastEnabledTime": "2019-05-14T22:18:33.2246670Z"
            //             },
            //             "blob": {
            //               "enabled": true,
            //               "lastEnabledTime": "2019-05-14T22:18:33.2246670Z"
            //             }
            //           },
            //           "keySource": "Microsoft.Storage"
            //         },
            //         "accessTier": "Hot",
            //         "provisioningState": "Succeeded",
            //
            //         "creationTime": "2019-05-14T22:18:33.1309165Z",
            //         "primaryEndpoints": {
            //           "dfs": "https://chilkatsoftware.dfs.core.windows.net/",
            //           "web": "https://chilkatsoftware.z20.web.core.windows.net/",
            //           "blob": "https://chilkatsoftware.blob.core.windows.net/",
            //           "queue": "https://chilkatsoftware.queue.core.windows.net/",
            //           "table": "https://chilkatsoftware.table.core.windows.net/",
            //           "file": "https://chilkatsoftware.file.core.windows.net/"
            //         },
            //         "primaryLocation": "eastus2",
            //         "statusOfPrimary": "available",
            //         "secondaryLocation": "centralus",
            //         "statusOfSecondary": "available"
            //       }
            //     }

            // Use this online tool to generate parsing code from sample JSON:
            // Generate Parsing Code from JSON

            String skuName = json.stringOf("sku.name");
            String skuTier = json.stringOf("sku.tier");
            String kind = json.stringOf("kind");
            String id = json.stringOf("id");
            String name = json.stringOf("name");
            String v_type = json.stringOf("type");
            String location = json.stringOf("location");
            String propertiesNetworkAclsBypass = json.stringOf("properties.networkAcls.bypass");
            String propertiesNetworkAclsDefaultAction = json.stringOf("properties.networkAcls.defaultAction");
            boolean propertiesSupportsHttpsTrafficOnly = json.boolOf("properties.supportsHttpsTrafficOnly");
            boolean propertiesEncryptionServicesFileEnabled = json.boolOf("properties.encryption.services.file.enabled");
            String propertiesEncryptionServicesFileLastEnabledTime = json.stringOf("properties.encryption.services.file.lastEnabledTime");
            boolean propertiesEncryptionServicesBlobEnabled = json.boolOf("properties.encryption.services.blob.enabled");
            String propertiesEncryptionServicesBlobLastEnabledTime = json.stringOf("properties.encryption.services.blob.lastEnabledTime");
            String propertiesEncryptionKeySource = json.stringOf("properties.encryption.keySource");
            String propertiesAccessTier = json.stringOf("properties.accessTier");
            String propertiesProvisioningState = json.stringOf("properties.provisioningState");
            String propertiesCreationTime = json.stringOf("properties.creationTime");
            String propertiesPrimaryEndpointsDfs = json.stringOf("properties.primaryEndpoints.dfs");
            String propertiesPrimaryEndpointsWeb = json.stringOf("properties.primaryEndpoints.web");
            String propertiesPrimaryEndpointsBlob = json.stringOf("properties.primaryEndpoints.blob");
            String propertiesPrimaryEndpointsQueue = json.stringOf("properties.primaryEndpoints.queue");
            String propertiesPrimaryEndpointsTable = json.stringOf("properties.primaryEndpoints.table");
            String propertiesPrimaryEndpointsFile = json.stringOf("properties.primaryEndpoints.file");
            String propertiesPrimaryLocation = json.stringOf("properties.primaryLocation");
            String propertiesStatusOfPrimary = json.stringOf("properties.statusOfPrimary");
            String propertiesSecondaryLocation = json.stringOf("properties.secondaryLocation");
            String propertiesStatusOfSecondary = json.stringOf("properties.statusOfSecondary");
        }

        System.out.println("Success.");
    }
}