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.
-- {
-- "ratePlan": {
-- "hotelId": "{{HotelId}}",
-- "code": "PACKADD"
-- },
-- "packages": {
-- "packages": [
-- {
-- "scheduleExceptions": [
-- ],
-- "quantity": "1",
-- "header": {
-- "primaryDetails": {
-- "beginSellDate": "2020-01-01",
-- "endSellDate": "2031-01-31"
-- },
-- "postingAttributes": {
-- "addToRate": false,
-- "printSeparateLine": false,
-- "sellSeparate": false,
-- "postNextDay": false,
-- "forecastNextDay": true,
-- "deliveryTimeRequired": false,
-- "formula": "",
-- "startTime": "2021-03-12",
-- "endTime": "2031-03-12",
-- "postingRhythm": {
-- "type": "EveryNight"
-- },
-- "priceCalculationRule": "PerPerson"
-- }
-- },
-- "schedules": [
-- {
-- "schedulePrices": [
-- {
-- "unitPrice": "25",
-- "bucket": "Bucket1"
-- }
-- ],
-- "start": "2020-01-01",
-- "end": "2031-01-31"
-- }
-- ],
-- "hotelId": "{{HotelId}}",
-- "code": "BKFSTINC",
-- "description": "Breakfast"
-- }
-- ]
-- }
-- }
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, 'ratePlan.hotelId', '{{HotelId}}'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlan.code', 'PACKADD'
EXEC sp_OAMethod @json, 'UpdateNewArray', @success OUT, 'packages.packages[0].scheduleExceptions'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'packages.packages[0].quantity', '1'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'packages.packages[0].header.primaryDetails.beginSellDate', '2020-01-01'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'packages.packages[0].header.primaryDetails.endSellDate', '2031-01-31'
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'packages.packages[0].header.postingAttributes.addToRate', 0
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'packages.packages[0].header.postingAttributes.printSeparateLine', 0
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'packages.packages[0].header.postingAttributes.sellSeparate', 0
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'packages.packages[0].header.postingAttributes.postNextDay', 0
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'packages.packages[0].header.postingAttributes.forecastNextDay', 1
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'packages.packages[0].header.postingAttributes.deliveryTimeRequired', 0
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'packages.packages[0].header.postingAttributes.formula', ''
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'packages.packages[0].header.postingAttributes.startTime', '2021-03-12'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'packages.packages[0].header.postingAttributes.endTime', '2031-03-12'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'packages.packages[0].header.postingAttributes.postingRhythm.type', 'EveryNight'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'packages.packages[0].header.postingAttributes.priceCalculationRule', 'PerPerson'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'packages.packages[0].schedules[0].schedulePrices[0].unitPrice', '25'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'packages.packages[0].schedules[0].schedulePrices[0].bucket', 'Bucket1'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'packages.packages[0].schedules[0].start', '2020-01-01'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'packages.packages[0].schedules[0].end', '2031-01-31'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'packages.packages[0].hotelId', '{{HotelId}}'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'packages.packages[0].code', 'BKFSTINC'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'packages.packages[0].description', 'Breakfast'
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}}/packages', '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 '{
"ratePlan": {
"hotelId": "{{HotelId}}",
"code": "PACKADD"
},
"packages": {
"packages": [
{
"scheduleExceptions": [],
"quantity": "1",
"header": {
"primaryDetails": {
"beginSellDate": "2020-01-01",
"endSellDate": "2031-01-31"
},
"postingAttributes": {
"addToRate": false,
"printSeparateLine": false,
"sellSeparate": false,
"postNextDay": false,
"forecastNextDay": true,
"deliveryTimeRequired": false,
"formula": "",
"startTime": "2021-03-12",
"endTime": "2031-03-12",
"postingRhythm": {
"type": "EveryNight"
},
"priceCalculationRule": "PerPerson"
}
},
"schedules": [
{
"schedulePrices": [
{
"unitPrice": "25",
"bucket": "Bucket1"
}
],
"start": "2020-01-01",
"end": "2031-01-31"
}
],
"hotelId": "{{HotelId}}",
"code": "BKFSTINC",
"description": "Breakfast"
}
]
}
}\''
https://domain.com/rtp/v0/hotels/{{HotelId}}/ratePlans/{{RatePlanCode}}/packages
Postman Collection Item JSON
{
"name": "Add packages to a Rate Plan",
"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 \"ratePlan\": {\r\n \"hotelId\": \"{{HotelId}}\",\r\n \"code\": \"PACKADD\"\r\n },\r\n \"packages\": {\r\n \"packages\": [\r\n {\r\n \"scheduleExceptions\": [],\r\n \"quantity\": \"1\",\r\n \"header\": {\r\n \"primaryDetails\": {\r\n \"beginSellDate\": \"2020-01-01\",\r\n \"endSellDate\": \"2031-01-31\"\r\n },\r\n \"postingAttributes\": {\r\n \"addToRate\": false,\r\n \"printSeparateLine\": false,\r\n \"sellSeparate\": false,\r\n \"postNextDay\": false,\r\n \"forecastNextDay\": true,\r\n \"deliveryTimeRequired\": false,\r\n \"formula\": \"\",\r\n \"startTime\": \"2021-03-12\",\r\n \"endTime\": \"2031-03-12\",\r\n \"postingRhythm\": {\r\n \"type\": \"EveryNight\"\r\n },\r\n \"priceCalculationRule\": \"PerPerson\"\r\n }\r\n },\r\n \"schedules\": [\r\n {\r\n \"schedulePrices\": [\r\n {\r\n \"unitPrice\": \"25\",\r\n \"bucket\": \"Bucket1\"\r\n }\r\n ],\r\n \"start\": \"2020-01-01\",\r\n \"end\": \"2031-01-31\"\r\n }\r\n ],\r\n \"hotelId\": \"{{HotelId}}\",\r\n \"code\": \"BKFSTINC\",\r\n \"description\": \"Breakfast\"\r\n }\r\n ]\r\n }\r\n}'"
},
"url": {
"raw": "{{HostName}}/rtp/v0/hotels/{{HotelId}}/ratePlans/{{RatePlanCode}}/packages",
"host": [
"{{HostName}}"
],
"path": [
"rtp",
"v0",
"hotels",
"{{HotelId}}",
"ratePlans",
"{{RatePlanCode}}",
"packages"
]
},
"description": "Use this operation to add a package (such as Breakfast, or box of chocolated) to a rate plan."
},
"response": [
]
}