Chilkat Online Tools

unicodeCpp / ORACLE Hospitality OPERA Cloud REST API Workflows / Add notes to a block

Back to Collection Items

#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>
#include <CkHttpResponseW.h>

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

    CkHttpW http;
    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.

    // {
    //   "blocks": [
    //     {
    //       "blockIdList": [
    //         {
    //           "type": "Block",
    //           "idContext": "OPERA",
    //           "id": "{{BlockId}}"
    //         }
    //       ],
    //       "comments": {
    //         "commentInfo": [
    //           {
    //             "comment": {
    //               "commentTitle": "Block note title",
    //               "type": "BOOK",
    //               "internal": true,
    //               "hotelId": "{{HotelId}}",
    //               "text": {
    //                 "value": "Block notes can go here"
    //               }
    //             }
    //           }
    //         ]
    //       },
    //       "hotelId": "{{HotelId}}",
    //       "markAsRecentlyAccessed": false
    //     }
    //   ]
    // }

    CkJsonObjectW json;
    json.UpdateString(L"blocks[0].blockIdList[0].type",L"Block");
    json.UpdateString(L"blocks[0].blockIdList[0].idContext",L"OPERA");
    json.UpdateString(L"blocks[0].blockIdList[0].id",L"{{BlockId}}");
    json.UpdateString(L"blocks[0].comments.commentInfo[0].comment.commentTitle",L"Block note title");
    json.UpdateString(L"blocks[0].comments.commentInfo[0].comment.type",L"BOOK");
    json.UpdateBool(L"blocks[0].comments.commentInfo[0].comment.internal",true);
    json.UpdateString(L"blocks[0].comments.commentInfo[0].comment.hotelId",L"{{HotelId}}");
    json.UpdateString(L"blocks[0].comments.commentInfo[0].comment.text.value",L"Block notes can go here");
    json.UpdateString(L"blocks[0].hotelId",L"{{HotelId}}");
    json.UpdateBool(L"blocks[0].markAsRecentlyAccessed",false);

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

    CkStringBuilderW sbRequestBody;
    json.EmitSb(sbRequestBody);

    CkHttpResponseW *resp = http.PTextSb(L"PUT",L"https://domain.com/blk/v0/hotels/{{HotelId}}/blocks/{{BlockId}}",sbRequestBody,L"utf-8",L"application/json",false,false);
    if (http.get_LastMethodSuccess() == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    wprintf(L"%d\n",resp->get_StatusCode());
    wprintf(L"%s\n",resp->bodyStr());
    delete resp;
    }

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-H "x-hotelid: {{HotelId}}"
	-H "x-app-key: {{AppKey}}"
	-d '{
    "blocks": [
        {
            "blockIdList": [
                {
                    "type": "Block",
                    "idContext": "OPERA",
                    "id": "{{BlockId}}"
                }
            ],
            "comments": {
                "commentInfo": [
                    {
                        "comment": {
                            "commentTitle": "Block note title",
                            "type": "BOOK",
                            "internal": true,
                            "hotelId": "{{HotelId}}",
                            "text": {
                                "value": "Block notes can go here"
                            }
                        }
                    }
                ]
            },
            "hotelId": "{{HotelId}}",
            "markAsRecentlyAccessed": false
        }
    ]
}'
https://domain.com/blk/v0/hotels/{{HotelId}}/blocks/{{BlockId}}

Postman Collection Item JSON

{
  "name": "Add notes to a block",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{Token}}",
          "type": "string"
        }
      ]
    },
    "method": "PUT",
    "header": [
      {
        "key": "x-hotelid",
        "value": "{{HotelId}}"
      },
      {
        "key": "x-app-key",
        "value": "{{AppKey}}"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\r\n    \"blocks\": [\r\n        {\r\n            \"blockIdList\": [\r\n                {\r\n                    \"type\": \"Block\",\r\n                    \"idContext\": \"OPERA\",\r\n                    \"id\": \"{{BlockId}}\"\r\n                }\r\n            ],\r\n            \"comments\": {\r\n                \"commentInfo\": [\r\n                    {\r\n                        \"comment\": {\r\n                            \"commentTitle\": \"Block note title\",\r\n                            \"type\": \"BOOK\",\r\n                            \"internal\": true,\r\n                            \"hotelId\": \"{{HotelId}}\",\r\n                            \"text\": {\r\n                                \"value\": \"Block notes can go here\"\r\n                            }\r\n                        }\r\n                    }\r\n                ]\r\n            },\r\n            \"hotelId\": \"{{HotelId}}\",\r\n            \"markAsRecentlyAccessed\": false\r\n        }\r\n    ]\r\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{HostName}}/blk/v0/hotels/{{HotelId}}/blocks/{{BlockId}}",
      "host": [
        "{{HostName}}"
      ],
      "path": [
        "blk",
        "v0",
        "hotels",
        "{{HotelId}}",
        "blocks",
        "{{BlockId}}"
      ]
    }
  },
  "response": [
  ]
}