Chilkat Online Tools

PowerBuilder / ORACLE Hospitality OPERA Cloud REST API Workflows / Update the Block's Status

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_SbRequestBody
oleobject loo_Resp

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Use this online tool to generate code from sample JSON: Generate Code to Create JSON

// The following JSON is sent in the request body.

// {
//   "verificationOnly": false,
//   "changeBlockStatus": {
//     "hotelId": "{{HotelId}}",
//     "blockId": {
//       "type": "Block",
//       "idContext": "OPERA",
//       "id": "{{BlockId}}"
//     },
//     "currentBlockStatus": "TEN",
//     "newBlockStatus": "DEF",
//     "reservationType": "GRPGTD",
//     "overbookAll": true,
//     "cancelAllPMReservations": false,
//     "applyChangesToCateringSatus": false,
//     "overrideEventsProcessingWarnings": true
//   }
// }

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_Json.UpdateBool("verificationOnly",0)
loo_Json.UpdateString("changeBlockStatus.hotelId","{{HotelId}}")
loo_Json.UpdateString("changeBlockStatus.blockId.type","Block")
loo_Json.UpdateString("changeBlockStatus.blockId.idContext","OPERA")
loo_Json.UpdateString("changeBlockStatus.blockId.id","{{BlockId}}")
loo_Json.UpdateString("changeBlockStatus.currentBlockStatus","TEN")
loo_Json.UpdateString("changeBlockStatus.newBlockStatus","DEF")
loo_Json.UpdateString("changeBlockStatus.reservationType","GRPGTD")
loo_Json.UpdateBool("changeBlockStatus.overbookAll",1)
loo_Json.UpdateBool("changeBlockStatus.cancelAllPMReservations",0)
loo_Json.UpdateBool("changeBlockStatus.applyChangesToCateringSatus",0)
loo_Json.UpdateBool("changeBlockStatus.overrideEventsProcessingWarnings",1)

loo_Http.SetRequestHeader("x-app-key","{{AppKey}}")
loo_Http.SetRequestHeader("x-hotelid","{{HotelId}}")
// Adds the "Authorization: Bearer <access_token>" header.
loo_Http.AuthToken = "<access_token>"

loo_SbRequestBody = create oleobject
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_Json.EmitSb(loo_SbRequestBody)

loo_Resp = loo_Http.PTextSb("PUT","https://domain.com/blk/v0/hotels/{{HotelId}}/blocks/{{BlockId}}/status",loo_SbRequestBody,"utf-8","application/json",0,0)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Json
    destroy loo_SbRequestBody
    return
end if

Write-Debug string(loo_Resp.StatusCode)
Write-Debug loo_Resp.BodyStr
destroy loo_Resp


destroy loo_Http
destroy loo_Json
destroy loo_SbRequestBody

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-H "x-hotelid: {{HotelId}}"
	-H "x-app-key: {{AppKey}}"
	-d '{
    "verificationOnly": false,
    "changeBlockStatus": {
        "hotelId": "{{HotelId}}",
        "blockId": {
            "type": "Block",
            "idContext": "OPERA",
            "id": "{{BlockId}}"
        },
        "currentBlockStatus": "TEN",
        "newBlockStatus": "DEF",
        "reservationType": "GRPGTD",
        "overbookAll": true,
        "cancelAllPMReservations": false,
        "applyChangesToCateringSatus": false,
        "overrideEventsProcessingWarnings": true
    }
}'
https://domain.com/blk/v0/hotels/{{HotelId}}/blocks/{{BlockId}}/status

Postman Collection Item JSON

{
  "name": "Update the Block's Status",
  "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    \"verificationOnly\": false,\r\n    \"changeBlockStatus\": {\r\n        \"hotelId\": \"{{HotelId}}\",\r\n        \"blockId\": {\r\n            \"type\": \"Block\",\r\n            \"idContext\": \"OPERA\",\r\n            \"id\": \"{{BlockId}}\"\r\n        },\r\n        \"currentBlockStatus\": \"TEN\",\r\n        \"newBlockStatus\": \"DEF\",\r\n        \"reservationType\": \"GRPGTD\",\r\n        \"overbookAll\": true,\r\n        \"cancelAllPMReservations\": false,\r\n        \"applyChangesToCateringSatus\": false,\r\n        \"overrideEventsProcessingWarnings\": true\r\n    }\r\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{HostName}}/blk/v0/hotels/{{HotelId}}/blocks/{{BlockId}}/status",
      "host": [
        "{{HostName}}"
      ],
      "path": [
        "blk",
        "v0",
        "hotels",
        "{{HotelId}}",
        "blocks",
        "{{BlockId}}",
        "status"
      ]
    },
    "description": "\"overbookAll\": true/ false.  Set this to false, to ensure relevant warnings are returned about changing the status.   Set to true, to override all warnings."
  },
  "response": [
  ]
}