Chilkat Online Tools

PowerBuilder / ORACLE Hospitality OPERA Cloud REST API Workflows / Create Rate Plan Schedules

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_Resp

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

loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// 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": "200",
//         "twoPersonRate": "200",
//         "threePersonRate": "235",
//         "fourPersonRate": "270",
//         "oneChildRate": "150",
//         "twoChildrenRate": "175",
//         "threeChildrenRate": "200",
//         "rateByAgeBuckets": [
//           {
//             "minimumAge": "1",
//             "maximumAge": "17"
//           }
//         ],
//         "minimumChildrenForFreeStay": "1",
//         "overrideFloorAmount": true
//       },
//       "classifications": {},
//       "rateSchedulePackages": {
//         "packages": [
//         ],
//         "packageGroups": [
//         ]
//       },
//       "tierID": "1",
//       "start": "2020-11-01",
//       "end": "2020-11-30"
//     }
//   ],
//   "hotelId": "{{HotelId}}",
//   "ratePlanCode": "{{RatePlanCode}}"
// }

loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.UpdateString("ratePlanScheduleList[0].roomTypeList[0]","DLXK")
loo_Json.UpdateString("ratePlanScheduleList[0].roomTypeList[1]","DLXQ")
loo_Json.UpdateBool("ratePlanScheduleList[0].sunday",1)
loo_Json.UpdateBool("ratePlanScheduleList[0].monday",1)
loo_Json.UpdateBool("ratePlanScheduleList[0].tuesday",1)
loo_Json.UpdateBool("ratePlanScheduleList[0].wednesday",1)
loo_Json.UpdateBool("ratePlanScheduleList[0].thursday",1)
loo_Json.UpdateBool("ratePlanScheduleList[0].friday",1)
loo_Json.UpdateBool("ratePlanScheduleList[0].saturday",1)
loo_Json.UpdateString("ratePlanScheduleList[0].rateAmounts.onePersonRate","200")
loo_Json.UpdateString("ratePlanScheduleList[0].rateAmounts.twoPersonRate","200")
loo_Json.UpdateString("ratePlanScheduleList[0].rateAmounts.threePersonRate","235")
loo_Json.UpdateString("ratePlanScheduleList[0].rateAmounts.fourPersonRate","270")
loo_Json.UpdateString("ratePlanScheduleList[0].rateAmounts.oneChildRate","150")
loo_Json.UpdateString("ratePlanScheduleList[0].rateAmounts.twoChildrenRate","175")
loo_Json.UpdateString("ratePlanScheduleList[0].rateAmounts.threeChildrenRate","200")
loo_Json.UpdateString("ratePlanScheduleList[0].rateAmounts.rateByAgeBuckets[0].minimumAge","1")
loo_Json.UpdateString("ratePlanScheduleList[0].rateAmounts.rateByAgeBuckets[0].maximumAge","17")
loo_Json.UpdateString("ratePlanScheduleList[0].rateAmounts.minimumChildrenForFreeStay","1")
loo_Json.UpdateBool("ratePlanScheduleList[0].rateAmounts.overrideFloorAmount",1)
loo_Json.UpdateNewObject("ratePlanScheduleList[0].classifications")
loo_Json.UpdateNewArray("ratePlanScheduleList[0].rateSchedulePackages.packages")
loo_Json.UpdateNewArray("ratePlanScheduleList[0].rateSchedulePackages.packageGroups")
loo_Json.UpdateString("ratePlanScheduleList[0].tierID","1")
loo_Json.UpdateString("ratePlanScheduleList[0].start","2020-11-01")
loo_Json.UpdateString("ratePlanScheduleList[0].end","2020-11-30")
loo_Json.UpdateString("hotelId","{{HotelId}}")
loo_Json.UpdateString("ratePlanCode","{{RatePlanCode}}")

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

loo_Resp = loo_Http.PostJson3("https://domain.com/rtp/v0/hotels/{{HotelId}}/ratePlans/{{RatePlanCode}}/schedules","application/json;charset=UTF-8",loo_Json)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Json
    return
end if

Write-Debug string(loo_Resp.StatusCode)
Write-Debug loo_Resp.BodyStr
destroy loo_Resp


destroy loo_Http
destroy loo_Json

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": "200",
                "twoPersonRate": "200",
                "threePersonRate": "235",
                "fourPersonRate": "270",
                "oneChildRate": "150",
                "twoChildrenRate": "175",
                "threeChildrenRate": "200",
                "rateByAgeBuckets": [
                    {
                        "minimumAge": "1",
                        "maximumAge": "17"
                    }
                ],
                "minimumChildrenForFreeStay": "1",
                "overrideFloorAmount": true
            },
            "classifications": {},
            "rateSchedulePackages": {
                "packages": [],
                "packageGroups": []
            },
            "tierID": "1",
            "start": "2020-11-01",
            "end": "2020-11-30"
        }
    ],
    "hotelId": "{{HotelId}}",
    "ratePlanCode": "{{RatePlanCode}}"
}'
https://domain.com/rtp/v0/hotels/{{HotelId}}/ratePlans/{{RatePlanCode}}/schedules

Postman Collection Item JSON

{
  "name": "Create Rate Plan Schedules",
  "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\": \"200\",\r\n                \"twoPersonRate\": \"200\",\r\n                \"threePersonRate\": \"235\",\r\n                \"fourPersonRate\": \"270\",\r\n                \"oneChildRate\": \"150\",\r\n                \"twoChildrenRate\": \"175\",\r\n                \"threeChildrenRate\": \"200\",\r\n                \"rateByAgeBuckets\": [\r\n                    {\r\n                        \"minimumAge\": \"1\",\r\n                        \"maximumAge\": \"17\"\r\n                    }\r\n                ],\r\n                \"minimumChildrenForFreeStay\": \"1\",\r\n                \"overrideFloorAmount\": true\r\n            },\r\n            \"classifications\": {},\r\n            \"rateSchedulePackages\": {\r\n                \"packages\": [],\r\n                \"packageGroups\": []\r\n            },\r\n            \"tierID\": \"1\",\r\n            \"start\": \"2020-11-01\",\r\n            \"end\": \"2020-11-30\"\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": [
  ]
}