Chilkat Online Tools

Node.js / ORACLE Hospitality OPERA Cloud REST API Workflows / Update an existing Rate Plan

Back to Collection Items

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node21-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node21-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node21-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node21-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node21-linux64');
    }
} else if (os.platform() == 'darwin') {
    if (os.arch() == 'arm64') {
        var chilkat = require('@chilkat/ck-node21-mac-m1');
    } else {
        var chilkat = require('@chilkat/ck-node21-macosx');
    }
}


function chilkatExample() {

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

    var http = new chilkat.Http();
    var 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
    //   }
    // }

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

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

    var sbRequestBody = new chilkat.StringBuilder();
    json.EmitSb(sbRequestBody);

    // resp: HttpResponse
    var resp = http.PTextSb("PUT","https://domain.com/rtp/v0/hotels/{{HotelId}}/ratePlans/{{RatePlanCode}}",sbRequestBody,"utf-8","application/json;charset=UTF-8",false,false);
    if (http.LastMethodSuccess == false) {
        console.log(http.LastErrorText);
        return;
    }

    console.log(resp.StatusCode);
    console.log(resp.BodyStr);


}

chilkatExample();

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