Chilkat Online Tools

C / ORACLE Hospitality OPERA Cloud REST API Workflows / Update an existing Rate Plan

Back to Collection Items

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

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkJsonObject json;
    HCkStringBuilder sbRequestBody;
    HCkHttpResponse resp;

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

    http = CkHttp_Create();

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

    // The following JSON is sent in the request body.

    // {
    //   "ratePlan": {
    //     "primaryDetails": {
    //       "description": {
    //         "defaultText": "Description of rate code "
    //       },
    //       "startSellDate": "2021-07-03",
    //       "endSellDate": "2021-08-31",
    //       "privilegedRate": false,
    //       "privilegedRateRestriction": false,
    //       "lockStatus": "Unlocked"
    //     },
    //     "classifications": {
    //       "rateCategory": "PHONE",
    //       "marketCode": "BUSINESS"
    //     },
    //     "roomTypeList": [
    //       {
    //         "code": "ECO"
    //       },
    //       {
    //         "code": "SUP"
    //       }
    //     ],
    //     "mobileCheckinAllowed": false,
    //     "mobileCheckoutAllowed": false,
    //     "hotelId": "{{HotelId}}",
    //     "ratePlanCode": "{{RatePlanCode}}",
    //     "supressRate": false,
    //     "printRate": true,
    //     "discountAllowed": false,
    //     "redemption": false,
    //     "bARRate": false,
    //     "daily": false,
    //     "tiered": false,
    //     "dayUse": false,
    //     "dayType": false,
    //     "complimentary": false,
    //     "houseUse": false,
    //     "negotiated": false,
    //     "ownerRate": false,
    //     "membershipEligible": true,
    //     "advancedDailyBase": false,
    //     "advancedDailyRate": false
    //   }
    // }

    json = CkJsonObject_Create();
    CkJsonObject_UpdateString(json,"ratePlan.primaryDetails.description.defaultText","Description of rate code ");
    CkJsonObject_UpdateString(json,"ratePlan.primaryDetails.startSellDate","2021-07-03");
    CkJsonObject_UpdateString(json,"ratePlan.primaryDetails.endSellDate","2021-08-31");
    CkJsonObject_UpdateBool(json,"ratePlan.primaryDetails.privilegedRate",FALSE);
    CkJsonObject_UpdateBool(json,"ratePlan.primaryDetails.privilegedRateRestriction",FALSE);
    CkJsonObject_UpdateString(json,"ratePlan.primaryDetails.lockStatus","Unlocked");
    CkJsonObject_UpdateString(json,"ratePlan.classifications.rateCategory","PHONE");
    CkJsonObject_UpdateString(json,"ratePlan.classifications.marketCode","BUSINESS");
    CkJsonObject_UpdateString(json,"ratePlan.roomTypeList[0].code","ECO");
    CkJsonObject_UpdateString(json,"ratePlan.roomTypeList[1].code","SUP");
    CkJsonObject_UpdateBool(json,"ratePlan.mobileCheckinAllowed",FALSE);
    CkJsonObject_UpdateBool(json,"ratePlan.mobileCheckoutAllowed",FALSE);
    CkJsonObject_UpdateString(json,"ratePlan.hotelId","{{HotelId}}");
    CkJsonObject_UpdateString(json,"ratePlan.ratePlanCode","{{RatePlanCode}}");
    CkJsonObject_UpdateBool(json,"ratePlan.supressRate",FALSE);
    CkJsonObject_UpdateBool(json,"ratePlan.printRate",TRUE);
    CkJsonObject_UpdateBool(json,"ratePlan.discountAllowed",FALSE);
    CkJsonObject_UpdateBool(json,"ratePlan.redemption",FALSE);
    CkJsonObject_UpdateBool(json,"ratePlan.bARRate",FALSE);
    CkJsonObject_UpdateBool(json,"ratePlan.daily",FALSE);
    CkJsonObject_UpdateBool(json,"ratePlan.tiered",FALSE);
    CkJsonObject_UpdateBool(json,"ratePlan.dayUse",FALSE);
    CkJsonObject_UpdateBool(json,"ratePlan.dayType",FALSE);
    CkJsonObject_UpdateBool(json,"ratePlan.complimentary",FALSE);
    CkJsonObject_UpdateBool(json,"ratePlan.houseUse",FALSE);
    CkJsonObject_UpdateBool(json,"ratePlan.negotiated",FALSE);
    CkJsonObject_UpdateBool(json,"ratePlan.ownerRate",FALSE);
    CkJsonObject_UpdateBool(json,"ratePlan.membershipEligible",TRUE);
    CkJsonObject_UpdateBool(json,"ratePlan.advancedDailyBase",FALSE);
    CkJsonObject_UpdateBool(json,"ratePlan.advancedDailyRate",FALSE);

    CkHttp_SetRequestHeader(http,"Content-Type","application/json;charset=UTF-8");
    CkHttp_SetRequestHeader(http,"x-hotelid","{{HotelId}}");
    // Adds the "Authorization: Bearer <access_token>" header.
    CkHttp_putAuthToken(http,"<access_token>");
    CkHttp_SetRequestHeader(http,"Accept","application/json;charset=UTF-8");
    CkHttp_SetRequestHeader(http,"x-app-key","{{AppKey}}");

    sbRequestBody = CkStringBuilder_Create();
    CkJsonObject_EmitSb(json,sbRequestBody);

    resp = CkHttp_PTextSb(http,"PUT","https://domain.com/rtp/v0/hotels/{{HotelId}}/ratePlans/{{RatePlanCode}}",sbRequestBody,"utf-8","application/json;charset=UTF-8",FALSE,FALSE);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(json);
        CkStringBuilder_Dispose(sbRequestBody);
        return;
    }

    printf("%d\n",CkHttpResponse_getStatusCode(resp));
    printf("%s\n",CkHttpResponse_bodyStr(resp));
    CkHttpResponse_Dispose(resp);


    CkHttp_Dispose(http);
    CkJsonObject_Dispose(json);
    CkStringBuilder_Dispose(sbRequestBody);

    }

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json;charset=UTF-8"
	-H "Accept: application/json;charset=UTF-8"
	-H "x-hotelid: {{HotelId}}"
	-H "x-app-key: {{AppKey}}"
	-d '{
    "ratePlan": {
        "primaryDetails": {
            "description": {
                "defaultText": "Description of rate code "
            },
            "startSellDate": "2021-07-03",
            "endSellDate": "2021-08-31",
            "privilegedRate": false,
            "privilegedRateRestriction": false,
            "lockStatus": "Unlocked"
        },
        "classifications": {
            "rateCategory": "PHONE",
            "marketCode": "BUSINESS"
        },
        "roomTypeList": [
            {
                "code": "ECO"
            },
            {
                "code": "SUP"
            }
        ],
        "mobileCheckinAllowed": false,
        "mobileCheckoutAllowed": false,
        "hotelId": "{{HotelId}}",
        "ratePlanCode": "{{RatePlanCode}}",
        "supressRate": false,
        "printRate": true,
        "discountAllowed": false,
        "redemption": false,
        "bARRate": false,
        "daily": false,
        "tiered": false,
        "dayUse": false,
        "dayType": false,
        "complimentary": false,
        "houseUse": false,
        "negotiated": false,
        "ownerRate": false,
        "membershipEligible": true,
        "advancedDailyBase": false,
        "advancedDailyRate": false
    }
}'
https://domain.com/rtp/v0/hotels/{{HotelId}}/ratePlans/{{RatePlanCode}}

