Chilkat Online Tools

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

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    -- 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
    --         }
    --       }
    --     ]
    --   }
    -- }

    DECLARE @json int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT

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

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'x-app-key', '{{AppKey}}'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'x-hotelid', '{{HotelId}}'
    -- Adds the "Authorization: Bearer <access_token>" header.
    EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://domain.com/blk/v0/hotels/{{HotelId}}/block', 'application/json', @json
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        RETURN
      END

    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT @iTmp0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    PRINT @sTmp0
    EXEC @hr = sp_OADestroy @resp


    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json


END
GO

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