Sample code for 30+ languages & platforms
Dart

Azure Create Storage Account

See more Azure Storage Accounts Examples

Demonstrates how to create an Azure storage account.

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

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

  final http = CkHttp();

  // Load an OAuth2 access token previously fetched by this example:  Get Azure OAuth2 Access Token
  final jsonToken = CkJsonObject();
  jsonToken.loadFile('qa_data/tokens/azureToken.json');
  // Assuming success..
  http.authToken = jsonToken.stringOf('access_token');
  print('AuthToken: ${http.authToken}');

  http.accept = '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

  final jsonRequestBody = CkJsonObject();
  jsonRequestBody.updateString('sku.name', 'Standard_GRS');
  jsonRequestBody.updateString('kind', 'StorageV2');
  jsonRequestBody.updateString('location', 'eastus2');

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

  final resp = CkHttpResponse();
  try {
    http.httpJson('PUT', url, jsonRequestBody, 'application/json', resp);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  print('Response Status Code: ${resp.statusCode}');

  final json = CkJsonObject();
  json.load(resp.bodyStr);
  json.emitCompact = false;
  print(json.emit());

  if (resp.statusCode >= 300) {
    print('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.statusCode == 202) {
    print('Azure-AsyncOperation: ${resp.getHeaderField('Azure-AsyncOperation')}');
  }

  if (resp.statusCode == 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

    final i = 0;
    final countI = 0;

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

  print('Success.');
}