Chilkat Online Tools

PureBasic / ORACLE Hospitality OPERA Cloud REST API Workflows / Create a new reservation

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

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

    ; The following JSON is sent in the request body.

    ; {
    ;   "reservations": {
    ;     "reservation": [
    ;       {
    ;         "sourceOfSale": {
    ;           "sourceType": "PMS",
    ;           "sourceCode": "{{HotelId}}"
    ;         },
    ;         "roomStay": {
    ;           "roomRates": [
    ;             {
    ;               "total": {
    ;                 "amountBeforeTax": "200"
    ;               },
    ;               "rates": {
    ;                 "rate": [
    ;                   {
    ;                     "base": {
    ;                       "amountBeforeTax": "200",
    ;                       "currencyCode": "USD"
    ;                     },
    ;                     "shareDistributionInstruction": "Full",
    ;                     "total": {
    ;                       "amountBeforeTax": "200"
    ;                     },
    ;                     "start": "{{currentdate}}",
    ;                     "end": "{{currentdateplus1}}"
    ;                   }
    ;                 ]
    ;               },
    ;               "guestCounts": {
    ;                 "adults": "1",
    ;                 "children": "0"
    ;               },
    ;               "roomType": "{{RoomTypeCode}}",
    ;               "ratePlanCode": "{{RatePlanCode}}",
    ;               "start": "{{currentdate}}",
    ;               "end": "{{currentdateplus1}}",
    ;               "suppressRate": true,
    ;               "marketCode": "LEISURE",
    ;               "marketCodeDescription": "Leisure",
    ;               "sourceCode": "PHONE",
    ;               "sourceCodeDescription": "Over the Phone",
    ;               "numberOfUnits": "1",
    ;               "pseudoRoom": false,
    ;               "roomTypeCharged": "{{RoomTypeCode}}",
    ;               "houseUseOnly": false,
    ;               "complimentary": false,
    ;               "fixedRate": true,
    ;               "discountAllowed": false,
    ;               "bogoDiscount": false
    ;             }
    ;           ],
    ;           "guestCounts": {
    ;             "adults": "1",
    ;             "children": "0"
    ;           },
    ;           "arrivalDate": "{{currentdate}}",
    ;           "departureDate": "{{currentdateplus1}}",
    ;           "guarantee": {
    ;             "guaranteeCode": "6PM",
    ;             "shortDescription": "6PM Hold"
    ;           },
    ;           "roomNumberLocked": false,
    ;           "printRate": false
    ;         },
    ;         "reservationGuests": [
    ;           {
    ;             "profileInfo": {
    ;               "profile": {
    ;                 "customer": {
    ;                   "personName": [
    ;                     {
    ;                       "givenName": "Jane",
    ;                       "surname": "Smith",
    ;                       "nameType": "Primary"
    ;                     },
    ;                     {
    ;                       "nameType": "External"
    ;                     }
    ;                   ],
    ;                   "language": "E"
    ;                 },
    ;                 "profileType": "Guest"
    ;               }
    ;             },
    ;             "primary": true
    ;           }
    ;         ],
    ;         "reservationPaymentMethods": [
    ;           {
    ;             "paymentMethod": "CA",
    ;             "folioView": "1"
    ;           }
    ;         ],
    ;         "comments": [
    ;           {
    ;             "comment": {
    ;               "text": {
    ;                 "value": "Please ensure I have tea in my room"
    ;               },
    ;               "commentTitle": "General Notes",
    ;               "notificationLocation": "RESERVATION",
    ;               "type": "GEN",
    ;               "internal": false
    ;             }
    ;           }
    ;         ],
    ;         "hotelId": "{{HotelId}}",
    ;         "roomStayReservation": true,
    ;         "reservationStatus": "Reserved",
    ;         "computedReservationStatus": "DueIn",
    ;         "walkIn": false,
    ;         "printRate": false,
    ;         "preRegistered": false,
    ;         "upgradeEligible": false,
    ;         "allowAutoCheckin": false,
    ;         "hasOpenFolio": false,
    ;         "allowMobileCheckout": false,
    ;         "allowMobileViewFolio": false,
    ;         "allowPreRegistration": false,
    ;         "optedForCommunication": false
    ;       }
    ;     ]
    ;   }
    ; }

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].sourceOfSale.sourceType","PMS")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].sourceOfSale.sourceCode","{{HotelId}}")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.roomRates[0].total.amountBeforeTax","200")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.roomRates[0].rates.rate[0].base.amountBeforeTax","200")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.roomRates[0].rates.rate[0].base.currencyCode","USD")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.roomRates[0].rates.rate[0].shareDistributionInstruction","Full")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.roomRates[0].rates.rate[0].total.amountBeforeTax","200")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.roomRates[0].rates.rate[0].start","{{currentdate}}")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.roomRates[0].rates.rate[0].end","{{currentdateplus1}}")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.roomRates[0].guestCounts.adults","1")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.roomRates[0].guestCounts.children","0")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.roomRates[0].roomType","{{RoomTypeCode}}")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.roomRates[0].ratePlanCode","{{RatePlanCode}}")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.roomRates[0].start","{{currentdate}}")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.roomRates[0].end","{{currentdateplus1}}")
    CkJsonObject::ckUpdateBool(json,"reservations.reservation[0].roomStay.roomRates[0].suppressRate",1)
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.roomRates[0].marketCode","LEISURE")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.roomRates[0].marketCodeDescription","Leisure")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.roomRates[0].sourceCode","PHONE")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.roomRates[0].sourceCodeDescription","Over the Phone")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.roomRates[0].numberOfUnits","1")
    CkJsonObject::ckUpdateBool(json,"reservations.reservation[0].roomStay.roomRates[0].pseudoRoom",0)
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.roomRates[0].roomTypeCharged","{{RoomTypeCode}}")
    CkJsonObject::ckUpdateBool(json,"reservations.reservation[0].roomStay.roomRates[0].houseUseOnly",0)
    CkJsonObject::ckUpdateBool(json,"reservations.reservation[0].roomStay.roomRates[0].complimentary",0)
    CkJsonObject::ckUpdateBool(json,"reservations.reservation[0].roomStay.roomRates[0].fixedRate",1)
    CkJsonObject::ckUpdateBool(json,"reservations.reservation[0].roomStay.roomRates[0].discountAllowed",0)
    CkJsonObject::ckUpdateBool(json,"reservations.reservation[0].roomStay.roomRates[0].bogoDiscount",0)
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.guestCounts.adults","1")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.guestCounts.children","0")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.arrivalDate","{{currentdate}}")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.departureDate","{{currentdateplus1}}")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.guarantee.guaranteeCode","6PM")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].roomStay.guarantee.shortDescription","6PM Hold")
    CkJsonObject::ckUpdateBool(json,"reservations.reservation[0].roomStay.roomNumberLocked",0)
    CkJsonObject::ckUpdateBool(json,"reservations.reservation[0].roomStay.printRate",0)
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].reservationGuests[0].profileInfo.profile.customer.personName[0].givenName","Jane")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].reservationGuests[0].profileInfo.profile.customer.personName[0].surname","Smith")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].reservationGuests[0].profileInfo.profile.customer.personName[0].nameType","Primary")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].reservationGuests[0].profileInfo.profile.customer.personName[1].nameType","External")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].reservationGuests[0].profileInfo.profile.customer.language","E")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].reservationGuests[0].profileInfo.profile.profileType","Guest")
    CkJsonObject::ckUpdateBool(json,"reservations.reservation[0].reservationGuests[0].primary",1)
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].reservationPaymentMethods[0].paymentMethod","CA")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].reservationPaymentMethods[0].folioView","1")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].comments[0].comment.text.value","Please ensure I have tea in my room")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].comments[0].comment.commentTitle","General Notes")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].comments[0].comment.notificationLocation","RESERVATION")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].comments[0].comment.type","GEN")
    CkJsonObject::ckUpdateBool(json,"reservations.reservation[0].comments[0].comment.internal",0)
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].hotelId","{{HotelId}}")
    CkJsonObject::ckUpdateBool(json,"reservations.reservation[0].roomStayReservation",1)
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].reservationStatus","Reserved")
    CkJsonObject::ckUpdateString(json,"reservations.reservation[0].computedReservationStatus","DueIn")
    CkJsonObject::ckUpdateBool(json,"reservations.reservation[0].walkIn",0)
    CkJsonObject::ckUpdateBool(json,"reservations.reservation[0].printRate",0)
    CkJsonObject::ckUpdateBool(json,"reservations.reservation[0].preRegistered",0)
    CkJsonObject::ckUpdateBool(json,"reservations.reservation[0].upgradeEligible",0)
    CkJsonObject::ckUpdateBool(json,"reservations.reservation[0].allowAutoCheckin",0)
    CkJsonObject::ckUpdateBool(json,"reservations.reservation[0].hasOpenFolio",0)
    CkJsonObject::ckUpdateBool(json,"reservations.reservation[0].allowMobileCheckout",0)
    CkJsonObject::ckUpdateBool(json,"reservations.reservation[0].allowMobileViewFolio",0)
    CkJsonObject::ckUpdateBool(json,"reservations.reservation[0].allowPreRegistration",0)
    CkJsonObject::ckUpdateBool(json,"reservations.reservation[0].optedForCommunication",0)

    CkHttp::ckSetRequestHeader(http,"Content-Type","application/json")
    CkHttp::ckSetRequestHeader(http,"x-hotelid","{{HotelId}}")
    ; Adds the "Authorization: Bearer <access_token>" header.
    CkHttp::setCkAuthToken(http, "<access_token>")
    CkHttp::ckSetRequestHeader(http,"x-app-key","{{AppKey}}")

    resp.i = CkHttp::ckPostJson3(http,"https://domain.com/rsv/v1/hotels/{{HotelId}}/reservations/","application/json",json)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(json)
        ProcedureReturn
    EndIf

    Debug Str(CkHttpResponse::ckStatusCode(resp))
    Debug CkHttpResponse::ckBodyStr(resp)
    CkHttpResponse::ckDispose(resp)



    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(json)


    ProcedureReturn
