Chilkat Online Tools

unicodeC / ORACLE Hospitality OPERA Cloud REST API Workflows / Create a new Block

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    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.

    // {
    //   "blocks": {
    //     "blockInfo": [
    //       {
    //         "block": {
    //           "blockDetails": {
    //             "blockCode": "ORCLE0622",
    //             "blockName": "Oracle Conference 2022",
    //             "blockAliases": [
    //             ],
    //             "timeSpan": {
    //               "startDate": "2022-06-01",
    //               "endDate": "2022-06-02"
    //             },
    //             "shoulderDates": {},
    //             "blockStatus": {
    //               "bookingStatus": {
    //                 "status": {
    //                   "code": "TEN"
    //                 }
    //               }
    //             },
    //             "reservationType": {
    //               "reservationType": "GRPGTD"
    //             },
    //             "marketCode": {
    //               "marketCode": "LEISURE"
    //             },
    //             "sourceOfSale": {
    //               "sourceCode": {
    //                 "sourceCode": "WEB"
    //               }
    //             },
    //             "reservationMethod": {},
    //             "bookingType": {},
    //             "rateProtectionDetails": {
    //               "criteria": "None"
    //             },
    //             "nonCompeteDetails": {
    //               "criteria": "None"
    //             },
    //             "currencyCode": "USD",
    //             "blockClassification": "RegularBooking",
    //             "cateringOnlyBlock": false,
    //             "allowRateOverride": false,
    //             "manualCutOff": false,
    //             "wholesaleBlock": false,
    //             "controlBlockLocally": false
    //           },
    //           "blockOwners": {
    //             "owner": [
    //               {
    //                 "ownership": "Block",
    //                 "ownerCode": "ALL",
    //                 "primary": true
    //               },
    //               {
    //                 "ownership": "Catering",
    //                 "ownerCode": "ALL",
    //                 "primary": true
    //               },
    //               {
    //                 "ownership": "Rooms",
    //                 "ownerCode": "ALL",
    //                 "primary": true
    //               }
    //             ],
    //             "lockBlockOwners": false,
    //             "lockRoomsOwners": false,
    //             "lockCateringOwners": false
    //           },
    //           "reservationDetails": {
    //             "ratePlanCode": [
    //               {
    //                 "primary": true,
    //                 "ratePlanCode": "BAR"
    //               }
    //             ],
    //             "traceCode": {},
    //             "breakfast": {
    //               "breakfastIncluded": false,
    //               "price": {
    //                 "currencyCode": "USD"
    //               }
    //             },
    //             "porterage": {
    //               "porterageIncluded": false,
    //               "price": {
    //                 "currencyCode": "USD"
    //               }
    //             },
    //             "elastic": "1",
    //             "suppressRate": false,
    //             "housing": true
    //           },
    //           "catering": {
    //             "cateringStatus": {
    //               "bookingStatus": {
    //                 "status": {}
    //               }
    //             },
    //             "eventAttendees": {},
    //             "overrideEventsProcessingWarnings": true
    //           },
    //           "blockProfiles": {
    //             "fullOverlay": false
    //           },
    //           "blockPackages": [
    //           ],
    //           "externalAttributes": {
    //             "eventType": "Convention",
    //             "rollEndDate": false
    //           },
    //           "hotelId": "{{HotelId}}",
    //           "markAsRecentlyAccessed": true
    //         }
    //       }
    //     ]
    //   }
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.blockDetails.blockCode",L"ORCLE0622");
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.blockDetails.blockName",L"Oracle Conference 2022");
    CkJsonObjectW_UpdateNewArray(json,L"blocks.blockInfo[0].block.blockDetails.blockAliases");
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.blockDetails.timeSpan.startDate",L"2022-06-01");
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.blockDetails.timeSpan.endDate",L"2022-06-02");
    CkJsonObjectW_UpdateNewObject(json,L"blocks.blockInfo[0].block.blockDetails.shoulderDates");
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.blockDetails.blockStatus.bookingStatus.status.code",L"TEN");
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.blockDetails.reservationType.reservationType",L"GRPGTD");
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.blockDetails.marketCode.marketCode",L"LEISURE");
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.blockDetails.sourceOfSale.sourceCode.sourceCode",L"WEB");
    CkJsonObjectW_UpdateNewObject(json,L"blocks.blockInfo[0].block.blockDetails.reservationMethod");
    CkJsonObjectW_UpdateNewObject(json,L"blocks.blockInfo[0].block.blockDetails.bookingType");
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.blockDetails.rateProtectionDetails.criteria",L"None");
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.blockDetails.nonCompeteDetails.criteria",L"None");
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.blockDetails.currencyCode",L"USD");
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.blockDetails.blockClassification",L"RegularBooking");
    CkJsonObjectW_UpdateBool(json,L"blocks.blockInfo[0].block.blockDetails.cateringOnlyBlock",FALSE);
    CkJsonObjectW_UpdateBool(json,L"blocks.blockInfo[0].block.blockDetails.allowRateOverride",FALSE);
    CkJsonObjectW_UpdateBool(json,L"blocks.blockInfo[0].block.blockDetails.manualCutOff",FALSE);
    CkJsonObjectW_UpdateBool(json,L"blocks.blockInfo[0].block.blockDetails.wholesaleBlock",FALSE);
    CkJsonObjectW_UpdateBool(json,L"blocks.blockInfo[0].block.blockDetails.controlBlockLocally",FALSE);
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.blockOwners.owner[0].ownership",L"Block");
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.blockOwners.owner[0].ownerCode",L"ALL");
    CkJsonObjectW_UpdateBool(json,L"blocks.blockInfo[0].block.blockOwners.owner[0].primary",TRUE);
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.blockOwners.owner[1].ownership",L"Catering");
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.blockOwners.owner[1].ownerCode",L"ALL");
    CkJsonObjectW_UpdateBool(json,L"blocks.blockInfo[0].block.blockOwners.owner[1].primary",TRUE);
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.blockOwners.owner[2].ownership",L"Rooms");
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.blockOwners.owner[2].ownerCode",L"ALL");
    CkJsonObjectW_UpdateBool(json,L"blocks.blockInfo[0].block.blockOwners.owner[2].primary",TRUE);
    CkJsonObjectW_UpdateBool(json,L"blocks.blockInfo[0].block.blockOwners.lockBlockOwners",FALSE);
    CkJsonObjectW_UpdateBool(json,L"blocks.blockInfo[0].block.blockOwners.lockRoomsOwners",FALSE);
    CkJsonObjectW_UpdateBool(json,L"blocks.blockInfo[0].block.blockOwners.lockCateringOwners",FALSE);
    CkJsonObjectW_UpdateBool(json,L"blocks.blockInfo[0].block.reservationDetails.ratePlanCode[0].primary",TRUE);
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.reservationDetails.ratePlanCode[0].ratePlanCode",L"BAR");
    CkJsonObjectW_UpdateNewObject(json,L"blocks.blockInfo[0].block.reservationDetails.traceCode");
    CkJsonObjectW_UpdateBool(json,L"blocks.blockInfo[0].block.reservationDetails.breakfast.breakfastIncluded",FALSE);
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.reservationDetails.breakfast.price.currencyCode",L"USD");
    CkJsonObjectW_UpdateBool(json,L"blocks.blockInfo[0].block.reservationDetails.porterage.porterageIncluded",FALSE);
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.reservationDetails.porterage.price.currencyCode",L"USD");
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.reservationDetails.elastic",L"1");
    CkJsonObjectW_UpdateBool(json,L"blocks.blockInfo[0].block.reservationDetails.suppressRate",FALSE);
    CkJsonObjectW_UpdateBool(json,L"blocks.blockInfo[0].block.reservationDetails.housing",TRUE);
    CkJsonObjectW_UpdateNewObject(json,L"blocks.blockInfo[0].block.catering.cateringStatus.bookingStatus.status");
    CkJsonObjectW_UpdateNewObject(json,L"blocks.blockInfo[0].block.catering.eventAttendees");
    CkJsonObjectW_UpdateBool(json,L"blocks.blockInfo[0].block.catering.overrideEventsProcessingWarnings",TRUE);
    CkJsonObjectW_UpdateBool(json,L"blocks.blockInfo[0].block.blockProfiles.fullOverlay",FALSE);
    CkJsonObjectW_UpdateNewArray(json,L"blocks.blockInfo[0].block.blockPackages");
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.externalAttributes.eventType",L"Convention");
    CkJsonObjectW_UpdateBool(json,L"blocks.blockInfo[0].block.externalAttributes.rollEndDate",FALSE);
    CkJsonObjectW_UpdateString(json,L"blocks.blockInfo[0].block.hotelId",L"{{HotelId}}");
    CkJsonObjectW_UpdateBool(json,L"blocks.blockInfo[0].block.markAsRecentlyAccessed",TRUE);

    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>");

    resp = CkHttpW_PostJson3(http,L"https://domain.com/blk/v0/hotels/{{HotelId}}/block",L"application/json",json);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);

    }

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "x-hotelid: {{HotelId}}"
	-H "x-app-key: {{AppKey}}"
	-d '{
    "blocks": {
        "blockInfo": [
            {
                "block": {
                    "blockDetails": {
                        "blockCode": "ORCLE0622",
                        "blockName": "Oracle Conference 2022",
                        "blockAliases": [],
                        "timeSpan": {
                            "startDate": "2022-06-01",
                            "endDate": "2022-06-02"
                        },
                        "shoulderDates": {},
                        "blockStatus": {
                            "bookingStatus": {
                                "status": {
                                    "code": "TEN"
                                }
                            }
                        },
                        "reservationType": {
                            "reservationType": "GRPGTD"
                        },
                        "marketCode": {
                            "marketCode": "LEISURE"
                        },
                        "sourceOfSale": {
                            "sourceCode": {
                                "sourceCode": "WEB"
                            }
                        },
                        "reservationMethod": {},
                        "bookingType": {},
                        "rateProtectionDetails": {
                            "criteria": "None"
                        },
                        "nonCompeteDetails": {
                            "criteria": "None"
                        },
                        "currencyCode": "USD",
                        "blockClassification": "RegularBooking",
                        "cateringOnlyBlock": false,
                        "allowRateOverride": false,
                        "manualCutOff": false,
                        "wholesaleBlock": false,
                        "controlBlockLocally": false
                    },
                    "blockOwners": {
                        "owner": [
                            {
                                "ownership": "Block",
                                "ownerCode": "ALL",
                                "primary": true
                            },
                            {
                                "ownership": "Catering",
                                "ownerCode": "ALL",
                                "primary": true
                            },
                            {
                                "ownership": "Rooms",
                                "ownerCode": "ALL",
                                "primary": true
                            }
                        ],
                        "lockBlockOwners": false,
                        "lockRoomsOwners": false,
                        "lockCateringOwners": false
                    },
                    "reservationDetails": {
                        "ratePlanCode": [
                            {
                                "primary": true,
                                "ratePlanCode": "BAR"
                            }
                        ],
                        "traceCode": {},
                        "breakfast": {
                            "breakfastIncluded": false,
                            "price": {
                                "currencyCode": "USD"
                            }
                        },
                        "porterage": {
                            "porterageIncluded": false,
                            "price": {
                                "currencyCode": "USD"
                            }
                        },
                        "elastic": "1",
                        "suppressRate": false,
                        "housing": true
                    },
                    "catering": {
                        "cateringStatus": {
                            "bookingStatus": {
                                "status": {}
                            }
                        },
                        "eventAttendees": {},
                        "overrideEventsProcessingWarnings": true
                    },
                    "blockProfiles": {
                        "fullOverlay": false
                    },
                    "blockPackages": [],
                    "externalAttributes": {
                        "eventType": "Convention",
                        "rollEndDate": false
                    },
                    "hotelId": "{{HotelId}}",
                    "markAsRecentlyAccessed": true
                }
            }
        ]
    }
}'
https://domain.com/blk/v0/hotels/{{HotelId}}/block

