Chilkat Online Tools

CreateLicenseVersion unicodeCpp Example

AWS License Manager

#include <CkRestW.h>
#include <CkAuthAwsW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>

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

    CkRestW rest;
    bool success;

    CkAuthAwsW authAws;
    authAws.put_AccessKey(L"AWS_ACCESS_KEY");
    authAws.put_SecretKey(L"AWS_SECRET_KEY");

    // Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
    authAws.put_Region(L"us-west-2");
    authAws.put_ServiceName(L"license-manager");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.SetAuthAws(authAws);

    // URL: https://license-manager.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect(L"license-manager.us-west-2.amazonaws.com",443,true,true);
    if (success != true) {
        wprintf(L"ConnectFailReason: %d\n",rest.get_ConnectFailReason());
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    // The following code creates the JSON request body.
    // The JSON created by this code is shown below.

    // Use this online tool to generate code from sample JSON:
    // Generate Code to Create JSON

    CkJsonObjectW json;
    json.UpdateString(L"ClientToken",L"string");
    json.UpdateInt(L"ConsumptionConfiguration.BorrowConfiguration.AllowEarlyCheckIn",123);
    json.UpdateInt(L"ConsumptionConfiguration.BorrowConfiguration.MaxTimeToLiveInMinutes",123);
    json.UpdateInt(L"ConsumptionConfiguration.ProvisionalConfiguration.MaxTimeToLiveInMinutes",123);
    json.UpdateString(L"ConsumptionConfiguration.RenewType",L"string");
    json.UpdateInt(L"Entitlements[0].AllowCheckIn",123);
    json.UpdateInt(L"Entitlements[0].MaxCount",123);
    json.UpdateString(L"Entitlements[0].Name",L"string");
    json.UpdateInt(L"Entitlements[0].Overage",123);
    json.UpdateString(L"Entitlements[0].Unit",L"string");
    json.UpdateString(L"Entitlements[0].Value",L"string");
    json.UpdateString(L"HomeRegion",L"string");
    json.UpdateString(L"Issuer.Name",L"string");
    json.UpdateString(L"Issuer.SignKey",L"string");
    json.UpdateString(L"LicenseArn",L"string");
    json.UpdateString(L"LicenseMetadata[0].Name",L"string");
    json.UpdateString(L"LicenseMetadata[0].Value",L"string");
    json.UpdateString(L"LicenseName",L"string");
    json.UpdateString(L"ProductName",L"string");
    json.UpdateString(L"SourceVersion",L"string");
    json.UpdateString(L"Status",L"string");
    json.UpdateString(L"Validity.Begin",L"string");
    json.UpdateString(L"Validity.End",L"string");

    // The JSON request body created by the above code:

    // {
    //   "ClientToken": "string",
    //   "ConsumptionConfiguration": {
    //     "BorrowConfiguration": {
    //       "AllowEarlyCheckIn": boolean,
    //       "MaxTimeToLiveInMinutes": number
    //     },
    //     "ProvisionalConfiguration": {
    //       "MaxTimeToLiveInMinutes": number
    //     },
    //     "RenewType": "string"
    //   },
    //   "Entitlements": [
    //     {
    //       "AllowCheckIn": boolean,
    //       "MaxCount": number,
    //       "Name": "string",
    //       "Overage": boolean,
    //       "Unit": "string",
    //       "Value": "string"
    //     }
    //   ],
    //   "HomeRegion": "string",
    //   "Issuer": {
    //     "Name": "string",
    //     "SignKey": "string"
    //   },
    //   "LicenseArn": "string",
    //   "LicenseMetadata": [
    //     {
    //       "Name": "string",
    //       "Value": "string"
    //     }
    //   ],
    //   "LicenseName": "string",
    //   "ProductName": "string",
    //   "SourceVersion": "string",
    //   "Status": "string",
    //   "Validity": {
    //     "Begin": "string",
    //     "End": "string"
    //   }
    // }

    rest.AddHeader(L"Content-Type",L"application/x-amz-json-1.1");
    rest.AddHeader(L"X-Amz-Target",L"AWSLicenseManager.CreateLicenseVersion");

    CkStringBuilderW sbRequestBody;
    json.EmitSb(sbRequestBody);
    CkStringBuilderW sbResponseBody;
    success = rest.FullRequestSb(L"POST",L"/",sbRequestBody,sbResponseBody);
    if (success != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    int respStatusCode = rest.get_ResponseStatusCode();
    wprintf(L"response status code = %d\n",respStatusCode);
    if (respStatusCode != 200) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",rest.responseHeader());
        wprintf(L"Response Body:\n");
        wprintf(L"%s\n",sbResponseBody.getAsString());
        return;
    }

    CkJsonObjectW jResp;
    jResp.LoadSb(sbResponseBody);

    // The following code parses the JSON response.
    // A sample JSON response is shown below the sample code.

    // Use this online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
    // See this example explaining how this memory should be used: const char * functions.

    const wchar_t *LicenseArn = jResp.stringOf(L"LicenseArn");
    const wchar_t *Status = jResp.stringOf(L"Status");
    const wchar_t *Version = jResp.stringOf(L"Version");

    // A sample JSON response body parsed by the above code:

    // {
    //   "LicenseArn": "string",
    //   "Status": "string",
    //   "Version": "string"
    // }
    }