Back to Collection Items
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkHttpResponseW.h>
void ChilkatSample(void)
{
HCkHttpW http;
BOOL success;
HCkJsonObjectW json;
HCkStringBuilderW sbRequestBody;
HCkHttpResponseW resp;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_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 = CkJsonObjectW_Create();
CkJsonObjectW_UpdateInt(json,L"eventItems.eventItemInfo[0].eventItem.quantity",1);
CkJsonObjectW_UpdateBool(json,L"eventItems.eventItemInfo[0].eventItem.externalOrder",TRUE);
CkJsonObjectW_UpdateString(json,L"eventItems.eventItemInfo[0].eventItem.hotelId",L"{{HotelId}}");
CkJsonObjectW_UpdateString(json,L"eventItems.eventItemInfo[0].eventItem.itemId.type",L"ItemInventoryId");
CkJsonObjectW_UpdateString(json,L"eventItems.eventItemInfo[0].eventItem.itemId.id",L"2586");
CkJsonObjectW_UpdateBool(json,L"eventItems.includedInPackage",FALSE);
CkJsonObjectW_UpdateBool(json,L"eventItems.critical",FALSE);
CkJsonObjectW_UpdateString(json,L"eventDetails[0].eventPrimaryInfo.eventId.type",L"EventId");
CkJsonObjectW_UpdateString(json,L"eventDetails[0].eventPrimaryInfo.eventId.idContext",L"OPERA");
CkJsonObjectW_UpdateString(json,L"eventDetails[0].eventPrimaryInfo.eventId.id",L"{{EventId}}");
CkJsonObjectW_UpdateString(json,L"eventDetails[0].eventPrimaryInfo.hotelId",L"{{HotelId}}");
CkJsonObjectW_UpdateString(json,L"eventDetails[0].eventBlockInfo.blockIdList[0].type",L"Block");
CkJsonObjectW_UpdateString(json,L"eventDetails[0].eventBlockInfo.blockIdList[0].id",L"{{BlockId}}");
CkHttpW_SetRequestHeader(http,L"x-app-key",L"{{AppKey}}");
CkHttpW_SetRequestHeader(http,L"x-hotelid",L"{{HotelId}}");
// Adds the "Authorization: Bearer <access_token>" header.
CkHttpW_putAuthToken(http,L"<access_token>");
sbRequestBody = CkStringBuilderW_Create();
CkJsonObjectW_EmitSb(json,sbRequestBody);
resp = CkHttpW_PTextSb(http,L"PUT",L"https://domain.com/evm/v0/hotels/{{HotelId}}/eventsResources",sbRequestBody,L"utf-8",L"application/json",FALSE,FALSE);
if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbRequestBody);
return;
}
wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
CkHttpResponseW_Dispose(resp);
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_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": [
]
}