Sample code for 30+ languages & platforms
DataFlex

Azure Create Storage Account

See more Azure Storage Accounts Examples

Demonstrates how to create an Azure storage account.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoHttp
Token    Handle hoJsonToken
RequestBody    Handle hoJsonRequestBody
    String sUrl
    Variant vResp
    Handle hoResp
    Handle hoJson
    String sSkuName
    String sSkuTier
    String sKind
    String sId
    String sName
    String sV_type
    String sLocation
    String sPropertiesNetworkAclsBypass
    String sPropertiesNetworkAclsDefaultAction
    Boolean iPropertiesSupportsHttpsTrafficOnly
    Boolean iPropertiesEncryptionServicesFileEnabled
    String sPropertiesEncryptionServicesFileLastEnabledTime
    Boolean iPropertiesEncryptionServicesBlobEnabled
    String sPropertiesEncryptionServicesBlobLastEnabledTime
    String sPropertiesEncryptionKeySource
    String sPropertiesAccessTier
    String sPropertiesProvisioningState
    String sPropertiesCreationTime
    String sPropertiesPrimaryEndpointsDfs
    String sPropertiesPrimaryEndpointsWeb
    String sPropertiesPrimaryEndpointsBlob
    String sPropertiesPrimaryEndpointsQueue
    String sPropertiesPrimaryEndpointsTable
    String sPropertiesPrimaryEndpointsFile
    String sPropertiesPrimaryLocation
    String sPropertiesStatusOfPrimary
    String sPropertiesSecondaryLocation
    String sPropertiesStatusOfSecondary
    Integer i
    Integer iCount_i
    String sTemp1
    Integer iTemp1

    Move False To iSuccess

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    // Load an OAuth2 access token previously fetched by this example:  Get Azure OAuth2 Access Token
    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonToken
    If (Not(IsComObjectCreated(hoJsonToken))) Begin
        Send CreateComObject of hoJsonToken
    End
    Get ComLoadFile Of hoJsonToken "qa_data/tokens/azureToken.json" To iSuccess
    // Assuming success..
    Get ComStringOf Of hoJsonToken "access_token" To sTemp1
    Set ComAuthToken Of hoHttp To sTemp1
    Get ComAuthToken Of hoHttp To sTemp1
    Showln "AuthToken: " sTemp1

    Set ComAccept Of hoHttp To "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

    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonRequestBody
    If (Not(IsComObjectCreated(hoJsonRequestBody))) Begin
        Send CreateComObject of hoJsonRequestBody
    End
    Get ComUpdateString Of hoJsonRequestBody "sku.name" "Standard_GRS" To iSuccess
    Get ComUpdateString Of hoJsonRequestBody "kind" "StorageV2" To iSuccess
    Get ComUpdateString Of hoJsonRequestBody "location" "eastus2" To iSuccess

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

    Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
    If (Not(IsComObjectCreated(hoResp))) Begin
        Send CreateComObject of hoResp
    End
    Get pvComObject of hoJsonRequestBody to vJsonRequestBody
    Get pvComObject of hoResp to vResp
    Get ComHttpJson Of hoHttp "PUT" sUrl vJsonRequestBody "application/json" vResp To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    Showln "Response Status Code: " iTemp1

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComBodyStr Of hoResp To sTemp1
    Get ComLoad Of hoJson sTemp1 To iSuccess
    Set ComEmitCompact Of hoJson To False
    Get ComEmit Of hoJson To sTemp1
    Showln sTemp1

    Get ComStatusCode Of hoResp To iTemp1
    If (iTemp1 >= 300) Begin
        Showln "Failed."
        Procedure_Return
    End

    // 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.
    Get ComStatusCode Of hoResp To iTemp1
    If (iTemp1 = 202) Begin
        Get ComGetHeaderField Of hoResp "Azure-AsyncOperation" To sTemp1
        Showln "Azure-AsyncOperation: " sTemp1
    End

    Get ComStatusCode Of hoResp To iTemp1
    If (iTemp1 = 200) Begin

        // 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

        Get ComStringOf Of hoJson "sku.name" To sSkuName
        Get ComStringOf Of hoJson "sku.tier" To sSkuTier
        Get ComStringOf Of hoJson "kind" To sKind
        Get ComStringOf Of hoJson "id" To sId
        Get ComStringOf Of hoJson "name" To sName
        Get ComStringOf Of hoJson "type" To sV_type
        Get ComStringOf Of hoJson "location" To sLocation
        Get ComStringOf Of hoJson "properties.networkAcls.bypass" To sPropertiesNetworkAclsBypass
        Get ComStringOf Of hoJson "properties.networkAcls.defaultAction" To sPropertiesNetworkAclsDefaultAction
        Get ComBoolOf Of hoJson "properties.supportsHttpsTrafficOnly" To iPropertiesSupportsHttpsTrafficOnly
        Get ComBoolOf Of hoJson "properties.encryption.services.file.enabled" To iPropertiesEncryptionServicesFileEnabled
        Get ComStringOf Of hoJson "properties.encryption.services.file.lastEnabledTime" To sPropertiesEncryptionServicesFileLastEnabledTime
        Get ComBoolOf Of hoJson "properties.encryption.services.blob.enabled" To iPropertiesEncryptionServicesBlobEnabled
        Get ComStringOf Of hoJson "properties.encryption.services.blob.lastEnabledTime" To sPropertiesEncryptionServicesBlobLastEnabledTime
        Get ComStringOf Of hoJson "properties.encryption.keySource" To sPropertiesEncryptionKeySource
        Get ComStringOf Of hoJson "properties.accessTier" To sPropertiesAccessTier
        Get ComStringOf Of hoJson "properties.provisioningState" To sPropertiesProvisioningState
        Get ComStringOf Of hoJson "properties.creationTime" To sPropertiesCreationTime
        Get ComStringOf Of hoJson "properties.primaryEndpoints.dfs" To sPropertiesPrimaryEndpointsDfs
        Get ComStringOf Of hoJson "properties.primaryEndpoints.web" To sPropertiesPrimaryEndpointsWeb
        Get ComStringOf Of hoJson "properties.primaryEndpoints.blob" To sPropertiesPrimaryEndpointsBlob
        Get ComStringOf Of hoJson "properties.primaryEndpoints.queue" To sPropertiesPrimaryEndpointsQueue
        Get ComStringOf Of hoJson "properties.primaryEndpoints.table" To sPropertiesPrimaryEndpointsTable
        Get ComStringOf Of hoJson "properties.primaryEndpoints.file" To sPropertiesPrimaryEndpointsFile
        Get ComStringOf Of hoJson "properties.primaryLocation" To sPropertiesPrimaryLocation
        Get ComStringOf Of hoJson "properties.statusOfPrimary" To sPropertiesStatusOfPrimary
        Get ComStringOf Of hoJson "properties.secondaryLocation" To sPropertiesSecondaryLocation
        Get ComStringOf Of hoJson "properties.statusOfSecondary" To sPropertiesStatusOfSecondary
    End

    Showln "Success."


End_Procedure