Chilkat Online Tools

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

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkStringBuilder.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkJsonObject json;
    HCkStringBuilder sbRequestBody;
    HCkHttpResponse resp;

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

    http = CkHttp_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.

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

    json = CkJsonObject_Create();
    CkJsonObject_UpdateInt(json,"eventItems.eventItemInfo[0].eventItem.quantity",1);
    CkJsonObject_UpdateBool(json,"eventItems.eventItemInfo[0].eventItem.externalOrder",TRUE);
    CkJsonObject_UpdateString(json,"eventItems.eventItemInfo[0].eventItem.hotelId","{{HotelId}}");
    CkJsonObject_UpdateString(json,"eventItems.eventItemInfo[0].eventItem.itemId.type","ItemInventoryId");
    CkJsonObject_UpdateString(json,"eventItems.eventItemInfo[0].eventItem.itemId.id","2586");
    CkJsonObject_UpdateBool(json,"eventItems.includedInPackage",FALSE);
    CkJsonObject_UpdateBool(json,"eventItems.critical",FALSE);
    CkJsonObject_UpdateString(json,"eventDetails[0].eventPrimaryInfo.eventId.type","EventId");
    CkJsonObject_UpdateString(json,"eventDetails[0].eventPrimaryInfo.eventId.idContext","OPERA");
    CkJsonObject_UpdateString(json,"eventDetails[0].eventPrimaryInfo.eventId.id","{{EventId}}");
    CkJsonObject_UpdateString(json,"eventDetails[0].eventPrimaryInfo.hotelId","{{HotelId}}");
    CkJsonObject_UpdateString(json,"eventDetails[0].eventBlockInfo.blockIdList[0].type","Block");
    CkJsonObject_UpdateString(json,"eventDetails[0].eventBlockInfo.blockIdList[0].id","{{BlockId}}");

    CkHttp_SetRequestHeader(http,"x-app-key","{{AppKey}}");
    CkHttp_SetRequestHeader(http,"x-hotelid","{{HotelId}}");
    // Adds the "Authorization: Bearer <access_token>" header.
    CkHttp_putAuthToken(http,"<access_token>");

    sbRequestBody = CkStringBuilder_Create();
    CkJsonObject_EmitSb(json,sbRequestBody);

    resp = CkHttp_PTextSb(http,"PUT","https://domain.com/evm/v0/hotels/{{HotelId}}/eventsResources",sbRequestBody,"utf-8","application/json",FALSE,FALSE);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(json);
        CkStringBuilder_Dispose(sbRequestBody);
        return;
    }

    printf("%d\n",CkHttpResponse_getStatusCode(resp));
    printf("%s\n",CkHttpResponse_bodyStr(resp));
    CkHttpResponse_Dispose(resp);


    CkHttp_Dispose(http);
    CkJsonObject_Dispose(json);
    CkStringBuilder_Dispose(sbRequestBody);

    }

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