Chilkat Online Tools

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

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

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

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleId.type', 'RateSetId'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleId.id', '199827'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.roomTypeList[0]', 'ECO'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.roomTypeList[1]', 'SUP'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.sunday', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.monday', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.tuesday', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.wednesday', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.thursday', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.friday', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.saturday', 1
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.onePersonRate', '305'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.twoPersonRate', '305'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.threePersonRate', '344'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.fourPersonRate', '340'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.fivePersonRate', '400'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.rateByAgeBuckets[0].minimumAge', '0'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.rateByAgeBuckets[0].maximumAge', '3'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.rateByAgeBuckets[1].minimumAge', '4'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.rateByAgeBuckets[1].maximumAge', '10'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.rateByAgeBuckets[2].minimumAge', '11'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.rateByAgeBuckets[2].maximumAge', '17'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmounts.overrideFloorAmount', 1
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmountBoundaries.minimum.onePersonRate', '300'
    EXEC sp_OAMethod @json, 'UpdateNewObject', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.rateAmountBoundaries.maximum'
    EXEC sp_OAMethod @json, 'UpdateNewObject', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.classifications'
    EXEC sp_OAMethod @json, 'UpdateNewArray', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.rateSchedulePackages.packages'
    EXEC sp_OAMethod @json, 'UpdateNewArray', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.rateSchedulePackages.packageGroups'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.tierID', '1'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.start', '2021-03-11'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].ratePlanScheduleDetail.end', '2021-03-31'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'hotelId', '{{HotelId}}'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanCode', '{{RatePlanCode}}'

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

    DECLARE @sbRequestBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbRequestBody OUT

    EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @sbRequestBody

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'PUT', 'https://domain.com/rtp/v0/hotels/{{HotelId}}/ratePlans/{{RatePlanCode}}/schedules', @sbRequestBody, 'utf-8', 'application/json;charset=UTF-8', 0, 0
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbRequestBody
        RETURN
      END

    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT @iTmp0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    PRINT @sTmp0
    EXEC @hr = sp_OADestroy @resp


    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @sbRequestBody


END
GO

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