Chilkat Online Tools

SQL Server / ORACLE Hospitality OPERA Cloud REST API Workflows / Create a new Rate Plans

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": {
    --     "primaryDetails": {
    --       "description": {
    --         "defaultText": "Rate Code Description Goes Here"
    --       },
    --       "startSellDate": "2021-01-03",
    --       "endSellDate": "2021-12-31",
    --       "privilegedRate": false,
    --       "privilegedRateRestriction": false,
    --       "lockStatus": "Unlocked"
    --     },
    --     "classifications": {
    --       "rateCategory": "HOTEL",
    --       "marketCode": "LEISURE"
    --     },
    --     "transactionDetails": {
    --       "folioText": {
    --         "defaultText": "Accommodation"
    --       },
    --       "transactionCode": "1000",
    --       "currencyCode": "USD",
    --       "rateIncludesTax": true
    --     },
    --     "rateCommission": {},
    --     "roomTypeList": [
    --       {
    --         "code": "ECO"
    --       },
    --       {
    --         "code": "SGL"
    --       },
    --       {
    --         "code": "DBL"
    --       },
    --       {
    --         "code": "SUP"
    --       },
    --       {
    --         "code": "JSUI"
    --       },
    --       {
    --         "code": "SUI"
    --       }
    --     ],
    --     "ratePackages": {
    --       "packages": [
    --       ],
    --       "packageGroups": [
    --       ]
    --     },
    --     "controls": {
    --       "sell": {
    --         "minimumStayThrough": "1",
    --         "minimumLengthOfStay": "1"
    --       },
    --       "yield": {
    --         "yieldable": "NonYieldable"
    --       }
    --     },
    --     "distribution": {
    --       "restrictionUpdate": false,
    --       "rateUpdate": false,
    --       "myFidelioUploadAllowed": false,
    --       "channelRateMappingExists": false,
    --       "channelAllowed": false
    --     },
    --     "ratePlanBasedOnRates": [
    --       {
    --         "basedOnRatePlanType": "None"
    --       }
    --     ],
    --     "approvalNotes": [
    --       {}
    --     ],
    --     "mobileCheckinAllowed": false,
    --     "mobileCheckoutAllowed": false,
    --     "hotelId": "{{HotelId}}",
    --     "ratePlanCode": "RACK123",
    --     "supressRate": false,
    --     "printRate": true,
    --     "discountAllowed": false,
    --     "redemption": false,
    --     "bARRate": false,
    --     "daily": false,
    --     "tiered": false,
    --     "dayUse": false,
    --     "dayType": false,
    --     "complimentary": false,
    --     "houseUse": false,
    --     "negotiated": false,
    --     "ownerRate": false,
    --     "membershipEligible": true,
    --     "advancedDailyBase": false,
    --     "advancedDailyRate": false
    --   }
    -- }

    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.primaryDetails.description.defaultText', 'Rate Code Description Goes Here'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlan.primaryDetails.startSellDate', '2021-01-03'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlan.primaryDetails.endSellDate', '2021-12-31'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.primaryDetails.privilegedRate', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.primaryDetails.privilegedRateRestriction', 0
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlan.primaryDetails.lockStatus', 'Unlocked'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlan.classifications.rateCategory', 'HOTEL'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlan.classifications.marketCode', 'LEISURE'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlan.transactionDetails.folioText.defaultText', 'Accommodation'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlan.transactionDetails.transactionCode', '1000'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlan.transactionDetails.currencyCode', 'USD'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.transactionDetails.rateIncludesTax', 1
    EXEC sp_OAMethod @json, 'UpdateNewObject', @success OUT, 'ratePlan.rateCommission'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlan.roomTypeList[0].code', 'ECO'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlan.roomTypeList[1].code', 'SGL'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlan.roomTypeList[2].code', 'DBL'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlan.roomTypeList[3].code', 'SUP'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlan.roomTypeList[4].code', 'JSUI'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlan.roomTypeList[5].code', 'SUI'
    EXEC sp_OAMethod @json, 'UpdateNewArray', @success OUT, 'ratePlan.ratePackages.packages'
    EXEC sp_OAMethod @json, 'UpdateNewArray', @success OUT, 'ratePlan.ratePackages.packageGroups'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlan.controls.sell.minimumStayThrough', '1'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlan.controls.sell.minimumLengthOfStay', '1'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlan.controls.yield.yieldable', 'NonYieldable'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.distribution.restrictionUpdate', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.distribution.rateUpdate', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.distribution.myFidelioUploadAllowed', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.distribution.channelRateMappingExists', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.distribution.channelAllowed', 0
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlan.ratePlanBasedOnRates[0].basedOnRatePlanType', 'None'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.mobileCheckinAllowed', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.mobileCheckoutAllowed', 0
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlan.hotelId', '{{HotelId}}'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'ratePlan.ratePlanCode', 'RACK123'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.supressRate', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.printRate', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.discountAllowed', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.redemption', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.bARRate', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.daily', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.tiered', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.dayUse', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.dayType', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.complimentary', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.houseUse', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.negotiated', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.ownerRate', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.membershipEligible', 1
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.advancedDailyBase', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'ratePlan.advancedDailyRate', 0

    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', '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": {
        "primaryDetails": {
            "description": {
                "defaultText": "Rate Code Description Goes Here"
            },
            "startSellDate": "2021-01-03",
            "endSellDate": "2021-12-31",
            "privilegedRate": false,
            "privilegedRateRestriction": false,
            "lockStatus": "Unlocked"
        },
        "classifications": {
            "rateCategory": "HOTEL",
            "marketCode": "LEISURE"
        },
        "transactionDetails": {
            "folioText": {
                "defaultText": "Accommodation"
            },
            "transactionCode": "1000",
            "currencyCode": "USD",
            "rateIncludesTax": true
        },
        "rateCommission": {},
        "roomTypeList": [
            {
                "code": "ECO"
            },
            {
                "code": "SGL"
            },
            {
                "code": "DBL"
            },
            {
                "code": "SUP"
            },
            {
                "code": "JSUI"
            },
            {
                "code": "SUI"
            }
        ],
        "ratePackages": {
            "packages": [],
            "packageGroups": []
        },
        "controls": {
            "sell": {
                "minimumStayThrough": "1",
                "minimumLengthOfStay": "1"
            },
            "yield": {
                "yieldable": "NonYieldable"
            }
        },
        "distribution": {
            "restrictionUpdate": false,
            "rateUpdate": false,
            "myFidelioUploadAllowed": false,
            "channelRateMappingExists": false,
            "channelAllowed": false
        },
        "ratePlanBasedOnRates": [
            {
                "basedOnRatePlanType": "None"
            }
        ],
        "approvalNotes": [
            {}
        ],
        "mobileCheckinAllowed": false,
        "mobileCheckoutAllowed": false,
        "hotelId": "{{HotelId}}",
        "ratePlanCode": "RACK123",
        "supressRate": false,
        "printRate": true,
        "discountAllowed": false,
        "redemption": false,
        "bARRate": false,
        "daily": false,
        "tiered": false,
        "dayUse": false,
        "dayType": false,
        "complimentary": false,
        "houseUse": false,
        "negotiated": false,
        "ownerRate": false,
        "membershipEligible": true,
        "advancedDailyBase": false,
        "advancedDailyRate": false
    }
}'
https://domain.com/rtp/v0/hotels/{{HotelId}}/ratePlans

