Chilkat Online Tools

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

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkHttpResponseW resp;

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

    http = CkHttpW_Create();

    // 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
    //   }
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"ratePlan.primaryDetails.description.defaultText",L"Rate Code Description Goes Here");
    CkJsonObjectW_UpdateString(json,L"ratePlan.primaryDetails.startSellDate",L"2021-01-03");
    CkJsonObjectW_UpdateString(json,L"ratePlan.primaryDetails.endSellDate",L"2021-12-31");
    CkJsonObjectW_UpdateBool(json,L"ratePlan.primaryDetails.privilegedRate",FALSE);
    CkJsonObjectW_UpdateBool(json,L"ratePlan.primaryDetails.privilegedRateRestriction",FALSE);
    CkJsonObjectW_UpdateString(json,L"ratePlan.primaryDetails.lockStatus",L"Unlocked");
    CkJsonObjectW_UpdateString(json,L"ratePlan.classifications.rateCategory",L"HOTEL");
    CkJsonObjectW_UpdateString(json,L"ratePlan.classifications.marketCode",L"LEISURE");
    CkJsonObjectW_UpdateString(json,L"ratePlan.transactionDetails.folioText.defaultText",L"Accommodation");
    CkJsonObjectW_UpdateString(json,L"ratePlan.transactionDetails.transactionCode",L"1000");
    CkJsonObjectW_UpdateString(json,L"ratePlan.transactionDetails.currencyCode",L"USD");
    CkJsonObjectW_UpdateBool(json,L"ratePlan.transactionDetails.rateIncludesTax",TRUE);
    CkJsonObjectW_UpdateNewObject(json,L"ratePlan.rateCommission");
    CkJsonObjectW_UpdateString(json,L"ratePlan.roomTypeList[0].code",L"ECO");
    CkJsonObjectW_UpdateString(json,L"ratePlan.roomTypeList[1].code",L"SGL");
    CkJsonObjectW_UpdateString(json,L"ratePlan.roomTypeList[2].code",L"DBL");
    CkJsonObjectW_UpdateString(json,L"ratePlan.roomTypeList[3].code",L"SUP");
    CkJsonObjectW_UpdateString(json,L"ratePlan.roomTypeList[4].code",L"JSUI");
    CkJsonObjectW_UpdateString(json,L"ratePlan.roomTypeList[5].code",L"SUI");
    CkJsonObjectW_UpdateNewArray(json,L"ratePlan.ratePackages.packages");
    CkJsonObjectW_UpdateNewArray(json,L"ratePlan.ratePackages.packageGroups");
    CkJsonObjectW_UpdateString(json,L"ratePlan.controls.sell.minimumStayThrough",L"1");
    CkJsonObjectW_UpdateString(json,L"ratePlan.controls.sell.minimumLengthOfStay",L"1");
    CkJsonObjectW_UpdateString(json,L"ratePlan.controls.yield.yieldable",L"NonYieldable");
    CkJsonObjectW_UpdateBool(json,L"ratePlan.distribution.restrictionUpdate",FALSE);
    CkJsonObjectW_UpdateBool(json,L"ratePlan.distribution.rateUpdate",FALSE);
    CkJsonObjectW_UpdateBool(json,L"ratePlan.distribution.myFidelioUploadAllowed",FALSE);
    CkJsonObjectW_UpdateBool(json,L"ratePlan.distribution.channelRateMappingExists",FALSE);
    CkJsonObjectW_UpdateBool(json,L"ratePlan.distribution.channelAllowed",FALSE);
    CkJsonObjectW_UpdateString(json,L"ratePlan.ratePlanBasedOnRates[0].basedOnRatePlanType",L"None");
    CkJsonObjectW_UpdateBool(json,L"ratePlan.mobileCheckinAllowed",FALSE);
    CkJsonObjectW_UpdateBool(json,L"ratePlan.mobileCheckoutAllowed",FALSE);
    CkJsonObjectW_UpdateString(json,L"ratePlan.hotelId",L"{{HotelId}}");
    CkJsonObjectW_UpdateString(json,L"ratePlan.ratePlanCode",L"RACK123");
    CkJsonObjectW_UpdateBool(json,L"ratePlan.supressRate",FALSE);
    CkJsonObjectW_UpdateBool(json,L"ratePlan.printRate",TRUE);
    CkJsonObjectW_UpdateBool(json,L"ratePlan.discountAllowed",FALSE);
    CkJsonObjectW_UpdateBool(json,L"ratePlan.redemption",FALSE);
    CkJsonObjectW_UpdateBool(json,L"ratePlan.bARRate",FALSE);
    CkJsonObjectW_UpdateBool(json,L"ratePlan.daily",FALSE);
    CkJsonObjectW_UpdateBool(json,L"ratePlan.tiered",FALSE);
    CkJsonObjectW_UpdateBool(json,L"ratePlan.dayUse",FALSE);
    CkJsonObjectW_UpdateBool(json,L"ratePlan.dayType",FALSE);
    CkJsonObjectW_UpdateBool(json,L"ratePlan.complimentary",FALSE);
    CkJsonObjectW_UpdateBool(json,L"ratePlan.houseUse",FALSE);
    CkJsonObjectW_UpdateBool(json,L"ratePlan.negotiated",FALSE);
    CkJsonObjectW_UpdateBool(json,L"ratePlan.ownerRate",FALSE);
    CkJsonObjectW_UpdateBool(json,L"ratePlan.membershipEligible",TRUE);
    CkJsonObjectW_UpdateBool(json,L"ratePlan.advancedDailyBase",FALSE);
    CkJsonObjectW_UpdateBool(json,L"ratePlan.advancedDailyRate",FALSE);

    CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json;charset=UTF-8");
    CkHttpW_SetRequestHeader(http,L"x-hotelid",L"{{HotelId}}");
    // Adds the "Authorization: Bearer <access_token>" header.
    CkHttpW_putAuthToken(http,L"<access_token>");
    CkHttpW_SetRequestHeader(http,L"Accept",L"application/json;charset=UTF-8");
    CkHttpW_SetRequestHeader(http,L"x-app-key",L"{{AppKey}}");

    resp = CkHttpW_PostJson3(http,L"https://domain.com/rtp/v0/hotels/{{HotelId}}/ratePlans",L"application/json;charset=UTF-8",json);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);

    }

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": [
  ]
}