Sample code for 30+ languages & platforms
Perl

Azure Create Storage Account

See more Azure Storage Accounts Examples

Demonstrates how to create an Azure storage account.

Chilkat Perl Downloads

Perl
use chilkat();

$success = 0;

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

$http = chilkat::CkHttp->new();

# Load an OAuth2 access token previously fetched by this example:  Get Azure OAuth2 Access Token
$jsonToken = chilkat::CkJsonObject->new();
$success = $jsonToken->LoadFile("qa_data/tokens/azureToken.json");
# Assuming success..
$http->put_AuthToken($jsonToken->stringOf("access_token"));
print "AuthToken: " . $http->authToken() . "\r\n";

$http->put_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

$jsonRequestBody = chilkat::CkJsonObject->new();
$jsonRequestBody->UpdateString("sku.name","Standard_GRS");
$jsonRequestBody->UpdateString("kind","StorageV2");
$jsonRequestBody->UpdateString("location","eastus2");

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

$resp = chilkat::CkHttpResponse->new();
$success = $http->HttpJson("PUT",$url,$jsonRequestBody,"application/json",$resp);
if ($success == 0) {
    print $http->lastErrorText() . "\r\n";
    exit;
}

print "Response Status Code: " . $resp->get_StatusCode() . "\r\n";

$json = chilkat::CkJsonObject->new();
$json->Load($resp->bodyStr());
$json->put_EmitCompact(0);
print $json->emit() . "\r\n";

if ($resp->get_StatusCode() >= 300) {
    print "Failed." . "\r\n";
    exit;
}

# 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->get_StatusCode() == 202) {
    print "Azure-AsyncOperation: " . $resp->getHeaderField("Azure-AsyncOperation") . "\r\n";
}

if ($resp->get_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

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

print "Success." . "\r\n";