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
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.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": [
-- {
-- "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}}"
-- }
DECLARE @json int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].roomTypeList[0]', 'DLXK'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].roomTypeList[1]', 'DLXQ'
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlanScheduleList[0].sunday', 1
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlanScheduleList[0].monday', 1
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlanScheduleList[0].tuesday', 1
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlanScheduleList[0].wednesday', 1
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlanScheduleList[0].thursday', 1
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlanScheduleList[0].friday', 1
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlanScheduleList[0].saturday', 1
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].rateAmounts.onePersonRate', '220'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].rateAmounts.twoPersonRate', '250'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].rateAmounts.threePersonRate', '280'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].rateAmounts.fourPersonRate', '300'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].rateAmounts.rateByAgeBuckets[0].minimumAge', '1'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].rateAmounts.rateByAgeBuckets[0].maximumAge', '17'
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlanScheduleList[0].rateAmounts.overrideFloorAmount', 1
EXEC sp_OAMethod @json, 'UpdateNewObject', @success OUT, 'ratePlanScheduleList[0].classifications'
EXEC sp_OAMethod @json, 'UpdateNewObject', @success OUT, 'ratePlanScheduleList[0].rateSchedulePackages.packages[0].header'
EXEC sp_OAMethod @json, 'UpdateNewArray', @success OUT, 'ratePlanScheduleList[0].rateSchedulePackages.packages[0].schedules'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].rateSchedulePackages.packages[0].code', 'PKG2'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].rateSchedulePackages.packages[0].description', 'Chocolates Package'
EXEC sp_OAMethod @json, 'UpdateNewArray', @success OUT, 'ratePlanScheduleList[0].rateSchedulePackages.packageGroups'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].tierID', '1'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].start', '2020-12-01'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlanScheduleList[0].end', '2020-12-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 @resp int
EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://domain.com/rtp/v0/hotels/{{HotelId}}/ratePlans/{{RatePlanCode}}/schedules', 'application/json;charset=UTF-8', @json
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
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
END
GO
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": [
]
}