Chilkat Online Tools

Objective-C / ORACLE Hospitality OPERA Cloud REST API Workflows / Update an existing Rate Plan

Back to Collection Items

#import <CkoHttp.h>
#import <CkoJsonObject.h>
#import <CkoStringBuilder.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": {
//     "primaryDetails": {
//       "description": {
//         "defaultText": "Description of rate code "
//       },
//       "startSellDate": "2021-07-03",
//       "endSellDate": "2021-08-31",
//       "privilegedRate": false,
//       "privilegedRateRestriction": false,
//       "lockStatus": "Unlocked"
//     },
//     "classifications": {
//       "rateCategory": "PHONE",
//       "marketCode": "BUSINESS"
//     },
//     "roomTypeList": [
//       {
//         "code": "ECO"
//       },
//       {
//         "code": "SUP"
//       }
//     ],
//     "mobileCheckinAllowed": false,
//     "mobileCheckoutAllowed": false,
//     "hotelId": "{{HotelId}}",
//     "ratePlanCode": "{{RatePlanCode}}",
//     "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
//   }
// }

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"ratePlan.primaryDetails.description.defaultText" value: @"Description of rate code "];
[json UpdateString: @"ratePlan.primaryDetails.startSellDate" value: @"2021-07-03"];
[json UpdateString: @"ratePlan.primaryDetails.endSellDate" value: @"2021-08-31"];
[json UpdateBool: @"ratePlan.primaryDetails.privilegedRate" value: NO];
[json UpdateBool: @"ratePlan.primaryDetails.privilegedRateRestriction" value: NO];
[json UpdateString: @"ratePlan.primaryDetails.lockStatus" value: @"Unlocked"];
[json UpdateString: @"ratePlan.classifications.rateCategory" value: @"PHONE"];
[json UpdateString: @"ratePlan.classifications.marketCode" value: @"BUSINESS"];
[json UpdateString: @"ratePlan.roomTypeList[0].code" value: @"ECO"];
[json UpdateString: @"ratePlan.roomTypeList[1].code" value: @"SUP"];
[json UpdateBool: @"ratePlan.mobileCheckinAllowed" value: NO];
[json UpdateBool: @"ratePlan.mobileCheckoutAllowed" value: NO];
[json UpdateString: @"ratePlan.hotelId" value: @"{{HotelId}}"];
[json UpdateString: @"ratePlan.ratePlanCode" value: @"{{RatePlanCode}}"];
[json UpdateBool: @"ratePlan.supressRate" value: NO];
[json UpdateBool: @"ratePlan.printRate" value: YES];
[json UpdateBool: @"ratePlan.discountAllowed" value: NO];
[json UpdateBool: @"ratePlan.redemption" value: NO];
[json UpdateBool: @"ratePlan.bARRate" value: NO];
[json UpdateBool: @"ratePlan.daily" value: NO];
[json UpdateBool: @"ratePlan.tiered" value: NO];
[json UpdateBool: @"ratePlan.dayUse" value: NO];
[json UpdateBool: @"ratePlan.dayType" value: NO];
[json UpdateBool: @"ratePlan.complimentary" value: NO];
[json UpdateBool: @"ratePlan.houseUse" value: NO];
[json UpdateBool: @"ratePlan.negotiated" value: NO];
[json UpdateBool: @"ratePlan.ownerRate" value: NO];
[json UpdateBool: @"ratePlan.membershipEligible" value: YES];
[json UpdateBool: @"ratePlan.advancedDailyBase" value: NO];
[json UpdateBool: @"ratePlan.advancedDailyRate" value: NO];

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

CkoStringBuilder *sbRequestBody = [[CkoStringBuilder alloc] init];
[json EmitSb: sbRequestBody];

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

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

Curl Command

curl -X PUT
	-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": "Description of rate code "
            },
            "startSellDate": "2021-07-03",
            "endSellDate": "2021-08-31",
            "privilegedRate": false,
            "privilegedRateRestriction": false,
            "lockStatus": "Unlocked"
        },
        "classifications": {
            "rateCategory": "PHONE",
            "marketCode": "BUSINESS"
        },
        "roomTypeList": [
            {
                "code": "ECO"
            },
            {
                "code": "SUP"
            }
        ],
        "mobileCheckinAllowed": false,
        "mobileCheckoutAllowed": false,
        "hotelId": "{{HotelId}}",
        "ratePlanCode": "{{RatePlanCode}}",
        "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/{{RatePlanCode}}

Postman Collection Item JSON

{
  "name": "Update an existing Rate Plan",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{Token}}",
          "type": "string"
        }
      ]
    },
    "method": "PUT",
    "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\": \"Description of rate code \"\r\n            },\r\n            \"startSellDate\": \"2021-07-03\",\r\n            \"endSellDate\": \"2021-08-31\",\r\n            \"privilegedRate\": false,\r\n            \"privilegedRateRestriction\": false,\r\n            \"lockStatus\": \"Unlocked\"\r\n        },\r\n        \"classifications\": {\r\n            \"rateCategory\": \"PHONE\",\r\n            \"marketCode\": \"BUSINESS\"\r\n        },\r\n        \"roomTypeList\": [\r\n            {\r\n                \"code\": \"ECO\"\r\n            },\r\n            {\r\n                \"code\": \"SUP\"\r\n            }\r\n        ],\r\n        \"mobileCheckinAllowed\": false,\r\n        \"mobileCheckoutAllowed\": false,\r\n        \"hotelId\": \"{{HotelId}}\",\r\n        \"ratePlanCode\": \"{{RatePlanCode}}\",\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/{{RatePlanCode}}",
      "host": [
        "{{HostName}}"
      ],
      "path": [
        "rtp",
        "v0",
        "hotels",
        "{{HotelId}}",
        "ratePlans",
        "{{RatePlanCode}}"
      ]
    }
  },
  "response": [
  ]
}