Back to Collection Items
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoHttp
Boolean iSuccess
Handle hoJson
Variant vSbRequestBody
Handle hoSbRequestBody
Variant vResp
Handle hoResp
String sTemp1
Integer iTemp1
Boolean bTemp1
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// 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}}"
// }
// ]
// }
// }
// ]
// }
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComUpdateInt Of hoJson "eventItems.eventItemInfo[0].eventItem.quantity" 1 To iSuccess
Get ComUpdateBool Of hoJson "eventItems.eventItemInfo[0].eventItem.externalOrder" True To iSuccess
Get ComUpdateString Of hoJson "eventItems.eventItemInfo[0].eventItem.hotelId" "{{HotelId}}" To iSuccess
Get ComUpdateString Of hoJson "eventItems.eventItemInfo[0].eventItem.itemId.type" "ItemInventoryId" To iSuccess
Get ComUpdateString Of hoJson "eventItems.eventItemInfo[0].eventItem.itemId.id" "2586" To iSuccess
Get ComUpdateBool Of hoJson "eventItems.includedInPackage" False To iSuccess
Get ComUpdateBool Of hoJson "eventItems.critical" False To iSuccess
Get ComUpdateString Of hoJson "eventDetails[0].eventPrimaryInfo.eventId.type" "EventId" To iSuccess
Get ComUpdateString Of hoJson "eventDetails[0].eventPrimaryInfo.eventId.idContext" "OPERA" To iSuccess
Get ComUpdateString Of hoJson "eventDetails[0].eventPrimaryInfo.eventId.id" "{{EventId}}" To iSuccess
Get ComUpdateString Of hoJson "eventDetails[0].eventPrimaryInfo.hotelId" "{{HotelId}}" To iSuccess
Get ComUpdateString Of hoJson "eventDetails[0].eventBlockInfo.blockIdList[0].type" "Block" To iSuccess
Get ComUpdateString Of hoJson "eventDetails[0].eventBlockInfo.blockIdList[0].id" "{{BlockId}}" To iSuccess
Send ComSetRequestHeader To hoHttp "x-app-key" "{{AppKey}}"
Send ComSetRequestHeader To hoHttp "x-hotelid" "{{HotelId}}"
// Adds the "Authorization: Bearer <access_token>" header.
Set ComAuthToken Of hoHttp To "<access_token>"
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequestBody
If (Not(IsComObjectCreated(hoSbRequestBody))) Begin
Send CreateComObject of hoSbRequestBody
End
Get pvComObject of hoSbRequestBody to vSbRequestBody
Get ComEmitSb Of hoJson vSbRequestBody To iSuccess
Get pvComObject of hoSbRequestBody to vSbRequestBody
Get ComPTextSb Of hoHttp "PUT" "https://domain.com/evm/v0/hotels/{{HotelId}}/eventsResources" vSbRequestBody "utf-8" "application/json" False False To vResp
If (IsComObject(vResp)) Begin
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
Set pvComObject Of hoResp To vResp
End
Get ComLastMethodSuccess Of hoHttp To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComStatusCode Of hoResp To iTemp1
Showln iTemp1
Get ComBodyStr Of hoResp To sTemp1
Showln sTemp1
Send Destroy of hoResp
End_Procedure
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": [
]
}