Chilkat Online Tools

Objective-C / ORACLE Hospitality OPERA Cloud REST API Workflows / Create Rate Plan Schedules

Back to Collection Items

#import <CkoHttp.h>
#import <CkoJsonObject.h>
#import <CkoHttpResponse.h>

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

CkoHttp *http = [[CkoHttp alloc] init];
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.

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

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"ratePlanScheduleList[0].roomTypeList[0]" value: @"DLXK"];
[json UpdateString: @"ratePlanScheduleList[0].roomTypeList[1]" value: @"DLXQ"];
[json UpdateBool: @"ratePlanScheduleList[0].sunday" value: YES];
[json UpdateBool: @"ratePlanScheduleList[0].monday" value: YES];
[json UpdateBool: @"ratePlanScheduleList[0].tuesday" value: YES];
[json UpdateBool: @"ratePlanScheduleList[0].wednesday" value: YES];
[json UpdateBool: @"ratePlanScheduleList[0].thursday" value: YES];
[json UpdateBool: @"ratePlanScheduleList[0].friday" value: YES];
[json UpdateBool: @"ratePlanScheduleList[0].saturday" value: YES];
[json UpdateString: @"ratePlanScheduleList[0].rateAmounts.onePersonRate" value: @"200"];
[json UpdateString: @"ratePlanScheduleList[0].rateAmounts.twoPersonRate" value: @"200"];
[json UpdateString: @"ratePlanScheduleList[0].rateAmounts.threePersonRate" value: @"235"];
[json UpdateString: @"ratePlanScheduleList[0].rateAmounts.fourPersonRate" value: @"270"];
[json UpdateString: @"ratePlanScheduleList[0].rateAmounts.oneChildRate" value: @"150"];
[json UpdateString: @"ratePlanScheduleList[0].rateAmounts.twoChildrenRate" value: @"175"];
[json UpdateString: @"ratePlanScheduleList[0].rateAmounts.threeChildrenRate" value: @"200"];
[json UpdateString: @"ratePlanScheduleList[0].rateAmounts.rateByAgeBuckets[0].minimumAge" value: @"1"];
[json UpdateString: @"ratePlanScheduleList[0].rateAmounts.rateByAgeBuckets[0].maximumAge" value: @"17"];
[json UpdateString: @"ratePlanScheduleList[0].rateAmounts.minimumChildrenForFreeStay" value: @"1"];
[json UpdateBool: @"ratePlanScheduleList[0].rateAmounts.overrideFloorAmount" value: YES];
[json UpdateNewObject: @"ratePlanScheduleList[0].classifications"];
[json UpdateNewArray: @"ratePlanScheduleList[0].rateSchedulePackages.packages"];
[json UpdateNewArray: @"ratePlanScheduleList[0].rateSchedulePackages.packageGroups"];
[json UpdateString: @"ratePlanScheduleList[0].tierID" value: @"1"];
[json UpdateString: @"ratePlanScheduleList[0].start" value: @"2020-11-01"];
[json UpdateString: @"ratePlanScheduleList[0].end" value: @"2020-11-30"];
[json UpdateString: @"hotelId" value: @"{{HotelId}}"];
[json UpdateString: @"ratePlanCode" value: @"{{RatePlanCode}}"];

[http SetRequestHeader: @"Content-Type" value: @"application/json;charset=UTF-8"];
[http SetRequestHeader: @"x-hotelid" value: @"{{HotelId}}"];
// Adds the "Authorization: Bearer <access_token>" header.
http.AuthToken = @"<access_token>";
[http SetRequestHeader: @"Accept" value: @"application/json;charset=UTF-8"];
[http SetRequestHeader: @"x-app-key" value: @"{{AppKey}}"];

CkoHttpResponse *resp = [http PostJson3: @"https://domain.com/rtp/v0/hotels/{{HotelId}}/ratePlans/{{RatePlanCode}}/schedules" contentType: @"application/json;charset=UTF-8" json: json];
if (http.LastMethodSuccess == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

NSLog(@"%d",[resp.StatusCode intValue]);
NSLog(@"%@",resp.BodyStr);

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