Sample code for 30+ languages & platforms
AutoIt

Azure Create Storage Account

See more Azure Storage Accounts Examples

Demonstrates how to create an Azure storage account.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

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

$oHttp = ObjCreate("Chilkat.Http")

; Load an OAuth2 access token previously fetched by this example:  Get Azure OAuth2 Access Token
$oJsonToken = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oJsonToken.LoadFile("qa_data/tokens/azureToken.json")
; Assuming success..
$oHttp.AuthToken = $oJsonToken.StringOf("access_token")
ConsoleWrite("AuthToken: " & $oHttp.AuthToken & @CRLF)

$oHttp.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

$oJsonRequestBody = ObjCreate("Chilkat.JsonObject")
$oJsonRequestBody.UpdateString("sku.name","Standard_GRS")
$oJsonRequestBody.UpdateString("kind","StorageV2")
$oJsonRequestBody.UpdateString("location","eastus2")

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

$oResp = ObjCreate("Chilkat.HttpResponse")
$bSuccess = $oHttp.HttpJson("PUT",$sUrl,$oJsonRequestBody,"application/json",$oResp)
If ($bSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("Response Status Code: " & $oResp.StatusCode & @CRLF)

$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.Load($oResp.BodyStr)
$oJson.EmitCompact = False
ConsoleWrite($oJson.Emit() & @CRLF)

If ($oResp.StatusCode >= 300) Then
    ConsoleWrite("Failed." & @CRLF)
    Exit
EndIf

; 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 ($oResp.StatusCode = 202) Then
    ConsoleWrite("Azure-AsyncOperation: " & $oResp.GetHeaderField("Azure-AsyncOperation") & @CRLF)
EndIf

If ($oResp.StatusCode = 200) Then

    ; 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

Local $skuName
Local $skuTier
Local $sKind
Local $sId
Local $sName
Local $sV_type
Local $sLocation
Local $sPropertiesNetworkAclsBypass
Local $sPropertiesNetworkAclsDefaultAction
Local $bPropertiesSupportsHttpsTrafficOnly
Local $bPropertiesEncryptionServicesFileEnabled
Local $sPropertiesEncryptionServicesFileLastEnabledTime
Local $bPropertiesEncryptionServicesBlobEnabled
Local $sPropertiesEncryptionServicesBlobLastEnabledTime
Local $sPropertiesEncryptionKeySource
Local $sPropertiesAccessTier
Local $sPropertiesProvisioningState
Local $sPropertiesCreationTime
Local $sPropertiesPrimaryEndpointsDfs
Local $sPropertiesPrimaryEndpointsWeb
Local $sPropertiesPrimaryEndpointsBlob
Local $sPropertiesPrimaryEndpointsQueue
Local $sPropertiesPrimaryEndpointsTable
Local $sPropertiesPrimaryEndpointsFile
Local $sPropertiesPrimaryLocation
Local $sPropertiesStatusOfPrimary
Local $sPropertiesSecondaryLocation
Local $sPropertiesStatusOfSecondary
Local $i
Local $iCount_i

    $skuName = $oJson.StringOf("sku.name")
    $skuTier = $oJson.StringOf("sku.tier")
    $sKind = $oJson.StringOf("kind")
    $sId = $oJson.StringOf("id")
    $sName = $oJson.StringOf("name")
    $sV_type = $oJson.StringOf("type")
    $sLocation = $oJson.StringOf("location")
    $sPropertiesNetworkAclsBypass = $oJson.StringOf("properties.networkAcls.bypass")
    $sPropertiesNetworkAclsDefaultAction = $oJson.StringOf("properties.networkAcls.defaultAction")
    $bPropertiesSupportsHttpsTrafficOnly = $oJson.BoolOf("properties.supportsHttpsTrafficOnly")
    $bPropertiesEncryptionServicesFileEnabled = $oJson.BoolOf("properties.encryption.services.file.enabled")
    $sPropertiesEncryptionServicesFileLastEnabledTime = $oJson.StringOf("properties.encryption.services.file.lastEnabledTime")
    $bPropertiesEncryptionServicesBlobEnabled = $oJson.BoolOf("properties.encryption.services.blob.enabled")
    $sPropertiesEncryptionServicesBlobLastEnabledTime = $oJson.StringOf("properties.encryption.services.blob.lastEnabledTime")
    $sPropertiesEncryptionKeySource = $oJson.StringOf("properties.encryption.keySource")
    $sPropertiesAccessTier = $oJson.StringOf("properties.accessTier")
    $sPropertiesProvisioningState = $oJson.StringOf("properties.provisioningState")
    $sPropertiesCreationTime = $oJson.StringOf("properties.creationTime")
    $sPropertiesPrimaryEndpointsDfs = $oJson.StringOf("properties.primaryEndpoints.dfs")
    $sPropertiesPrimaryEndpointsWeb = $oJson.StringOf("properties.primaryEndpoints.web")
    $sPropertiesPrimaryEndpointsBlob = $oJson.StringOf("properties.primaryEndpoints.blob")
    $sPropertiesPrimaryEndpointsQueue = $oJson.StringOf("properties.primaryEndpoints.queue")
    $sPropertiesPrimaryEndpointsTable = $oJson.StringOf("properties.primaryEndpoints.table")
    $sPropertiesPrimaryEndpointsFile = $oJson.StringOf("properties.primaryEndpoints.file")
    $sPropertiesPrimaryLocation = $oJson.StringOf("properties.primaryLocation")
    $sPropertiesStatusOfPrimary = $oJson.StringOf("properties.statusOfPrimary")
    $sPropertiesSecondaryLocation = $oJson.StringOf("properties.secondaryLocation")
    $sPropertiesStatusOfSecondary = $oJson.StringOf("properties.statusOfSecondary")
EndIf

ConsoleWrite("Success." & @CRLF)