EndProcedure

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-H "x-hotelid: {{HotelId}}"
	-H "x-app-key: {{AppKey}}"
	-d '{
    "reservations": {
        "reservation": [
            {
                "sourceOfSale": {
                    "sourceType": "PMS",
                    "sourceCode": "{{HotelId}}"
                },
                "roomStay": {
                    "roomRates": [
                        {
                            "total": {
                                "amountBeforeTax": "200"
                            },
                            "rates": {
                                "rate": [
                                    {
                                        "base": {
                                            "amountBeforeTax": "200",
                                            "currencyCode": "USD"
                                        },
                                        "shareDistributionInstruction": "Full",
                                        "total": {
                                            "amountBeforeTax": "200"
                                        },
                                        "start": "{{currentdate}}",
                                        "end": "{{currentdateplus1}}"
                                    }
                                ]
                            },
                            "guestCounts": {
                                "adults": "1",
                                "children": "0"
                            },
                            "roomType": "{{RoomTypeCode}}",
                            "ratePlanCode": "{{RatePlanCode}}",
                            "start": "{{currentdate}}",
                            "end": "{{currentdateplus1}}",
                            "suppressRate": true,
                            "marketCode": "LEISURE",
                            "marketCodeDescription": "Leisure",
                            "sourceCode": "PHONE",
                            "sourceCodeDescription": "Over the Phone",
                            "numberOfUnits": "1",
                            "pseudoRoom": false,
                            "roomTypeCharged": "{{RoomTypeCode}}",
                            "houseUseOnly": false,
                            "complimentary": false,
                            "fixedRate": true,
                            "discountAllowed": false,
                            "bogoDiscount": false
                        }
                    ],
                    "guestCounts": {
                        "adults": "1",
                        "children": "0"
                    },
                    "arrivalDate": "{{currentdate}}",
                    "departureDate": "{{currentdateplus1}}",
                    "guarantee": {
                        "guaranteeCode": "6PM",
                        "shortDescription": "6PM Hold"
                    },
                    "roomNumberLocked": false,
                    "printRate": false
                },
                "reservationGuests": [
                    {
                        "profileInfo": {
                            "profile": {
                                "customer": {
                                    "personName": [
                                        {
                                            "givenName": "Jane",
                                            "surname": "Smith",
                                            "nameType": "Primary"
                                        },
                                        {
                                            "nameType": "External"
                                        }
                                    ],
                                    "language": "E"
                                },
                                "profileType": "Guest"
                            }
                        },
                        "primary": true
                    }
                ],
               "reservationPaymentMethods": [
                    {
                        "paymentMethod": "CA",
                        "folioView": "1"
                    }
                ],
                "comments": [
                    {
                        "comment": {
                            "text": {
                                "value": "Please ensure I have tea in my room"
                            },
                            "commentTitle": "General Notes",
                            "notificationLocation": "RESERVATION",
                            "type": "GEN",
                            "internal": false
                        }
                    }
                ],
                "hotelId": "{{HotelId}}",
                "roomStayReservation": true,
                "reservationStatus": "Reserved",
                "computedReservationStatus": "DueIn",
                "walkIn": false,
                "printRate": false,
                "preRegistered": false,
                "upgradeEligible": false,
                "allowAutoCheckin": false,
                "hasOpenFolio": false,
                "allowMobileCheckout": false,
                "allowMobileViewFolio": false,
                "allowPreRegistration": false,
                "optedForCommunication": false
            }
        ]
    }
}'
https://domain.com/rsv/v1/hotels/{{HotelId}}/reservations/

