Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) Azure Create Storage AccountDemonstrates how to create an Azure storage account.
IncludeFile "CkHttpResponse.pb" IncludeFile "CkHttp.pb" IncludeFile "CkJsonObject.pb" Procedure ChilkatExample() ; This example requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Load an OAuth2 access token previously fetched by this example: Get Azure OAuth2 Access Token jsonToken.i = CkJsonObject::ckCreate() If jsonToken.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i = CkJsonObject::ckLoadFile(jsonToken,"qa_data/tokens/azureToken.json") ; Assuming success.. CkHttp::setCkAuthToken(http, CkJsonObject::ckStringOf(jsonToken,"access_token")) Debug "AuthToken: " + CkHttp::ckAuthToken(http) CkHttp::setCkAccept(http, "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.i = CkJsonObject::ckCreate() If jsonRequestBody.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckUpdateString(jsonRequestBody,"sku.name","Standard_GRS") CkJsonObject::ckUpdateString(jsonRequestBody,"kind","StorageV2") CkJsonObject::ckUpdateString(jsonRequestBody,"location","eastus2") url.s = "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}?api-version=2018-02-01" resp.i = CkHttp::ckPText(http,"PUT",url,CkJsonObject::ckEmit(jsonRequestBody),"utf-8","application/json",0,0) If CkHttp::ckLastMethodSuccess(http) <> 1 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkJsonObject::ckDispose(jsonToken) CkJsonObject::ckDispose(jsonRequestBody) ProcedureReturn EndIf Debug "Response Status Code: " + Str(CkHttpResponse::ckStatusCode(resp)) json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoad(json,CkHttpResponse::ckBodyStr(resp)) CkJsonObject::setCkEmitCompact(json, 0) Debug CkJsonObject::ckEmit(json) If CkHttpResponse::ckStatusCode(resp) >= 300 Debug "Failed." CkHttpResponse::ckDispose(resp) CkHttp::ckDispose(http) CkJsonObject::ckDispose(jsonToken) CkJsonObject::ckDispose(jsonRequestBody) CkJsonObject::ckDispose(json) ProcedureReturn 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 CkHttpResponse::ckStatusCode(resp) = 202 Debug "Azure-AsyncOperation: " + CkHttpResponse::ckGetHeaderField(resp,"Azure-AsyncOperation") EndIf If CkHttpResponse::ckStatusCode(resp) = 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.s skuTier.s kind.s id.s name.s v_type.s location.s propertiesNetworkAclsBypass.s propertiesNetworkAclsDefaultAction.s propertiesSupportsHttpsTrafficOnly.i propertiesEncryptionServicesFileEnabled.i propertiesEncryptionServicesFileLastEnabledTime.s propertiesEncryptionServicesBlobEnabled.i propertiesEncryptionServicesBlobLastEnabledTime.s propertiesEncryptionKeySource.s propertiesAccessTier.s propertiesProvisioningState.s propertiesCreationTime.s propertiesPrimaryEndpointsDfs.s propertiesPrimaryEndpointsWeb.s propertiesPrimaryEndpointsBlob.s propertiesPrimaryEndpointsQueue.s propertiesPrimaryEndpointsTable.s propertiesPrimaryEndpointsFile.s propertiesPrimaryLocation.s propertiesStatusOfPrimary.s propertiesSecondaryLocation.s propertiesStatusOfSecondary.s i.i count_i.i skuName = CkJsonObject::ckStringOf(json,"sku.name") skuTier = CkJsonObject::ckStringOf(json,"sku.tier") kind = CkJsonObject::ckStringOf(json,"kind") id = CkJsonObject::ckStringOf(json,"id") name = CkJsonObject::ckStringOf(json,"name") v_type = CkJsonObject::ckStringOf(json,"type") location = CkJsonObject::ckStringOf(json,"location") propertiesNetworkAclsBypass = CkJsonObject::ckStringOf(json,"properties.networkAcls.bypass") propertiesNetworkAclsDefaultAction = CkJsonObject::ckStringOf(json,"properties.networkAcls.defaultAction") propertiesSupportsHttpsTrafficOnly = CkJsonObject::ckBoolOf(json,"properties.supportsHttpsTrafficOnly") propertiesEncryptionServicesFileEnabled = CkJsonObject::ckBoolOf(json,"properties.encryption.services.file.enabled") propertiesEncryptionServicesFileLastEnabledTime = CkJsonObject::ckStringOf(json,"properties.encryption.services.file.lastEnabledTime") propertiesEncryptionServicesBlobEnabled = CkJsonObject::ckBoolOf(json,"properties.encryption.services.blob.enabled") propertiesEncryptionServicesBlobLastEnabledTime = CkJsonObject::ckStringOf(json,"properties.encryption.services.blob.lastEnabledTime") propertiesEncryptionKeySource = CkJsonObject::ckStringOf(json,"properties.encryption.keySource") propertiesAccessTier = CkJsonObject::ckStringOf(json,"properties.accessTier") propertiesProvisioningState = CkJsonObject::ckStringOf(json,"properties.provisioningState") propertiesCreationTime = CkJsonObject::ckStringOf(json,"properties.creationTime") propertiesPrimaryEndpointsDfs = CkJsonObject::ckStringOf(json,"properties.primaryEndpoints.dfs") propertiesPrimaryEndpointsWeb = CkJsonObject::ckStringOf(json,"properties.primaryEndpoints.web") propertiesPrimaryEndpointsBlob = CkJsonObject::ckStringOf(json,"properties.primaryEndpoints.blob") propertiesPrimaryEndpointsQueue = CkJsonObject::ckStringOf(json,"properties.primaryEndpoints.queue") propertiesPrimaryEndpointsTable = CkJsonObject::ckStringOf(json,"properties.primaryEndpoints.table") propertiesPrimaryEndpointsFile = CkJsonObject::ckStringOf(json,"properties.primaryEndpoints.file") propertiesPrimaryLocation = CkJsonObject::ckStringOf(json,"properties.primaryLocation") propertiesStatusOfPrimary = CkJsonObject::ckStringOf(json,"properties.statusOfPrimary") propertiesSecondaryLocation = CkJsonObject::ckStringOf(json,"properties.secondaryLocation") propertiesStatusOfSecondary = CkJsonObject::ckStringOf(json,"properties.statusOfSecondary") EndIf Debug "Success." CkHttpResponse::ckDispose(resp) CkHttp::ckDispose(http) CkJsonObject::ckDispose(jsonToken) CkJsonObject::ckDispose(jsonRequestBody) CkJsonObject::ckDispose(json) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.