Xbase++
Xbase++
Azure Create Storage Account
See more Azure Storage Accounts Examples
Demonstrates how to create an Azure storage account.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oJsonToken
LOCAL oJsonRequestBody
LOCAL cUrl
LOCAL oResp
LOCAL oJson
LOCAL cSkuName
LOCAL cSkuTier
LOCAL cKind
LOCAL cId
LOCAL cName
LOCAL cV_type
LOCAL cLocation
LOCAL cPropertiesNetworkAclsBypass
LOCAL cPropertiesNetworkAclsDefaultAction
LOCAL nPropertiesSupportsHttpsTrafficOnly
LOCAL nPropertiesEncryptionServicesFileEnabled
LOCAL cPropertiesEncryptionServicesFileLastEnabledTime
LOCAL nPropertiesEncryptionServicesBlobEnabled
LOCAL cPropertiesEncryptionServicesBlobLastEnabledTime
LOCAL cPropertiesEncryptionKeySource
LOCAL cPropertiesAccessTier
LOCAL cPropertiesProvisioningState
LOCAL cPropertiesCreationTime
LOCAL cPropertiesPrimaryEndpointsDfs
LOCAL cPropertiesPrimaryEndpointsWeb
LOCAL cPropertiesPrimaryEndpointsBlob
LOCAL cPropertiesPrimaryEndpointsQueue
LOCAL cPropertiesPrimaryEndpointsTable
LOCAL cPropertiesPrimaryEndpointsFile
LOCAL cPropertiesPrimaryLocation
LOCAL cPropertiesStatusOfPrimary
LOCAL cPropertiesSecondaryLocation
LOCAL cPropertiesStatusOfSecondary
LOCAL i
LOCAL nCount_i
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
// Load an OAuth2 access token previously fetched by this example: Get Azure OAuth2 Access Token
oJsonToken := CreateObject("Chilkat.JsonObject")
nSuccess := oJsonToken:LoadFile("qa_data/tokens/azureToken.json")
// Assuming success..
oHttp:AuthToken := oJsonToken:StringOf("access_token")
? "AuthToken: " + oHttp:AuthToken
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 := CreateObject("Chilkat.JsonObject")
oJsonRequestBody:UpdateString("sku.name", "Standard_GRS")
oJsonRequestBody:UpdateString("kind", "StorageV2")
oJsonRequestBody:UpdateString("location", "eastus2")
cUrl := "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}?api-version=2018-02-01"
oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpJson("PUT", cUrl, oJsonRequestBody, "application/json", oResp)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oJsonToken:destroy()
oJsonRequestBody:destroy()
oResp:destroy()
RETURN
ENDIF
? "Response Status Code: " + Str(oResp:StatusCode)
oJson := CreateObject("Chilkat.JsonObject")
oJson:Load(oResp:BodyStr)
oJson:EmitCompact := 0
? oJson:Emit()
IF (oResp:StatusCode >= 300)
? "Failed."
oHttp:destroy()
oJsonToken:destroy()
oJsonRequestBody:destroy()
oResp:destroy()
oJson:destroy()
RETURN
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)
? "Azure-AsyncOperation: " + oResp:GetHeaderField("Azure-AsyncOperation")
ENDIF
IF (oResp: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
cSkuName := oJson:StringOf("sku.name")
cSkuTier := oJson:StringOf("sku.tier")
cKind := oJson:StringOf("kind")
cId := oJson:StringOf("id")
cName := oJson:StringOf("name")
cV_type := oJson:StringOf("type")
cLocation := oJson:StringOf("location")
cPropertiesNetworkAclsBypass := oJson:StringOf("properties.networkAcls.bypass")
cPropertiesNetworkAclsDefaultAction := oJson:StringOf("properties.networkAcls.defaultAction")
nPropertiesSupportsHttpsTrafficOnly := oJson:BoolOf("properties.supportsHttpsTrafficOnly")
nPropertiesEncryptionServicesFileEnabled := oJson:BoolOf("properties.encryption.services.file.enabled")
cPropertiesEncryptionServicesFileLastEnabledTime := oJson:StringOf("properties.encryption.services.file.lastEnabledTime")
nPropertiesEncryptionServicesBlobEnabled := oJson:BoolOf("properties.encryption.services.blob.enabled")
cPropertiesEncryptionServicesBlobLastEnabledTime := oJson:StringOf("properties.encryption.services.blob.lastEnabledTime")
cPropertiesEncryptionKeySource := oJson:StringOf("properties.encryption.keySource")
cPropertiesAccessTier := oJson:StringOf("properties.accessTier")
cPropertiesProvisioningState := oJson:StringOf("properties.provisioningState")
cPropertiesCreationTime := oJson:StringOf("properties.creationTime")
cPropertiesPrimaryEndpointsDfs := oJson:StringOf("properties.primaryEndpoints.dfs")
cPropertiesPrimaryEndpointsWeb := oJson:StringOf("properties.primaryEndpoints.web")
cPropertiesPrimaryEndpointsBlob := oJson:StringOf("properties.primaryEndpoints.blob")
cPropertiesPrimaryEndpointsQueue := oJson:StringOf("properties.primaryEndpoints.queue")
cPropertiesPrimaryEndpointsTable := oJson:StringOf("properties.primaryEndpoints.table")
cPropertiesPrimaryEndpointsFile := oJson:StringOf("properties.primaryEndpoints.file")
cPropertiesPrimaryLocation := oJson:StringOf("properties.primaryLocation")
cPropertiesStatusOfPrimary := oJson:StringOf("properties.statusOfPrimary")
cPropertiesSecondaryLocation := oJson:StringOf("properties.secondaryLocation")
cPropertiesStatusOfSecondary := oJson:StringOf("properties.statusOfSecondary")
ENDIF
? "Success."
oHttp:destroy()
oJsonToken:destroy()
oJsonRequestBody:destroy()
oResp:destroy()
oJson:destroy()