Postman Collection Item JSON

{
  "name": "Create a new Rate Plans",
  "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        \"primaryDetails\": {\r\n            \"description\": {\r\n                \"defaultText\": \"Rate Code Description Goes Here\"\r\n            },\r\n            \"startSellDate\": \"2021-01-03\",\r\n            \"endSellDate\": \"2021-12-31\",\r\n            \"privilegedRate\": false,\r\n            \"privilegedRateRestriction\": false,\r\n            \"lockStatus\": \"Unlocked\"\r\n        },\r\n        \"classifications\": {\r\n            \"rateCategory\": \"HOTEL\",\r\n            \"marketCode\": \"LEISURE\"\r\n        },\r\n        \"transactionDetails\": {\r\n            \"folioText\": {\r\n                \"defaultText\": \"Accommodation\"\r\n            },\r\n            \"transactionCode\": \"1000\",\r\n            \"currencyCode\": \"USD\",\r\n            \"rateIncludesTax\": true\r\n        },\r\n        \"rateCommission\": {},\r\n        \"roomTypeList\": [\r\n            {\r\n                \"code\": \"ECO\"\r\n            },\r\n            {\r\n                \"code\": \"SGL\"\r\n            },\r\n            {\r\n                \"code\": \"DBL\"\r\n            },\r\n            {\r\n                \"code\": \"SUP\"\r\n            },\r\n            {\r\n                \"code\": \"JSUI\"\r\n            },\r\n            {\r\n                \"code\": \"SUI\"\r\n            }\r\n        ],\r\n        \"ratePackages\": {\r\n            \"packages\": [],\r\n            \"packageGroups\": []\r\n        },\r\n        \"controls\": {\r\n            \"sell\": {\r\n                \"minimumStayThrough\": \"1\",\r\n                \"minimumLengthOfStay\": \"1\"\r\n            },\r\n            \"yield\": {\r\n                \"yieldable\": \"NonYieldable\"\r\n            }\r\n        },\r\n        \"distribution\": {\r\n            \"restrictionUpdate\": false,\r\n            \"rateUpdate\": false,\r\n            \"myFidelioUploadAllowed\": false,\r\n            \"channelRateMappingExists\": false,\r\n            \"channelAllowed\": false\r\n        },\r\n        \"ratePlanBasedOnRates\": [\r\n            {\r\n                \"basedOnRatePlanType\": \"None\"\r\n            }\r\n        ],\r\n        \"approvalNotes\": [\r\n            {}\r\n        ],\r\n        \"mobileCheckinAllowed\": false,\r\n        \"mobileCheckoutAllowed\": false,\r\n        \"hotelId\": \"{{HotelId}}\",\r\n        \"ratePlanCode\": \"RACK123\",\r\n        \"supressRate\": false,\r\n        \"printRate\": true,\r\n        \"discountAllowed\": false,\r\n        \"redemption\": false,\r\n        \"bARRate\": false,\r\n        \"daily\": false,\r\n        \"tiered\": false,\r\n        \"dayUse\": false,\r\n        \"dayType\": false,\r\n        \"complimentary\": false,\r\n        \"houseUse\": false,\r\n        \"negotiated\": false,\r\n        \"ownerRate\": false,\r\n        \"membershipEligible\": true,\r\n        \"advancedDailyBase\": false,\r\n        \"advancedDailyRate\": false\r\n    }\r\n}"
    },
    "url": {
      "raw": "{{HostName}}/rtp/v0/hotels/{{HotelId}}/ratePlans",
      "host": [
        "{{HostName}}"
      ],
      "path": [
        "rtp",
        "v0",
        "hotels",
        "{{HotelId}}",
        "ratePlans"
      ]
    }
  },
  "response": [
  ]
}