Postman Collection Item JSON

{
  "name": "Create a new reservation",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "var data = pm.response.headers.get(\"Location\").split(\"/\").pop();\r",
          "postman.setEnvironmentVariable(\"ReservationId\", data);"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{Token}}",
          "type": "string"
        }
      ]
    },
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "type": "text",
        "value": "application/json"
      },
      {
        "key": "x-hotelid",
        "type": "text",
        "value": "{{HotelId}}"
      },
      {
        "key": "x-app-key",
        "value": "{{AppKey}}",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\r\n    \"reservations\": {\r\n        \"reservation\": [\r\n            {\r\n                \"sourceOfSale\": {\r\n                    \"sourceType\": \"PMS\",\r\n                    \"sourceCode\": \"{{HotelId}}\"\r\n                },\r\n                \"roomStay\": {\r\n                    \"roomRates\": [\r\n                        {\r\n                            \"total\": {\r\n                                \"amountBeforeTax\": \"200\"\r\n                            },\r\n                            \"rates\": {\r\n                                \"rate\": [\r\n                                    {\r\n                                        \"base\": {\r\n                                            \"amountBeforeTax\": \"200\",\r\n                                            \"currencyCode\": \"USD\"\r\n                                        },\r\n                                        \"shareDistributionInstruction\": \"Full\",\r\n                                        \"total\": {\r\n                                            \"amountBeforeTax\": \"200\"\r\n                                        },\r\n                                        \"start\": \"{{currentdate}}\",\r\n                                        \"end\": \"{{currentdateplus1}}\"\r\n                                    }\r\n                                ]\r\n                            },\r\n                            \"guestCounts\": {\r\n                                \"adults\": \"1\",\r\n                                \"children\": \"0\"\r\n                            },\r\n                            \"roomType\": \"{{RoomTypeCode}}\",\r\n                            \"ratePlanCode\": \"{{RatePlanCode}}\",\r\n                            \"start\": \"{{currentdate}}\",\r\n                            \"end\": \"{{currentdateplus1}}\",\r\n                            \"suppressRate\": true,\r\n                            \"marketCode\": \"LEISURE\",\r\n                            \"marketCodeDescription\": \"Leisure\",\r\n                            \"sourceCode\": \"PHONE\",\r\n                            \"sourceCodeDescription\": \"Over the Phone\",\r\n                            \"numberOfUnits\": \"1\",\r\n                            \"pseudoRoom\": false,\r\n                            \"roomTypeCharged\": \"{{RoomTypeCode}}\",\r\n                            \"houseUseOnly\": false,\r\n                            \"complimentary\": false,\r\n                            \"fixedRate\": true,\r\n                            \"discountAllowed\": false,\r\n                            \"bogoDiscount\": false\r\n                        }\r\n                    ],\r\n                    \"guestCounts\": {\r\n                        \"adults\": \"1\",\r\n                        \"children\": \"0\"\r\n                    },\r\n                    \"arrivalDate\": \"{{currentdate}}\",\r\n                    \"departureDate\": \"{{currentdateplus1}}\",\r\n                    \"guarantee\": {\r\n                        \"guaranteeCode\": \"6PM\",\r\n                        \"shortDescription\": \"6PM Hold\"\r\n                    },\r\n                    \"roomNumberLocked\": false,\r\n                    \"printRate\": false\r\n                },\r\n                \"reservationGuests\": [\r\n                    {\r\n                        \"profileInfo\": {\r\n                            \"profile\": {\r\n                                \"customer\": {\r\n                                    \"personName\": [\r\n                                        {\r\n                                            \"givenName\": \"Jane\",\r\n                                            \"surname\": \"Smith\",\r\n                                            \"nameType\": \"Primary\"\r\n                                        },\r\n                                        {\r\n                                            \"nameType\": \"External\"\r\n                                        }\r\n                                    ],\r\n                                    \"language\": \"E\"\r\n                                },\r\n                                \"profileType\": \"Guest\"\r\n                            }\r\n                        },\r\n                        \"primary\": true\r\n                    }\r\n                ],\r\n               \"reservationPaymentMethods\": [\r\n                    {\r\n                        \"paymentMethod\": \"CA\",\r\n                        \"folioView\": \"1\"\r\n                    }\r\n                ],\r\n                \"comments\": [\r\n                    {\r\n                        \"comment\": {\r\n                            \"text\": {\r\n                                \"value\": \"Please ensure I have tea in my room\"\r\n                            },\r\n                            \"commentTitle\": \"General Notes\",\r\n                            \"notificationLocation\": \"RESERVATION\",\r\n                            \"type\": \"GEN\",\r\n                            \"internal\": false\r\n                        }\r\n                    }\r\n                ],\r\n                \"hotelId\": \"{{HotelId}}\",\r\n                \"roomStayReservation\": true,\r\n                \"reservationStatus\": \"Reserved\",\r\n                \"computedReservationStatus\": \"DueIn\",\r\n                \"walkIn\": false,\r\n                \"printRate\": false,\r\n                \"preRegistered\": false,\r\n                \"upgradeEligible\": false,\r\n                \"allowAutoCheckin\": false,\r\n                \"hasOpenFolio\": false,\r\n                \"allowMobileCheckout\": false,\r\n                \"allowMobileViewFolio\": false,\r\n                \"allowPreRegistration\": false,\r\n                \"optedForCommunication\": false\r\n            }\r\n        ]\r\n    }\r\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{HostName}}/rsv/v1/hotels/{{HotelId}}/reservations/",
      "host": [
        "{{HostName}}"
      ],
      "path": [
        "rsv",
        "v1",
        "hotels",
        "{{HotelId}}",
        "reservations",
        ""
      ]
    }
  },
  "response": [
  ]
}