Chilkat Online Tools

TCL / ORACLE Hospitality OPERA Cloud REST API Workflows / Test an upsell Rule

Back to Collection Items

load ./chilkat.dll

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

set http [new_CkHttp]

# Use this online tool to generate code from sample JSON: Generate Code to Create JSON

# The following JSON is sent in the request body.

# {
#   "criteria": {
#     "hotelId": "{{HotelId}}",
#     "arrivalDate": "2021-04-06",
#     "nights": 1,
#     "adults": 1,
#     "children": 0,
#     "numberOfRooms": 1,
#     "roomType": "STDD",
#     "rateCode": "RACK"
#   }
# }

set json [new_CkJsonObject]

CkJsonObject_UpdateString $json "criteria.hotelId" "{{HotelId}}"
CkJsonObject_UpdateString $json "criteria.arrivalDate" "2021-04-06"
CkJsonObject_UpdateInt $json "criteria.nights" 1
CkJsonObject_UpdateInt $json "criteria.adults" 1
CkJsonObject_UpdateInt $json "criteria.children" 0
CkJsonObject_UpdateInt $json "criteria.numberOfRooms" 1
CkJsonObject_UpdateString $json "criteria.roomType" "STDD"
CkJsonObject_UpdateString $json "criteria.rateCode" "RACK"

CkHttp_SetRequestHeader $http "x-app-key" "{{AppKey}}"
CkHttp_SetRequestHeader $http "x-hotelid" "{{HotelId}}"
# Adds the "Authorization: Bearer <access_token>" header.
CkHttp_put_AuthToken $http "<access_token>"

set sbRequestBody [new_CkStringBuilder]

CkJsonObject_EmitSb $json $sbRequestBody

# resp is a CkHttpResponse
set resp [CkHttp_PTextSb $http "PUT" "https://domain.com/rsv/config/v0/hotels/{{HotelId}}/upsellRules/action/validate" $sbRequestBody "utf-8" "application/json" 0 0]
if {[CkHttp_get_LastMethodSuccess $http] == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkJsonObject $json
    delete_CkStringBuilder $sbRequestBody
    exit
}

puts [CkHttpResponse_get_StatusCode $resp]
puts [CkHttpResponse_bodyStr $resp]
delete_CkHttpResponse $resp


delete_CkHttp $http
delete_CkJsonObject $json
delete_CkStringBuilder $sbRequestBody

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-H "x-app-key: {{AppKey}}"
	-H "x-hotelid: {{HotelId}}"
	-d '{
    "criteria": {
        "hotelId": "{{HotelId}}",
        "arrivalDate": "2021-04-06",
        "nights": 1,
        "adults": 1,
        "children": 0,
        "numberOfRooms": 1,
        "roomType": "STDD",
        "rateCode": "RACK"
    }
}'
https://domain.com/rsv/config/v0/hotels/{{HotelId}}/upsellRules/action/validate

Postman Collection Item JSON

{
  "name": "Test an upsell Rule",
  "protocolProfileBehavior": {
    "disabledSystemHeaders": {}
  },
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{Token}}",
          "type": "string"
        }
      ]
    },
    "method": "PUT",
    "header": [
      {
        "key": "x-app-key",
        "type": "text",
        "value": "{{AppKey}}"
      },
      {
        "key": "x-hotelid",
        "type": "text",
        "value": "{{HotelId}}"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\r\n    \"criteria\": {\r\n        \"hotelId\": \"{{HotelId}}\",\r\n        \"arrivalDate\": \"2021-04-06\",\r\n        \"nights\": 1,\r\n        \"adults\": 1,\r\n        \"children\": 0,\r\n        \"numberOfRooms\": 1,\r\n        \"roomType\": \"STDD\",\r\n        \"rateCode\": \"RACK\"\r\n    }\r\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{HostName}}/rsv/config/v0/hotels/{{HotelId}}/upsellRules/action/validate",
      "host": [
        "{{HostName}}"
      ],
      "path": [
        "rsv",
        "config",
        "v0",
        "hotels",
        "{{HotelId}}",
        "upsellRules",
        "action",
        "validate"
      ]
    }
  },
  "response": [
  ]
}