Chilkat Examples

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

Unicode C Web API Examples

Primary Categories

ABN AMRO
AWS Translate
Activix CRM
Adyen
Amazon MWS
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Bitfinex v2 REST
Bluzone
CardConnect
ClickBank
Clickatell
Cloudfare
DocuSign
ETrade
Etsy
Facebook
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Hungary NAV Invoicing
IBM Text to Speech
Jira
MYOB
Magento

MercadoLibre
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Okta OAuth/OIDC
OneLogin OIDC
PayPal
Peoplevox
Populi
QuickBooks
Rabobank
SOAP finkok.com
Shippo
Shopify
SimpleTexting
Square
Stripe
SugarCRM
Trello
Twilio
Twitter
VoiceBase
Vonage
Walmart
Walmart v3
WhatsApp
WooCommerce
Xero
Yousign
_Miscellaneous_
eBay
effectconnect

 

 

 

(Unicode 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_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    HCkJsonObjectW jsonToken;
    BOOL success;
    HCkJsonObjectW jsonRequestBody;
    const wchar_t *url;
    HCkHttpResponseW resp;
    HCkJsonObjectW json;
    const wchar_t *skuName;
    const wchar_t *skuTier;
    const wchar_t *kind;
    const wchar_t *id;
    const wchar_t *name;
    const wchar_t *v_type;
    const wchar_t *location;
    const wchar_t *propertiesNetworkAclsBypass;
    const wchar_t *propertiesNetworkAclsDefaultAction;
    BOOL propertiesSupportsHttpsTrafficOnly;
    BOOL propertiesEncryptionServicesFileEnabled;
    const wchar_t *propertiesEncryptionServicesFileLastEnabledTime;
    BOOL propertiesEncryptionServicesBlobEnabled;
    const wchar_t *propertiesEncryptionServicesBlobLastEnabledTime;
    const wchar_t *propertiesEncryptionKeySource;
    const wchar_t *propertiesAccessTier;
    const wchar_t *propertiesProvisioningState;
    const wchar_t *propertiesCreationTime;
    const wchar_t *propertiesPrimaryEndpointsDfs;
    const wchar_t *propertiesPrimaryEndpointsWeb;
    const wchar_t *propertiesPrimaryEndpointsBlob;
    const wchar_t *propertiesPrimaryEndpointsQueue;
    const wchar_t *propertiesPrimaryEndpointsTable;
    const wchar_t *propertiesPrimaryEndpointsFile;
    const wchar_t *propertiesPrimaryLocation;
    const wchar_t *propertiesStatusOfPrimary;
    const wchar_t *propertiesSecondaryLocation;
    const wchar_t *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 = CkHttpW_Create();

    // Load an OAuth2 access token previously fetched by this example:  Get Azure OAuth2 Access Token
    jsonToken = CkJsonObjectW_Create();
    success = CkJsonObjectW_LoadFile(jsonToken,L"qa_data/tokens/azureToken.json");
    // Assuming success..
    CkHttpW_putAuthToken(http,CkJsonObjectW_stringOf(jsonToken,L"access_token"));
    wprintf(L"AuthToken: %s\n",CkHttpW_authToken(http));

    CkHttpW_putAccept(http,L"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 = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(jsonRequestBody,L"sku.name",L"Standard_GRS");
    CkJsonObjectW_UpdateString(jsonRequestBody,L"kind",L"StorageV2");
    CkJsonObjectW_UpdateString(jsonRequestBody,L"location",L"eastus2");

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

    resp = CkHttpW_PText(http,L"PUT",url,CkJsonObjectW_emit(jsonRequestBody),L"utf-8",L"application/json",FALSE,FALSE);
    if (CkHttpW_getLastMethodSuccess(http) != TRUE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(jsonToken);
        CkJsonObjectW_Dispose(jsonRequestBody);
        return;
    }

    wprintf(L"Response Status Code: %d\n",CkHttpResponseW_getStatusCode(resp));

    json = CkJsonObjectW_Create();
    CkJsonObjectW_Load(json,CkHttpResponseW_bodyStr(resp));
    CkJsonObjectW_putEmitCompact(json,FALSE);
    wprintf(L"%s\n",CkJsonObjectW_emit(json));

    if (CkHttpResponseW_getStatusCode(resp) >= 300) {
        wprintf(L"Failed.\n");
        CkHttpResponseW_Dispose(resp);
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(jsonToken);
        CkJsonObjectW_Dispose(jsonRequestBody);
        CkJsonObjectW_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 (CkHttpResponseW_getStatusCode(resp) == 202) {
        wprintf(L"Azure-AsyncOperation: %s\n",CkHttpResponseW_getHeaderField(resp,L"Azure-AsyncOperation"));
    }

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

    wprintf(L"Success.\n");

    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(jsonToken);
    CkJsonObjectW_Dispose(jsonRequestBody);
    CkJsonObjectW_Dispose(json);

    }

 

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