Chilkat Online Tools

unicodeCpp / ORACLE Hospitality OPERA Cloud REST API Workflows / Create Rate Plan Schedules with a package

Back to Collection Items

#include <CkHttpW.h>
#include <CkJsonObjectW.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.

    // {
    //   "ratePlanScheduleList": [
    //     {
    //       "roomTypeList": [
    //         "DLXK",
    //         "DLXQ"
    //       ],
    //       "sunday": true,
    //       "monday": true,
    //       "tuesday": true,
    //       "wednesday": true,
    //       "thursday": true,
    //       "friday": true,
    //       "saturday": true,
    //       "rateAmounts": {
    //         "onePersonRate": "220",
    //         "twoPersonRate": "250",
    //         "threePersonRate": "280",
    //         "fourPersonRate": "300",
    //         "rateByAgeBuckets": [
    //           {
    //             "minimumAge": "1",
    //             "maximumAge": "17"
    //           }
    //         ],
    //         "overrideFloorAmount": true
    //       },
    //       "classifications": {},
    //       "rateSchedulePackages": {
    //         "packages": [
    //           {
    //             "header": {},
    //             "schedules": [
    //             ],
    //             "code": "PKG2",
    //             "description": "Chocolates Package"
    //           }
    //         ],
    //         "packageGroups": [
    //         ]
    //       },
    //       "tierID": "1",
    //       "start": "2020-12-01",
    //       "end": "2020-12-31"
    //     }
    //   ],
    //   "hotelId": "{{HotelId}}",
    //   "ratePlanCode": "{{RatePlanCode}}"
    // }

    CkJsonObjectW json;
    json.UpdateString(L"ratePlanScheduleList[0].roomTypeList[0]",L"DLXK");
    json.UpdateString(L"ratePlanScheduleList[0].roomTypeList[1]",L"DLXQ");
    json.UpdateBool(L"ratePlanScheduleList[0].sunday",true);
    json.UpdateBool(L"ratePlanScheduleList[0].monday",true);
    json.UpdateBool(L"ratePlanScheduleList[0].tuesday",true);
    json.UpdateBool(L"ratePlanScheduleList[0].wednesday",true);
    json.UpdateBool(L"ratePlanScheduleList[0].thursday",true);
    json.UpdateBool(L"ratePlanScheduleList[0].friday",true);
    json.UpdateBool(L"ratePlanScheduleList[0].saturday",true);
    json.UpdateString(L"ratePlanScheduleList[0].rateAmounts.onePersonRate",L"220");
    json.UpdateString(L"ratePlanScheduleList[0].rateAmounts.twoPersonRate",L"250");
    json.UpdateString(L"ratePlanScheduleList[0].rateAmounts.threePersonRate",L"280");
    json.UpdateString(L"ratePlanScheduleList[0].rateAmounts.fourPersonRate",L"300");
    json.UpdateString(L"ratePlanScheduleList[0].rateAmounts.rateByAgeBuckets[0].minimumAge",L"1");
    json.UpdateString(L"ratePlanScheduleList[0].rateAmounts.rateByAgeBuckets[0].maximumAge",L"17");
    json.UpdateBool(L"ratePlanScheduleList[0].rateAmounts.overrideFloorAmount",true);
    json.UpdateNewObject(L"ratePlanScheduleList[0].classifications");
    json.UpdateNewObject(L"ratePlanScheduleList[0].rateSchedulePackages.packages[0].header");
    json.UpdateNewArray(L"ratePlanScheduleList[0].rateSchedulePackages.packages[0].schedules");
    json.UpdateString(L"ratePlanScheduleList[0].rateSchedulePackages.packages[0].code",L"PKG2");
    json.UpdateString(L"ratePlanScheduleList[0].rateSchedulePackages.packages[0].description",L"Chocolates Package");
    json.UpdateNewArray(L"ratePlanScheduleList[0].rateSchedulePackages.packageGroups");
    json.UpdateString(L"ratePlanScheduleList[0].tierID",L"1");
    json.UpdateString(L"ratePlanScheduleList[0].start",L"2020-12-01");
    json.UpdateString(L"ratePlanScheduleList[0].end",L"2020-12-31");
    json.UpdateString(L"hotelId",L"{{HotelId}}");
    json.UpdateString(L"ratePlanCode",L"{{RatePlanCode}}");

    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}}");

    CkHttpResponseW *resp = http.PostJson3(L"https://domain.com/rtp/v0/hotels/{{HotelId}}/ratePlans/{{RatePlanCode}}/schedules",L"application/json;charset=UTF-8",json);
    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 POST
	-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 '{
    "ratePlanScheduleList": [
        {
            "roomTypeList": [
                "DLXK",
                "DLXQ"
            ],
            "sunday": true,
            "monday": true,
            "tuesday": true,
            "wednesday": true,
            "thursday": true,
            "friday": true,
            "saturday": true,
            "rateAmounts": {
                "onePersonRate": "220",
                "twoPersonRate": "250",
                "threePersonRate": "280",
                "fourPersonRate": "300",
                "rateByAgeBuckets": [
                    {
                        "minimumAge": "1",
                        "maximumAge": "17"
                    }
                ],
                "overrideFloorAmount": true
            },
            "classifications": {},
            "rateSchedulePackages": {
                "packages": [
                    {
                        "header": {},
                        "schedules": [],
                        "code": "PKG2",
                        "description": "Chocolates Package"
                    }
                ],
                "packageGroups": []
            },
            "tierID": "1",
            "start": "2020-12-01",
            "end": "2020-12-31"
        }
    ],
    "hotelId": "{{HotelId}}",
    "ratePlanCode": "{{RatePlanCode}}"
}'
https://domain.com/rtp/v0/hotels/{{HotelId}}/ratePlans/{{RatePlanCode}}/schedules

