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.
// {
// "ratePlanScheduleList": [
// {
// "roomTypeList": [
// "DLXK",
// "DLXQ"
// ],
// "sunday": true,
// "monday": true,
// "tuesday": true,
// "wednesday": true,
// "thursday": true,
// "friday": true,
// "saturday": true,
// "rateAmounts": {
// "onePersonRate": "200",
// "twoPersonRate": "200",
// "threePersonRate": "235",
// "fourPersonRate": "270",
// "oneChildRate": "150",
// "twoChildrenRate": "175",
// "threeChildrenRate": "200",
// "rateByAgeBuckets": [
// {
// "minimumAge": "1",
// "maximumAge": "17"
// }
// ],
// "minimumChildrenForFreeStay": "1",
// "overrideFloorAmount": true
// },
// "classifications": {},
// "rateSchedulePackages": {
// "packages": [
// ],
// "packageGroups": [
// ]
// },
// "tierID": "1",
// "start": "2020-11-01",
// "end": "2020-11-30"
// }
// ],
// "hotelId": "{{HotelId}}",
// "ratePlanCode": "{{RatePlanCode}}"
// }
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].roomTypeList[0]",L"DLXK");
CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].roomTypeList[1]",L"DLXQ");
CkJsonObjectW_UpdateBool(json,L"ratePlanScheduleList[0].sunday",TRUE);
CkJsonObjectW_UpdateBool(json,L"ratePlanScheduleList[0].monday",TRUE);
CkJsonObjectW_UpdateBool(json,L"ratePlanScheduleList[0].tuesday",TRUE);
CkJsonObjectW_UpdateBool(json,L"ratePlanScheduleList[0].wednesday",TRUE);
CkJsonObjectW_UpdateBool(json,L"ratePlanScheduleList[0].thursday",TRUE);
CkJsonObjectW_UpdateBool(json,L"ratePlanScheduleList[0].friday",TRUE);
CkJsonObjectW_UpdateBool(json,L"ratePlanScheduleList[0].saturday",TRUE);
CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].rateAmounts.onePersonRate",L"200");
CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].rateAmounts.twoPersonRate",L"200");
CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].rateAmounts.threePersonRate",L"235");
CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].rateAmounts.fourPersonRate",L"270");
CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].rateAmounts.oneChildRate",L"150");
CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].rateAmounts.twoChildrenRate",L"175");
CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].rateAmounts.threeChildrenRate",L"200");
CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].rateAmounts.rateByAgeBuckets[0].minimumAge",L"1");
CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].rateAmounts.rateByAgeBuckets[0].maximumAge",L"17");
CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].rateAmounts.minimumChildrenForFreeStay",L"1");
CkJsonObjectW_UpdateBool(json,L"ratePlanScheduleList[0].rateAmounts.overrideFloorAmount",TRUE);
CkJsonObjectW_UpdateNewObject(json,L"ratePlanScheduleList[0].classifications");
CkJsonObjectW_UpdateNewArray(json,L"ratePlanScheduleList[0].rateSchedulePackages.packages");
CkJsonObjectW_UpdateNewArray(json,L"ratePlanScheduleList[0].rateSchedulePackages.packageGroups");
CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].tierID",L"1");
CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].start",L"2020-11-01");
CkJsonObjectW_UpdateString(json,L"ratePlanScheduleList[0].end",L"2020-11-30");
CkJsonObjectW_UpdateString(json,L"hotelId",L"{{HotelId}}");
CkJsonObjectW_UpdateString(json,L"ratePlanCode",L"{{RatePlanCode}}");
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/{{RatePlanCode}}/schedules",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 '{
"ratePlanScheduleList": [
{
"roomTypeList": [
"DLXK",
"DLXQ"
],
"sunday": true,
"monday": true,
"tuesday": true,
"wednesday": true,
"thursday": true,
"friday": true,
"saturday": true,
"rateAmounts": {
"onePersonRate": "200",
"twoPersonRate": "200",
"threePersonRate": "235",
"fourPersonRate": "270",
"oneChildRate": "150",
"twoChildrenRate": "175",
"threeChildrenRate": "200",
"rateByAgeBuckets": [
{
"minimumAge": "1",
"maximumAge": "17"
}
],
"minimumChildrenForFreeStay": "1",
"overrideFloorAmount": true
},
"classifications": {},
"rateSchedulePackages": {
"packages": [],
"packageGroups": []
},
"tierID": "1",
"start": "2020-11-01",
"end": "2020-11-30"
}
],
"hotelId": "{{HotelId}}",
"ratePlanCode": "{{RatePlanCode}}"
}'
https://domain.com/rtp/v0/hotels/{{HotelId}}/ratePlans/{{RatePlanCode}}/schedules
Postman Collection Item JSON
{
"name": "Create Rate Plan Schedules",
"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 \"ratePlanScheduleList\": [\r\n {\r\n \"roomTypeList\": [\r\n \"DLXK\",\r\n \"DLXQ\"\r\n ],\r\n \"sunday\": true,\r\n \"monday\": true,\r\n \"tuesday\": true,\r\n \"wednesday\": true,\r\n \"thursday\": true,\r\n \"friday\": true,\r\n \"saturday\": true,\r\n \"rateAmounts\": {\r\n \"onePersonRate\": \"200\",\r\n \"twoPersonRate\": \"200\",\r\n \"threePersonRate\": \"235\",\r\n \"fourPersonRate\": \"270\",\r\n \"oneChildRate\": \"150\",\r\n \"twoChildrenRate\": \"175\",\r\n \"threeChildrenRate\": \"200\",\r\n \"rateByAgeBuckets\": [\r\n {\r\n \"minimumAge\": \"1\",\r\n \"maximumAge\": \"17\"\r\n }\r\n ],\r\n \"minimumChildrenForFreeStay\": \"1\",\r\n \"overrideFloorAmount\": true\r\n },\r\n \"classifications\": {},\r\n \"rateSchedulePackages\": {\r\n \"packages\": [],\r\n \"packageGroups\": []\r\n },\r\n \"tierID\": \"1\",\r\n \"start\": \"2020-11-01\",\r\n \"end\": \"2020-11-30\"\r\n }\r\n ],\r\n \"hotelId\": \"{{HotelId}}\",\r\n \"ratePlanCode\": \"{{RatePlanCode}}\"\r\n}"
},
"url": {
"raw": "{{HostName}}/rtp/v0/hotels/{{HotelId}}/ratePlans/{{RatePlanCode}}/schedules",
"host": [
"{{HostName}}"
],
"path": [
"rtp",
"v0",
"hotels",
"{{HotelId}}",
"ratePlans",
"{{RatePlanCode}}",
"schedules"
]
}
},
"response": [
]
}