Chilkat Online Tools

unicodeCpp / ORACLE Hospitality OPERA Cloud REST API Workflows / Test an upsell rule

Back to Collection Items

#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>
#include <CkHttpResponseW.h>

void ChilkatSample(void)
    {
    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttpW http;
    bool success;

    // 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": "ECO",
    //     "rateCode": "BAR"
    //   }
    // }

    CkJsonObjectW json;
    json.UpdateString(L"criteria.hotelId",L"{{HotelId}}");
    json.UpdateString(L"criteria.arrivalDate",L"2021-04-06");
    json.UpdateInt(L"criteria.nights",1);
    json.UpdateInt(L"criteria.adults",1);
    json.UpdateInt(L"criteria.children",0);
    json.UpdateInt(L"criteria.numberOfRooms",1);
    json.UpdateString(L"criteria.roomType",L"ECO");
    json.UpdateString(L"criteria.rateCode",L"BAR");

    http.SetRequestHeader(L"x-app-key",L"{{AppKey}}");
    http.SetRequestHeader(L"x-hotelid",L"{{HotelId}}");
    // Adds the "Authorization: Bearer <access_token>" header.
    http.put_AuthToken(L"<access_token>");

    CkStringBuilderW sbRequestBody;
    json.EmitSb(sbRequestBody);

    CkHttpResponseW *resp = http.PTextSb(L"PUT",L"https://domain.com/rsv/config/v0/hotels/{{HotelId}}/upsellRules/action/validate",sbRequestBody,L"utf-8",L"application/json",false,false);
    if (http.get_LastMethodSuccess() == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    wprintf(L"%d\n",resp->get_StatusCode());
    wprintf(L"%s\n",resp->bodyStr());
    delete resp;
    }

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": "ECO",
        "rateCode": "BAR"
    }
}'
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\": \"ECO\",\r\n        \"rateCode\": \"BAR\"\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": [
  ]
}