Chilkat Online Tools

unicodeC / ORACLE Hospitality OPERA Cloud REST API Workflows / Update a Rate Plan Schedule

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkStringBuilderW sbRequestBody;
    HCkHttpResponseW resp;

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

    http = CkHttpW_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.

    // {
    //   "ratePlanScheduleList": [
    //     {
    //       "ratePlanScheduleId": {
    //         "type": "RateSetId",
    //         "id": "199827"
    //       },
    //       "ratePlanScheduleDetail": {
    //         "roomTypeList": [
    //           "ECO",
    //           "SUP"
    //         ],
    //         "sunday": true,
    //         "monday": true,
    //         "tuesday": true,
    //         "wednesday": true,
    //         "thursday": true,
    //         "friday": true,
    //         "saturday": true,
    //         "rateAmounts": {
    //           "onePersonRate": "305",
    //           "twoPersonRate": "305",
    //           "threePersonRate": "344",
    //           "fourPersonRate": "340",
    //           "fivePersonRate": "400",
    //           "rateByAgeBuckets": [
    //             {
    //               "minimumAge": "0",
    //               "maximumAge": "3"
    //             },
    //             {
    //               "minimumAge": "4",
    //               "maximumAge": "10"
    //             },
    //             {
    //               "minimumAge": "11",
    //               "maximumAge": "17"
    //             }
    //           ],
    //           "overrideFloorAmount": true
    //         },
    //         "rateAmountBoundaries": {
    //           "minimum": {
    //             "onePersonRate": "300"
    //           },
    //           "maximum": {}
    //         },
    //         "classifications": {},
    //         "rateSchedulePackages": {
    //           "packages": [
    //           ],
    //           "packageGroups": [
    //           ]
    //         },
    //         "tierID": "1",
    //         "start": "2021-03-11",
    //         "end": "2021-03-31"
    //       }
    //     }
    //   ],
    //   "hotelId": "{{HotelId}}",
    //   "ratePlanCode": "{{RatePlanCode}}"
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].ratePlanScheduleId.type",L"RateSetId");
    CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].ratePlanScheduleId.id",L"199827");
    CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.roomTypeList[0]",L"ECO");
    CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.roomTypeList[1]",L"SUP");
    CkJsonObjectW_UpdateBool(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.sunday",TRUE);
    CkJsonObjectW_UpdateBool(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.monday",TRUE);
    CkJsonObjectW_UpdateBool(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.tuesday",TRUE);
    CkJsonObjectW_UpdateBool(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.wednesday",TRUE);
    CkJsonObjectW_UpdateBool(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.thursday",TRUE);
    CkJsonObjectW_UpdateBool(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.friday",TRUE);
    CkJsonObjectW_UpdateBool(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.saturday",TRUE);
    CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.onePersonRate",L"305");
    CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.twoPersonRate",L"305");
    CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.threePersonRate",L"344");
    CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.fourPersonRate",L"340");
    CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.fivePersonRate",L"400");
    CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.rateByAgeBuckets[0].minimumAge",L"0");
    CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.rateByAgeBuckets[0].maximumAge",L"3");
    CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.rateByAgeBuckets[1].minimumAge",L"4");
    CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.rateByAgeBuckets[1].maximumAge",L"10");
    CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.rateByAgeBuckets[2].minimumAge",L"11");
    CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.rateByAgeBuckets[2].maximumAge",L"17");
    CkJsonObjectW_UpdateBool(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.overrideFloorAmount",TRUE);
    CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmountBoundaries.minimum.onePersonRate",L"300");
    CkJsonObjectW_UpdateNewObject(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmountBoundaries.maximum");
    CkJsonObjectW_UpdateNewObject(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.classifications");
    CkJsonObjectW_UpdateNewArray(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.rateSchedulePackages.packages");
    CkJsonObjectW_UpdateNewArray(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.rateSchedulePackages.packageGroups");
    CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.tierID",L"1");
    CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.start",L"2021-03-11");
    CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].ratePlanScheduleDetail.end",L"2021-03-31");
    CkJsonObjectW_UpdateString(json,L"hotelId",L"{{HotelId}}");
    CkJsonObjectW_UpdateString(json,L"ratePlanCode",L"{{RatePlanCode}}");

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

    sbRequestBody = CkStringBuilderW_Create();
    CkJsonObjectW_EmitSb(json,sbRequestBody);

    resp = CkHttpW_PTextSb(http,L"PUT",L"https://domain.com/rtp/v0/hotels/{{HotelId}}/ratePlans/{{RatePlanCode}}/schedules",sbRequestBody,L"utf-8",L"application/json;charset=UTF-8",FALSE,FALSE);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);
    CkStringBuilderW_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 '{
    "ratePlanScheduleList": [
        {
            "ratePlanScheduleId": {
                "type": "RateSetId",
                "id": "199827"
            },
            "ratePlanScheduleDetail": {
                "roomTypeList": [
                    "ECO",
                    "SUP"
                ],
                "sunday": true,
                "monday": true,
                "tuesday": true,
                "wednesday": true,
                "thursday": true,
                "friday": true,
                "saturday": true,
                "rateAmounts": {
                    "onePersonRate": "305",
                    "twoPersonRate": "305",
                    "threePersonRate": "344",
                    "fourPersonRate": "340",
                    "fivePersonRate": "400",
                    "rateByAgeBuckets": [
                        {
                            "minimumAge": "0",
                            "maximumAge": "3"
                        },
                        {
                            "minimumAge": "4",
                            "maximumAge": "10"
                        },
                        {
                            "minimumAge": "11",
                            "maximumAge": "17"
                        }
                    ],
                    "overrideFloorAmount": true
                },
                "rateAmountBoundaries": {
                    "minimum": {
                        "onePersonRate": "300"
                    },
                    "maximum": {}
                },
                "classifications": {},
                "rateSchedulePackages": {
                    "packages": [],
                    "packageGroups": []
                },
                "tierID": "1",
                "start": "2021-03-11",
                "end": "2021-03-31"
            }
        }
    ],
    "hotelId": "{{HotelId}}",
    "ratePlanCode": "{{RatePlanCode}}"
}'
https://domain.com/rtp/v0/hotels/{{HotelId}}/ratePlans/{{RatePlanCode}}/schedules

Postman Collection Item JSON

{
  "name": "Update a Rate Plan Schedule",
  "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    \"ratePlanScheduleList\": [\r\n        {\r\n            \"ratePlanScheduleId\": {\r\n                \"type\": \"RateSetId\",\r\n                \"id\": \"199827\"\r\n            },\r\n            \"ratePlanScheduleDetail\": {\r\n                \"roomTypeList\": [\r\n                    \"ECO\",\r\n                    \"SUP\"\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\": \"305\",\r\n                    \"twoPersonRate\": \"305\",\r\n                    \"threePersonRate\": \"344\",\r\n                    \"fourPersonRate\": \"340\",\r\n                    \"fivePersonRate\": \"400\",\r\n                    \"rateByAgeBuckets\": [\r\n                        {\r\n                            \"minimumAge\": \"0\",\r\n                            \"maximumAge\": \"3\"\r\n                        },\r\n                        {\r\n                            \"minimumAge\": \"4\",\r\n                            \"maximumAge\": \"10\"\r\n                        },\r\n                        {\r\n                            \"minimumAge\": \"11\",\r\n                            \"maximumAge\": \"17\"\r\n                        }\r\n                    ],\r\n                    \"overrideFloorAmount\": true\r\n                },\r\n                \"rateAmountBoundaries\": {\r\n                    \"minimum\": {\r\n                        \"onePersonRate\": \"300\"\r\n                    },\r\n                    \"maximum\": {}\r\n                },\r\n                \"classifications\": {},\r\n                \"rateSchedulePackages\": {\r\n                    \"packages\": [],\r\n                    \"packageGroups\": []\r\n                },\r\n                \"tierID\": \"1\",\r\n                \"start\": \"2021-03-11\",\r\n                \"end\": \"2021-03-31\"\r\n            }\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"
      ]
    }
  },
  "response": [
  ]
}