Chilkat Online Tools

Objective-C / ORACLE Hospitality OPERA Cloud REST API Workflows / Add packages to a Rate Plan

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.

// {
//   "ratePlan": {
//     "hotelId": "{{HotelId}}",
//     "code": "PACKADD"
//   },
//   "packages": {
//     "packages": [
//       {
//         "scheduleExceptions": [
//         ],
//         "quantity": "1",
//         "header": {
//           "primaryDetails": {
//             "beginSellDate": "2020-01-01",
//             "endSellDate": "2031-01-31"
//           },
//           "postingAttributes": {
//             "addToRate": false,
//             "printSeparateLine": false,
//             "sellSeparate": false,
//             "postNextDay": false,
//             "forecastNextDay": true,
//             "deliveryTimeRequired": false,
//             "formula": "",
//             "startTime": "2021-03-12",
//             "endTime": "2031-03-12",
//             "postingRhythm": {
//               "type": "EveryNight"
//             },
//             "priceCalculationRule": "PerPerson"
//           }
//         },
//         "schedules": [
//           {
//             "schedulePrices": [
//               {
//                 "unitPrice": "25",
//                 "bucket": "Bucket1"
//               }
//             ],
//             "start": "2020-01-01",
//             "end": "2031-01-31"
//           }
//         ],
//         "hotelId": "{{HotelId}}",
//         "code": "BKFSTINC",
//         "description": "Breakfast"
//       }
//     ]
//   }
// }

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"ratePlan.hotelId" value: @"{{HotelId}}"];
[json UpdateString: @"ratePlan.code" value: @"PACKADD"];
[json UpdateNewArray: @"packages.packages[0].scheduleExceptions"];
[json UpdateString: @"packages.packages[0].quantity" value: @"1"];
[json UpdateString: @"packages.packages[0].header.primaryDetails.beginSellDate" value: @"2020-01-01"];
[json UpdateString: @"packages.packages[0].header.primaryDetails.endSellDate" value: @"2031-01-31"];
[json UpdateBool: @"packages.packages[0].header.postingAttributes.addToRate" value: NO];
[json UpdateBool: @"packages.packages[0].header.postingAttributes.printSeparateLine" value: NO];
[json UpdateBool: @"packages.packages[0].header.postingAttributes.sellSeparate" value: NO];
[json UpdateBool: @"packages.packages[0].header.postingAttributes.postNextDay" value: NO];
[json UpdateBool: @"packages.packages[0].header.postingAttributes.forecastNextDay" value: YES];
[json UpdateBool: @"packages.packages[0].header.postingAttributes.deliveryTimeRequired" value: NO];
[json UpdateString: @"packages.packages[0].header.postingAttributes.formula" value: @""];
[json UpdateString: @"packages.packages[0].header.postingAttributes.startTime" value: @"2021-03-12"];
[json UpdateString: @"packages.packages[0].header.postingAttributes.endTime" value: @"2031-03-12"];
[json UpdateString: @"packages.packages[0].header.postingAttributes.postingRhythm.type" value: @"EveryNight"];
[json UpdateString: @"packages.packages[0].header.postingAttributes.priceCalculationRule" value: @"PerPerson"];
[json UpdateString: @"packages.packages[0].schedules[0].schedulePrices[0].unitPrice" value: @"25"];
[json UpdateString: @"packages.packages[0].schedules[0].schedulePrices[0].bucket" value: @"Bucket1"];
[json UpdateString: @"packages.packages[0].schedules[0].start" value: @"2020-01-01"];
[json UpdateString: @"packages.packages[0].schedules[0].end" value: @"2031-01-31"];
[json UpdateString: @"packages.packages[0].hotelId" value: @"{{HotelId}}"];
[json UpdateString: @"packages.packages[0].code" value: @"BKFSTINC"];
[json UpdateString: @"packages.packages[0].description" value: @"Breakfast"];

[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}}/packages" 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 '{
    "ratePlan": {
        "hotelId": "{{HotelId}}",
        "code": "PACKADD"
    },
    "packages": {
        "packages": [
            {
                "scheduleExceptions": [],
                "quantity": "1",
                "header": {
                    "primaryDetails": {
                        "beginSellDate": "2020-01-01",
                        "endSellDate": "2031-01-31"
                    },
                    "postingAttributes": {
                        "addToRate": false,
                        "printSeparateLine": false,
                        "sellSeparate": false,
                        "postNextDay": false,
                        "forecastNextDay": true,
                        "deliveryTimeRequired": false,
                        "formula": "",
                        "startTime": "2021-03-12",
                        "endTime": "2031-03-12",
                        "postingRhythm": {
                            "type": "EveryNight"
                        },
                        "priceCalculationRule": "PerPerson"
                    }
                },
                "schedules": [
                    {
                        "schedulePrices": [
                            {
                                "unitPrice": "25",
                                "bucket": "Bucket1"
                            }
                        ],
                        "start": "2020-01-01",
                        "end": "2031-01-31"
                    }
                ],
                "hotelId": "{{HotelId}}",
                "code": "BKFSTINC",
                "description": "Breakfast"
            }
        ]
    }
}\''
https://domain.com/rtp/v0/hotels/{{HotelId}}/ratePlans/{{RatePlanCode}}/packages

Postman Collection Item JSON

{
  "name": "Add packages to a Rate Plan",
  "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        \"hotelId\": \"{{HotelId}}\",\r\n        \"code\": \"PACKADD\"\r\n    },\r\n    \"packages\": {\r\n        \"packages\": [\r\n            {\r\n                \"scheduleExceptions\": [],\r\n                \"quantity\": \"1\",\r\n                \"header\": {\r\n                    \"primaryDetails\": {\r\n                        \"beginSellDate\": \"2020-01-01\",\r\n                        \"endSellDate\": \"2031-01-31\"\r\n                    },\r\n                    \"postingAttributes\": {\r\n                        \"addToRate\": false,\r\n                        \"printSeparateLine\": false,\r\n                        \"sellSeparate\": false,\r\n                        \"postNextDay\": false,\r\n                        \"forecastNextDay\": true,\r\n                        \"deliveryTimeRequired\": false,\r\n                        \"formula\": \"\",\r\n                        \"startTime\": \"2021-03-12\",\r\n                        \"endTime\": \"2031-03-12\",\r\n                        \"postingRhythm\": {\r\n                            \"type\": \"EveryNight\"\r\n                        },\r\n                        \"priceCalculationRule\": \"PerPerson\"\r\n                    }\r\n                },\r\n                \"schedules\": [\r\n                    {\r\n                        \"schedulePrices\": [\r\n                            {\r\n                                \"unitPrice\": \"25\",\r\n                                \"bucket\": \"Bucket1\"\r\n                            }\r\n                        ],\r\n                        \"start\": \"2020-01-01\",\r\n                        \"end\": \"2031-01-31\"\r\n                    }\r\n                ],\r\n                \"hotelId\": \"{{HotelId}}\",\r\n                \"code\": \"BKFSTINC\",\r\n                \"description\": \"Breakfast\"\r\n            }\r\n        ]\r\n    }\r\n}'"
    },
    "url": {
      "raw": "{{HostName}}/rtp/v0/hotels/{{HotelId}}/ratePlans/{{RatePlanCode}}/packages",
      "host": [
        "{{HostName}}"
      ],
      "path": [
        "rtp",
        "v0",
        "hotels",
        "{{HotelId}}",
        "ratePlans",
        "{{RatePlanCode}}",
        "packages"
      ]
    },
    "description": "Use this operation to add a package (such as Breakfast, or box of chocolated) to a rate plan."
  },
  "response": [
  ]
}