Chilkat Online Tools

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

Back to Collection Items

#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>
#include <CkHttpResponseW.h>

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

    CkHttpW http;
    bool success;

    // 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
    //   }
    // }

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

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

    CkStringBuilderW sbRequestBody;
    json.EmitSb(sbRequestBody);

    CkHttpResponseW *resp = http.PTextSb(L"PUT",L"https://domain.com/rtp/v0/hotels/{{HotelId}}/ratePlans/{{RatePlanCode}}",sbRequestBody,L"utf-8",L"application/json;charset=UTF-8",false,false);
    if (http.get_LastMethodSuccess() == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    wprintf(L"%d\n",resp->get_StatusCode());
    wprintf(L"%s\n",resp->bodyStr());
    delete resp;
    }

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": [
  ]
}