Chilkat Online Tools

CreateSite C Example

AWS Outposts

#include <C_CkRest.h>
#include <C_CkAuthAws.h>
#include <C_CkJsonObject.h>
#include <C_CkStringBuilder.h>

void ChilkatSample(void)
    {
    HCkRest rest;
    BOOL success;
    HCkAuthAws authAws;
    HCkJsonObject json;
    HCkStringBuilder sbRequestBody;
    HCkStringBuilder sbResponseBody;
    int respStatusCode;
    HCkJsonObject jResp;
    const char *AccountId;
    const char *Description;
    const char *Name;
    const char *Notes;
    const char *OperatingAddressCity;
    const char *OperatingAddressCountryCode;
    const char *OperatingAddressStateOrRegion;
    const char *FiberOpticCableType;
    const char *MaximumSupportedWeightLbs;
    const char *OpticalStandard;
    const char *PowerConnector;
    const char *PowerDrawKva;
    const char *PowerFeedDrop;
    const char *PowerPhase;
    const char *UplinkCount;
    const char *UplinkGbps;
    const char *SiteArn;
    const char *SiteId;
    const char *v_String;

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

    rest = CkRest_Create();

    authAws = CkAuthAws_Create();
    CkAuthAws_putAccessKey(authAws,"AWS_ACCESS_KEY");
    CkAuthAws_putSecretKey(authAws,"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.)
    CkAuthAws_putRegion(authAws,"us-west-2");
    CkAuthAws_putServiceName(authAws,"outposts");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    CkRest_SetAuthAws(rest,authAws);

    // URL: https://outposts.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = CkRest_Connect(rest,"outposts.us-west-2.amazonaws.com",443,TRUE,TRUE);
    if (success != TRUE) {
        printf("ConnectFailReason: %d\n",CkRest_getConnectFailReason(rest));
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        CkAuthAws_Dispose(authAws);
        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

    json = CkJsonObject_Create();
    CkJsonObject_UpdateString(json,"Description","string");
    CkJsonObject_UpdateString(json,"Name","string");
    CkJsonObject_UpdateString(json,"Notes","string");
    CkJsonObject_UpdateString(json,"OperatingAddress.AddressLine1","string");
    CkJsonObject_UpdateString(json,"OperatingAddress.AddressLine2","string");
    CkJsonObject_UpdateString(json,"OperatingAddress.AddressLine3","string");
    CkJsonObject_UpdateString(json,"OperatingAddress.City","string");
    CkJsonObject_UpdateString(json,"OperatingAddress.ContactName","string");
    CkJsonObject_UpdateString(json,"OperatingAddress.ContactPhoneNumber","string");
    CkJsonObject_UpdateString(json,"OperatingAddress.CountryCode","string");
    CkJsonObject_UpdateString(json,"OperatingAddress.DistrictOrCounty","string");
    CkJsonObject_UpdateString(json,"OperatingAddress.Municipality","string");
    CkJsonObject_UpdateString(json,"OperatingAddress.PostalCode","string");
    CkJsonObject_UpdateString(json,"OperatingAddress.StateOrRegion","string");
    CkJsonObject_UpdateString(json,"RackPhysicalProperties.FiberOpticCableType","string");
    CkJsonObject_UpdateString(json,"RackPhysicalProperties.MaximumSupportedWeightLbs","string");
    CkJsonObject_UpdateString(json,"RackPhysicalProperties.OpticalStandard","string");
    CkJsonObject_UpdateString(json,"RackPhysicalProperties.PowerConnector","string");
    CkJsonObject_UpdateString(json,"RackPhysicalProperties.PowerDrawKva","string");
    CkJsonObject_UpdateString(json,"RackPhysicalProperties.PowerFeedDrop","string");
    CkJsonObject_UpdateString(json,"RackPhysicalProperties.PowerPhase","string");
    CkJsonObject_UpdateString(json,"RackPhysicalProperties.UplinkCount","string");
    CkJsonObject_UpdateString(json,"RackPhysicalProperties.UplinkGbps","string");
    CkJsonObject_UpdateString(json,"ShippingAddress.AddressLine1","string");
    CkJsonObject_UpdateString(json,"ShippingAddress.AddressLine2","string");
    CkJsonObject_UpdateString(json,"ShippingAddress.AddressLine3","string");
    CkJsonObject_UpdateString(json,"ShippingAddress.City","string");
    CkJsonObject_UpdateString(json,"ShippingAddress.ContactName","string");
    CkJsonObject_UpdateString(json,"ShippingAddress.ContactPhoneNumber","string");
    CkJsonObject_UpdateString(json,"ShippingAddress.CountryCode","string");
    CkJsonObject_UpdateString(json,"ShippingAddress.DistrictOrCounty","string");
    CkJsonObject_UpdateString(json,"ShippingAddress.Municipality","string");
    CkJsonObject_UpdateString(json,"ShippingAddress.PostalCode","string");
    CkJsonObject_UpdateString(json,"ShippingAddress.StateOrRegion","string");
    CkJsonObject_UpdateString(json,"Tags.string","string");

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

    // {
    //   "Description": "string",
    //   "Name": "string",
    //   "Notes": "string",
    //   "OperatingAddress": {
    //     "AddressLine1": "string",
    //     "AddressLine2": "string",
    //     "AddressLine3": "string",
    //     "City": "string",
    //     "ContactName": "string",
    //     "ContactPhoneNumber": "string",
    //     "CountryCode": "string",
    //     "DistrictOrCounty": "string",
    //     "Municipality": "string",
    //     "PostalCode": "string",
    //     "StateOrRegion": "string"
    //   },
    //   "RackPhysicalProperties": {
    //     "FiberOpticCableType": "string",
    //     "MaximumSupportedWeightLbs": "string",
    //     "OpticalStandard": "string",
    //     "PowerConnector": "string",
    //     "PowerDrawKva": "string",
    //     "PowerFeedDrop": "string",
    //     "PowerPhase": "string",
    //     "UplinkCount": "string",
    //     "UplinkGbps": "string"
    //   },
    //   "ShippingAddress": {
    //     "AddressLine1": "string",
    //     "AddressLine2": "string",
    //     "AddressLine3": "string",
    //     "City": "string",
    //     "ContactName": "string",
    //     "ContactPhoneNumber": "string",
    //     "CountryCode": "string",
    //     "DistrictOrCounty": "string",
    //     "Municipality": "string",
    //     "PostalCode": "string",
    //     "StateOrRegion": "string"
    //   },
    //   "Tags": {
    //     "string": "string"
    //   }
    // }

    CkRest_AddHeader(rest,"Content-Type","application/x-amz-json-1.1");
    CkRest_AddHeader(rest,"X-Amz-Target","CreateSite");

    sbRequestBody = CkStringBuilder_Create();
    CkJsonObject_EmitSb(json,sbRequestBody);
    sbResponseBody = CkStringBuilder_Create();
    success = CkRest_FullRequestSb(rest,"POST","/sites",sbRequestBody,sbResponseBody);
    if (success != TRUE) {
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        CkAuthAws_Dispose(authAws);
        CkJsonObject_Dispose(json);
        CkStringBuilder_Dispose(sbRequestBody);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

    respStatusCode = CkRest_getResponseStatusCode(rest);
    printf("response status code = %d\n",respStatusCode);
    if (respStatusCode != 200) {
        printf("Response Header:\n");
        printf("%s\n",CkRest_responseHeader(rest));
        printf("Response Body:\n");
        printf("%s\n",CkStringBuilder_getAsString(sbResponseBody));
        CkRest_Dispose(rest);
        CkAuthAws_Dispose(authAws);
        CkJsonObject_Dispose(json);
        CkStringBuilder_Dispose(sbRequestBody);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

    jResp = CkJsonObject_Create();
    CkJsonObject_LoadSb(jResp,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.

    AccountId = CkJsonObject_stringOf(jResp,"Site.AccountId");
    Description = CkJsonObject_stringOf(jResp,"Site.Description");
    Name = CkJsonObject_stringOf(jResp,"Site.Name");
    Notes = CkJsonObject_stringOf(jResp,"Site.Notes");
    OperatingAddressCity = CkJsonObject_stringOf(jResp,"Site.OperatingAddressCity");
    OperatingAddressCountryCode = CkJsonObject_stringOf(jResp,"Site.OperatingAddressCountryCode");
    OperatingAddressStateOrRegion = CkJsonObject_stringOf(jResp,"Site.OperatingAddressStateOrRegion");
    FiberOpticCableType = CkJsonObject_stringOf(jResp,"Site.RackPhysicalProperties.FiberOpticCableType");
    MaximumSupportedWeightLbs = CkJsonObject_stringOf(jResp,"Site.RackPhysicalProperties.MaximumSupportedWeightLbs");
    OpticalStandard = CkJsonObject_stringOf(jResp,"Site.RackPhysicalProperties.OpticalStandard");
    PowerConnector = CkJsonObject_stringOf(jResp,"Site.RackPhysicalProperties.PowerConnector");
    PowerDrawKva = CkJsonObject_stringOf(jResp,"Site.RackPhysicalProperties.PowerDrawKva");
    PowerFeedDrop = CkJsonObject_stringOf(jResp,"Site.RackPhysicalProperties.PowerFeedDrop");
    PowerPhase = CkJsonObject_stringOf(jResp,"Site.RackPhysicalProperties.PowerPhase");
    UplinkCount = CkJsonObject_stringOf(jResp,"Site.RackPhysicalProperties.UplinkCount");
    UplinkGbps = CkJsonObject_stringOf(jResp,"Site.RackPhysicalProperties.UplinkGbps");
    SiteArn = CkJsonObject_stringOf(jResp,"Site.SiteArn");
    SiteId = CkJsonObject_stringOf(jResp,"Site.SiteId");
    v_String = CkJsonObject_stringOf(jResp,"Site.Tags.string");

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

    // {
    //   "Site": {
    //     "AccountId": "string",
    //     "Description": "string",
    //     "Name": "string",
    //     "Notes": "string",
    //     "OperatingAddressCity": "string",
    //     "OperatingAddressCountryCode": "string",
    //     "OperatingAddressStateOrRegion": "string",
    //     "RackPhysicalProperties": {
    //       "FiberOpticCableType": "string",
    //       "MaximumSupportedWeightLbs": "string",
    //       "OpticalStandard": "string",
    //       "PowerConnector": "string",
    //       "PowerDrawKva": "string",
    //       "PowerFeedDrop": "string",
    //       "PowerPhase": "string",
    //       "UplinkCount": "string",
    //       "UplinkGbps": "string"
    //     },
    //     "SiteArn": "string",
    //     "SiteId": "string",
    //     "Tags": {
    //       "string": "string"
    //     }
    //   }
    // }


    CkRest_Dispose(rest);
    CkAuthAws_Dispose(authAws);
    CkJsonObject_Dispose(json);
    CkStringBuilder_Dispose(sbRequestBody);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jResp);

    }