Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

C Web API Examples

Primary Categories

AWS Translate
Activix CRM
Adyen
Amazon MWS
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Bluzone
CardConnect
ClickBank
Clickatell
Cloudfare
DocuSign
ETrade
Etsy
Facebook
GeoOp
GetHarvest
Jira
MYOB

Magento
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Okta OAuth/OIDC
OneLogin OIDC
PayPal
Peoplevox
Populi
QuickBooks
SOAP finkok.com
Shippo
Shopify
Stripe
SugarCRM
Trello
Twitter
VoiceBase
Vonage
Walmart
Walmart v3
Xero
eBay
effectconnect

 

 

 

(C) Azure Create Storage Account

Demonstrates how to create an Azure storage account.

Chilkat C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Win Mobile 5.0/Pocket PC 2003

Solaris C/C++

FreeBSD C/C++

OpenBSD C/C++

MinGW C/C++

#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    HCkJsonObject jsonToken;
    BOOL success;
    HCkJsonObject jsonRequestBody;
    const char *url;
    HCkHttpResponse resp;
    HCkJsonObject json;
    const char *skuName;
    const char *skuTier;
    const char *kind;
    const char *id;
    const char *name;
    const char *v_type;
    const char *location;
    const char *propertiesNetworkAclsBypass;
    const char *propertiesNetworkAclsDefaultAction;
    BOOL propertiesSupportsHttpsTrafficOnly;
    BOOL propertiesEncryptionServicesFileEnabled;
    const char *propertiesEncryptionServicesFileLastEnabledTime;
    BOOL propertiesEncryptionServicesBlobEnabled;
    const char *propertiesEncryptionServicesBlobLastEnabledTime;
    const char *propertiesEncryptionKeySource;
    const char *propertiesAccessTier;
    const char *propertiesProvisioningState;
    const char *propertiesCreationTime;
    const char *propertiesPrimaryEndpointsDfs;
    const char *propertiesPrimaryEndpointsWeb;
    const char *propertiesPrimaryEndpointsBlob;
    const char *propertiesPrimaryEndpointsQueue;
    const char *propertiesPrimaryEndpointsTable;
    const char *propertiesPrimaryEndpointsFile;
    const char *propertiesPrimaryLocation;
    const char *propertiesStatusOfPrimary;
    const char *propertiesSecondaryLocation;
    const char *propertiesStatusOfSecondary;
    int i;
    int count_i;

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

    http = CkHttp_Create();

    // Load an OAuth2 access token previously fetched by this example:  Get Azure OAuth2 Access Token
    jsonToken = CkJsonObject_Create();
    success = CkJsonObject_LoadFile(jsonToken,"qa_data/tokens/azureToken.json");
    // Assuming success..
    CkHttp_putAuthToken(http,CkJsonObject_stringOf(jsonToken,"access_token"));
    printf("AuthToken: %s\n",CkHttp_authToken(http));

    CkHttp_putAccept(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 = CkJsonObject_Create();
    CkJsonObject_UpdateString(jsonRequestBody,"sku.name","Standard_GRS");
    CkJsonObject_UpdateString(jsonRequestBody,"kind","StorageV2");
    CkJsonObject_UpdateString(jsonRequestBody,"location","eastus2");

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

    resp = CkHttp_PText(http,"PUT",url,CkJsonObject_emit(jsonRequestBody),"utf-8","application/json",FALSE,FALSE);
    if (CkHttp_getLastMethodSuccess(http) != TRUE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(jsonToken);
        CkJsonObject_Dispose(jsonRequestBody);
        return;
    }

    printf("Response Status Code: %d\n",CkHttpResponse_getStatusCode(resp));

    json = CkJsonObject_Create();
    CkJsonObject_Load(json,CkHttpResponse_bodyStr(resp));
    CkJsonObject_putEmitCompact(json,FALSE);
    printf("%s\n",CkJsonObject_emit(json));

    if (CkHttpResponse_getStatusCode(resp) >= 300) {
        printf("Failed.\n");
        CkHttpResponse_Dispose(resp);
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(jsonToken);
        CkJsonObject_Dispose(jsonRequestBody);
        CkJsonObject_Dispose(json);
        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 (CkHttpResponse_getStatusCode(resp) == 202) {
        printf("Azure-AsyncOperation: %s\n",CkHttpResponse_getHeaderField(resp,"Azure-AsyncOperation"));
    }

    if (CkHttpResponse_getStatusCode(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 = CkJsonObject_stringOf(json,"sku.name");
        skuTier = CkJsonObject_stringOf(json,"sku.tier");
        kind = CkJsonObject_stringOf(json,"kind");
        id = CkJsonObject_stringOf(json,"id");
        name = CkJsonObject_stringOf(json,"name");
        v_type = CkJsonObject_stringOf(json,"type");
        location = CkJsonObject_stringOf(json,"location");
        propertiesNetworkAclsBypass = CkJsonObject_stringOf(json,"properties.networkAcls.bypass");
        propertiesNetworkAclsDefaultAction = CkJsonObject_stringOf(json,"properties.networkAcls.defaultAction");
        propertiesSupportsHttpsTrafficOnly = CkJsonObject_BoolOf(json,"properties.supportsHttpsTrafficOnly");
        propertiesEncryptionServicesFileEnabled = CkJsonObject_BoolOf(json,"properties.encryption.services.file.enabled");
        propertiesEncryptionServicesFileLastEnabledTime = CkJsonObject_stringOf(json,"properties.encryption.services.file.lastEnabledTime");
        propertiesEncryptionServicesBlobEnabled = CkJsonObject_BoolOf(json,"properties.encryption.services.blob.enabled");
        propertiesEncryptionServicesBlobLastEnabledTime = CkJsonObject_stringOf(json,"properties.encryption.services.blob.lastEnabledTime");
        propertiesEncryptionKeySource = CkJsonObject_stringOf(json,"properties.encryption.keySource");
        propertiesAccessTier = CkJsonObject_stringOf(json,"properties.accessTier");
        propertiesProvisioningState = CkJsonObject_stringOf(json,"properties.provisioningState");
        propertiesCreationTime = CkJsonObject_stringOf(json,"properties.creationTime");
        propertiesPrimaryEndpointsDfs = CkJsonObject_stringOf(json,"properties.primaryEndpoints.dfs");
        propertiesPrimaryEndpointsWeb = CkJsonObject_stringOf(json,"properties.primaryEndpoints.web");
        propertiesPrimaryEndpointsBlob = CkJsonObject_stringOf(json,"properties.primaryEndpoints.blob");
        propertiesPrimaryEndpointsQueue = CkJsonObject_stringOf(json,"properties.primaryEndpoints.queue");
        propertiesPrimaryEndpointsTable = CkJsonObject_stringOf(json,"properties.primaryEndpoints.table");
        propertiesPrimaryEndpointsFile = CkJsonObject_stringOf(json,"properties.primaryEndpoints.file");
        propertiesPrimaryLocation = CkJsonObject_stringOf(json,"properties.primaryLocation");
        propertiesStatusOfPrimary = CkJsonObject_stringOf(json,"properties.statusOfPrimary");
        propertiesSecondaryLocation = CkJsonObject_stringOf(json,"properties.secondaryLocation");
        propertiesStatusOfSecondary = CkJsonObject_stringOf(json,"properties.statusOfSecondary");
    }

    printf("Success.\n");

    CkHttpResponse_Dispose(resp);


    CkHttp_Dispose(http);
    CkJsonObject_Dispose(jsonToken);
    CkJsonObject_Dispose(jsonRequestBody);
    CkJsonObject_Dispose(json);

    }

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.