Chilkat Online Tools

Objective-C / ORACLE Hospitality OPERA Cloud REST API Workflows / Add event resources to the event

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.

// {
//   "eventItems": {
//     "eventItemInfo": [
//       {
//         "eventItem": {
//           "quantity": 1,
//           "externalOrder": true,
//           "hotelId": "{{HotelId}}",
//           "itemId": {
//             "type": "ItemInventoryId",
//             "id": "2586"
//           }
//         }
//       }
//     ],
//     "includedInPackage": false,
//     "critical": false
//   },
//   "eventDetails": [
//     {
//       "eventPrimaryInfo": {
//         "eventId": {
//           "type": "EventId",
//           "idContext": "OPERA",
//           "id": "{{EventId}}"
//         },
//         "hotelId": "{{HotelId}}"
//       },
//       "eventBlockInfo": {
//         "blockIdList": [
//           {
//             "type": "Block",
//             "id": "{{BlockId}}"
//           }
//         ]
//       }
//     }
//   ]
// }

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateInt: @"eventItems.eventItemInfo[0].eventItem.quantity" value: [NSNumber numberWithInt: 1]];
[json UpdateBool: @"eventItems.eventItemInfo[0].eventItem.externalOrder" value: YES];
[json UpdateString: @"eventItems.eventItemInfo[0].eventItem.hotelId" value: @"{{HotelId}}"];
[json UpdateString: @"eventItems.eventItemInfo[0].eventItem.itemId.type" value: @"ItemInventoryId"];
[json UpdateString: @"eventItems.eventItemInfo[0].eventItem.itemId.id" value: @"2586"];
[json UpdateBool: @"eventItems.includedInPackage" value: NO];
[json UpdateBool: @"eventItems.critical" value: NO];
[json UpdateString: @"eventDetails[0].eventPrimaryInfo.eventId.type" value: @"EventId"];
[json UpdateString: @"eventDetails[0].eventPrimaryInfo.eventId.idContext" value: @"OPERA"];
[json UpdateString: @"eventDetails[0].eventPrimaryInfo.eventId.id" value: @"{{EventId}}"];
[json UpdateString: @"eventDetails[0].eventPrimaryInfo.hotelId" value: @"{{HotelId}}"];
[json UpdateString: @"eventDetails[0].eventBlockInfo.blockIdList[0].type" value: @"Block"];
[json UpdateString: @"eventDetails[0].eventBlockInfo.blockIdList[0].id" value: @"{{BlockId}}"];

[http SetRequestHeader: @"x-app-key" value: @"{{AppKey}}"];
[http SetRequestHeader: @"x-hotelid" value: @"{{HotelId}}"];
// Adds the "Authorization: Bearer <access_token>" header.
http.AuthToken = @"<access_token>";

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

CkoHttpResponse *resp = [http PTextSb: @"PUT" url: @"https://domain.com/evm/v0/hotels/{{HotelId}}/eventsResources" textData: sbRequestBody charset: @"utf-8" contentType: @"application/json" 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 "x-app-key: {{AppKey}}"
	-H "x-hotelid: {{HotelId}}"
	-d '{
    "eventItems": {
        "eventItemInfo": [
            {
                "eventItem": {
                    "quantity": 1,
                    "externalOrder": true,
                    "hotelId": "{{HotelId}}",
                    "itemId": {
                        "type": "ItemInventoryId",
                        "id": "2586"
                    }
                }
            }
        ],
        "includedInPackage": false,
        "critical": false
    },
    "eventDetails": [
        {
            "eventPrimaryInfo": {
                "eventId": {
                    "type": "EventId",
                    "idContext": "OPERA",
                    "id": "{{EventId}}"
                },
                "hotelId": "{{HotelId}}"
            },
            "eventBlockInfo": {
                "blockIdList": [
                    {
                        "type": "Block",
                        "id": "{{BlockId}}"
                    }
                ]
            }
        }
    ]
}'
https://domain.com/evm/v0/hotels/{{HotelId}}/eventsResources

Postman Collection Item JSON

{
  "name": "Add event resources to the event",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{Token}}",
          "type": "string"
        }
      ]
    },
    "method": "PUT",
    "header": [
      {
        "key": "x-app-key",
        "type": "text",
        "value": "{{AppKey}}"
      },
      {
        "key": "x-hotelid",
        "value": "{{HotelId}}",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\r\n    \"eventItems\": {\r\n        \"eventItemInfo\": [\r\n            {\r\n                \"eventItem\": {\r\n                    \"quantity\": 1,\r\n                    \"externalOrder\": true,\r\n                    \"hotelId\": \"{{HotelId}}\",\r\n                    \"itemId\": {\r\n                        \"type\": \"ItemInventoryId\",\r\n                        \"id\": \"2586\"\r\n                    }\r\n                }\r\n            }\r\n        ],\r\n        \"includedInPackage\": false,\r\n        \"critical\": false\r\n    },\r\n    \"eventDetails\": [\r\n        {\r\n            \"eventPrimaryInfo\": {\r\n                \"eventId\": {\r\n                    \"type\": \"EventId\",\r\n                    \"idContext\": \"OPERA\",\r\n                    \"id\": \"{{EventId}}\"\r\n                },\r\n                \"hotelId\": \"{{HotelId}}\"\r\n            },\r\n            \"eventBlockInfo\": {\r\n                \"blockIdList\": [\r\n                    {\r\n                        \"type\": \"Block\",\r\n                        \"id\": \"{{BlockId}}\"\r\n                    }\r\n                ]\r\n            }\r\n        }\r\n    ]\r\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{HostName}}/evm/v0/hotels/{{HotelId}}/eventsResources",
      "host": [
        "{{HostName}}"
      ],
      "path": [
        "evm",
        "v0",
        "hotels",
        "{{HotelId}}",
        "eventsResources"
      ]
    }
  },
  "response": [
  ]
}