Postman Collection Item JSON

{
  "name": "Create Rate Plan Schedules with a package",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{Token}}",
          "type": "string"
        }
      ]
    },
    "method": "POST",
    "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    \"ratePlanScheduleList\": [\r\n        {\r\n            \"roomTypeList\": [\r\n                \"DLXK\",\r\n                \"DLXQ\"\r\n            ],\r\n            \"sunday\": true,\r\n            \"monday\": true,\r\n            \"tuesday\": true,\r\n            \"wednesday\": true,\r\n            \"thursday\": true,\r\n            \"friday\": true,\r\n            \"saturday\": true,\r\n            \"rateAmounts\": {\r\n                \"onePersonRate\": \"220\",\r\n                \"twoPersonRate\": \"250\",\r\n                \"threePersonRate\": \"280\",\r\n                \"fourPersonRate\": \"300\",\r\n                \"rateByAgeBuckets\": [\r\n                    {\r\n                        \"minimumAge\": \"1\",\r\n                        \"maximumAge\": \"17\"\r\n                    }\r\n                ],\r\n                \"overrideFloorAmount\": true\r\n            },\r\n            \"classifications\": {},\r\n            \"rateSchedulePackages\": {\r\n                \"packages\": [\r\n                    {\r\n                        \"header\": {},\r\n                        \"schedules\": [],\r\n                        \"code\": \"PKG2\",\r\n                        \"description\": \"Chocolates Package\"\r\n                    }\r\n                ],\r\n                \"packageGroups\": []\r\n            },\r\n            \"tierID\": \"1\",\r\n            \"start\": \"2020-12-01\",\r\n            \"end\": \"2020-12-31\"\r\n        }\r\n    ],\r\n    \"hotelId\": \"{{HotelId}}\",\r\n    \"ratePlanCode\": \"{{RatePlanCode}}\"\r\n}"
    },
    "url": {
      "raw": "{{HostName}}/rtp/v0/hotels/{{HotelId}}/ratePlans/{{RatePlanCode}}/schedules",
      "host": [
        "{{HostName}}"
      ],
      "path": [
        "rtp",
        "v0",
        "hotels",
        "{{HotelId}}",
        "ratePlans",
        "{{RatePlanCode}}",
        "schedules"
      ]
    },
    "description": "Use this operation to add a package (such as Breakfast, or box of chocolated) to a rate plan."
  },
  "response": [
  ]
}