Postman Collection Item JSON

{
  "name": "Update an existing Rate Plan",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{Token}}",
          "type": "string"
        }
      ]
    },
    "method": "PUT",
    "header": [
      {
        "key": "Content-Type",
        "type": "text",
        "value": "application/json;charset=UTF-8"
      },
      {
        "key": "Accept",
        "type": "text",
        "value": "application/json;charset=UTF-8"
      },
      {
        "key": "x-hotelid",
        "type": "text",
        "value": "{{HotelId}}"
      },
      {
        "key": "x-app-key",
        "type": "text",
        "value": "{{AppKey}}"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\r\n    \"ratePlan\": {\r\n        \"primaryDetails\": {\r\n            \"description\": {\r\n                \"defaultText\": \"Description of rate code \"\r\n            },\r\n            \"startSellDate\": \"2021-07-03\",\r\n            \"endSellDate\": \"2021-08-31\",\r\n            \"privilegedRate\": false,\r\n            \"privilegedRateRestriction\": false,\r\n            \"lockStatus\": \"Unlocked\"\r\n        },\r\n        \"classifications\": {\r\n            \"rateCategory\": \"PHONE\",\r\n            \"marketCode\": \"BUSINESS\"\r\n        },\r\n        \"roomTypeList\": [\r\n            {\r\n                \"code\": \"ECO\"\r\n            },\r\n            {\r\n                \"code\": \"SUP\"\r\n            }\r\n        ],\r\n        \"mobileCheckinAllowed\": false,\r\n        \"mobileCheckoutAllowed\": false,\r\n        \"hotelId\": \"{{HotelId}}\",\r\n        \"ratePlanCode\": \"{{RatePlanCode}}\",\r\n        \"supressRate\": false,\r\n        \"printRate\": true,\r\n        \"discountAllowed\": false,\r\n        \"redemption\": false,\r\n        \"bARRate\": false,\r\n        \"daily\": false,\r\n        \"tiered\": false,\r\n        \"dayUse\": false,\r\n        \"dayType\": false,\r\n        \"complimentary\": false,\r\n        \"houseUse\": false,\r\n        \"negotiated\": false,\r\n        \"ownerRate\": false,\r\n        \"membershipEligible\": true,\r\n        \"advancedDailyBase\": false,\r\n        \"advancedDailyRate\": false\r\n    }\r\n}"
    },
    "url": {
      "raw": "{{HostName}}/rtp/v0/hotels/{{HotelId}}/ratePlans/{{RatePlanCode}}",
      "host": [
        "{{HostName}}"
      ],
      "path": [
        "rtp",
        "v0",
        "hotels",
        "{{HotelId}}",
        "ratePlans",
        "{{RatePlanCode}}"
      ]
    }
  },
  "response": [
  ]
}