Postman Collection Item JSON

{
  "name": "Create a new Block",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "var data = pm.response.headers.get(\"Location\").split(\"/\").pop();\r",
          "postman.setEnvironmentVariable(\"BlockId\", data);"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{Token}}",
          "type": "string"
        }
      ]
    },
    "method": "POST",
    "header": [
      {
        "key": "x-hotelid",
        "value": "{{HotelId}}"
      },
      {
        "key": "x-app-key",
        "value": "{{AppKey}}"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\r\n    \"blocks\": {\r\n        \"blockInfo\": [\r\n            {\r\n                \"block\": {\r\n                    \"blockDetails\": {\r\n                        \"blockCode\": \"ORCLE0622\",\r\n                        \"blockName\": \"Oracle Conference 2022\",\r\n                        \"blockAliases\": [],\r\n                        \"timeSpan\": {\r\n                            \"startDate\": \"2022-06-01\",\r\n                            \"endDate\": \"2022-06-02\"\r\n                        },\r\n                        \"shoulderDates\": {},\r\n                        \"blockStatus\": {\r\n                            \"bookingStatus\": {\r\n                                \"status\": {\r\n                                    \"code\": \"TEN\"\r\n                                }\r\n                            }\r\n                        },\r\n                        \"reservationType\": {\r\n                            \"reservationType\": \"GRPGTD\"\r\n                        },\r\n                        \"marketCode\": {\r\n                            \"marketCode\": \"LEISURE\"\r\n                        },\r\n                        \"sourceOfSale\": {\r\n                            \"sourceCode\": {\r\n                                \"sourceCode\": \"WEB\"\r\n                            }\r\n                        },\r\n                        \"reservationMethod\": {},\r\n                        \"bookingType\": {},\r\n                        \"rateProtectionDetails\": {\r\n                            \"criteria\": \"None\"\r\n                        },\r\n                        \"nonCompeteDetails\": {\r\n                            \"criteria\": \"None\"\r\n                        },\r\n                        \"currencyCode\": \"USD\",\r\n                        \"blockClassification\": \"RegularBooking\",\r\n                        \"cateringOnlyBlock\": false,\r\n                        \"allowRateOverride\": false,\r\n                        \"manualCutOff\": false,\r\n                        \"wholesaleBlock\": false,\r\n                        \"controlBlockLocally\": false\r\n                    },\r\n                    \"blockOwners\": {\r\n                        \"owner\": [\r\n                            {\r\n                                \"ownership\": \"Block\",\r\n                                \"ownerCode\": \"ALL\",\r\n                                \"primary\": true\r\n                            },\r\n                            {\r\n                                \"ownership\": \"Catering\",\r\n                                \"ownerCode\": \"ALL\",\r\n                                \"primary\": true\r\n                            },\r\n                            {\r\n                                \"ownership\": \"Rooms\",\r\n                                \"ownerCode\": \"ALL\",\r\n                                \"primary\": true\r\n                            }\r\n                        ],\r\n                        \"lockBlockOwners\": false,\r\n                        \"lockRoomsOwners\": false,\r\n                        \"lockCateringOwners\": false\r\n                    },\r\n                    \"reservationDetails\": {\r\n                        \"ratePlanCode\": [\r\n                            {\r\n                                \"primary\": true,\r\n                                \"ratePlanCode\": \"BAR\"\r\n                            }\r\n                        ],\r\n                        \"traceCode\": {},\r\n                        \"breakfast\": {\r\n                            \"breakfastIncluded\": false,\r\n                            \"price\": {\r\n                                \"currencyCode\": \"USD\"\r\n                            }\r\n                        },\r\n                        \"porterage\": {\r\n                            \"porterageIncluded\": false,\r\n                            \"price\": {\r\n                                \"currencyCode\": \"USD\"\r\n                            }\r\n                        },\r\n                        \"elastic\": \"1\",\r\n                        \"suppressRate\": false,\r\n                        \"housing\": true\r\n                    },\r\n                    \"catering\": {\r\n                        \"cateringStatus\": {\r\n                            \"bookingStatus\": {\r\n                                \"status\": {}\r\n                            }\r\n                        },\r\n                        \"eventAttendees\": {},\r\n                        \"overrideEventsProcessingWarnings\": true\r\n                    },\r\n                    \"blockProfiles\": {\r\n                        \"fullOverlay\": false\r\n                    },\r\n                    \"blockPackages\": [],\r\n                    \"externalAttributes\": {\r\n                        \"eventType\": \"Convention\",\r\n                        \"rollEndDate\": false\r\n                    },\r\n                    \"hotelId\": \"{{HotelId}}\",\r\n                    \"markAsRecentlyAccessed\": true\r\n                }\r\n            }\r\n        ]\r\n    }\r\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{HostName}}/blk/v0/hotels/{{HotelId}}/block",
      "host": [
        "{{HostName}}"
      ],
      "path": [
        "blk",
        "v0",
        "hotels",
        "{{HotelId}}",
        "block"
      ]
    }
  },
  "response": [
  ]
}