Sample code for 30+ languages & platforms
Go

Azure Create Storage Account

See more Azure Storage Accounts Examples

Demonstrates how to create an Azure storage account.

Chilkat Go Downloads

Go
    success := false

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

    http := chilkat.NewHttp()

    // Load an OAuth2 access token previously fetched by this example:  Get Azure OAuth2 Access Token
    jsonToken := chilkat.NewJsonObject()
    success = jsonToken.LoadFile("qa_data/tokens/azureToken.json")
    // Assuming success..
    http.SetAuthToken(jsonToken.StringOf("access_token"))
    fmt.Println("AuthToken: ", http.AuthToken())

    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

    jsonRequestBody := chilkat.NewJsonObject()
    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.NewHttpResponse()
    success = http.HttpJson("PUT",url,jsonRequestBody,"application/json",resp)
    if success == false {
        fmt.Println(http.LastErrorText())
        http.DisposeHttp()
        jsonToken.DisposeJsonObject()
        jsonRequestBody.DisposeJsonObject()
        resp.DisposeHttpResponse()
        return
    }

    fmt.Println("Response Status Code: ", resp.StatusCode())

    json := chilkat.NewJsonObject()
    json.Load(resp.BodyStr())
    json.SetEmitCompact(false)
    fmt.Println(*json.Emit())

    if resp.StatusCode() >= 300 {
        fmt.Println("Failed.")
        http.DisposeHttp()
        jsonToken.DisposeJsonObject()
        jsonRequestBody.DisposeJsonObject()
        resp.DisposeHttpResponse()
        json.DisposeJsonObject()
        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 {
        fmt.Println("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

        var skuName *string = new(string)
        var skuTier *string = new(string)
        var kind *string = new(string)
        var id *string = new(string)
        var name *string = new(string)
        var v_type *string = new(string)
        var location *string = new(string)
        var propertiesNetworkAclsBypass *string = new(string)
        var propertiesNetworkAclsDefaultAction *string = new(string)
        var propertiesSupportsHttpsTrafficOnly bool
        var propertiesEncryptionServicesFileEnabled bool
        var propertiesEncryptionServicesFileLastEnabledTime *string = new(string)
        var propertiesEncryptionServicesBlobEnabled bool
        var propertiesEncryptionServicesBlobLastEnabledTime *string = new(string)
        var propertiesEncryptionKeySource *string = new(string)
        var propertiesAccessTier *string = new(string)
        var propertiesProvisioningState *string = new(string)
        var propertiesCreationTime *string = new(string)
        var propertiesPrimaryEndpointsDfs *string = new(string)
        var propertiesPrimaryEndpointsWeb *string = new(string)
        var propertiesPrimaryEndpointsBlob *string = new(string)
        var propertiesPrimaryEndpointsQueue *string = new(string)
        var propertiesPrimaryEndpointsTable *string = new(string)
        var propertiesPrimaryEndpointsFile *string = new(string)
        var propertiesPrimaryLocation *string = new(string)
        var propertiesStatusOfPrimary *string = new(string)
        var propertiesSecondaryLocation *string = new(string)
        var propertiesStatusOfSecondary *string = new(string)
        var i int
        var count_i int

        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")
    }

    fmt.Println("Success.")

    http.DisposeHttp()
    jsonToken.DisposeJsonObject()
    jsonRequestBody.DisposeJsonObject()
    resp.DisposeHttpResponse()
    json.DisposeJsonObject()