Chilkat Online Tools

PureBasic / ORACLE Hospitality OPERA Cloud REST API Workflows / Search hotel availability

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

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

    CkJsonObject::ckUpdateString(queryParams,"roomStayStartDate","{{currentdate}}")
    CkJsonObject::ckUpdateString(queryParams,"roomStayEndDate","{{currentdateplus1}}")
    CkJsonObject::ckUpdateInt(queryParams,"roomStayQuantity",2)
    CkJsonObject::ckUpdateInt(queryParams,"adults",1)
    CkJsonObject::ckUpdateInt(queryParams,"children",0)
    CkJsonObject::ckUpdateInt(queryParams,"limit",5)

    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::ckQuickRequestParams(http,"GET","https://domain.com/par/v0/hotels/{{HotelId}}/availability",queryParams)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(queryParams)
        ProcedureReturn
    EndIf

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



    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(queryParams)


    ProcedureReturn
EndProcedure

Curl Command

curl -G -d "roomStayStartDate=%7B%7Bcurrentdate%7D%7D"
	-d "roomStayEndDate=%7B%7Bcurrentdateplus1%7D%7D"
	-d "roomStayQuantity=2"
	-d "adults=1"
	-d "children=0"
	-d "limit=5"
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-H "x-hotelid: {{HotelId}}"
	-H "x-app-key: {{AppKey}}"
https://domain.com/par/v0/hotels/{{HotelId}}/availability

Postman Collection Item JSON

{
  "name": "Search hotel availability",
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    }
  ],
  "protocolProfileBehavior": {
    "disableBodyPruning": true
  },
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{Token}}",
          "type": "string"
        }
      ]
    },
    "method": "GET",
    "header": [
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "value": "application/json",
        "type": "text"
      },
      {
        "key": "x-hotelid",
        "value": "{{HotelId}}",
        "type": "text"
      },
      {
        "key": "x-app-key",
        "value": "{{AppKey}}",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{HostName}}/par/v0/hotels/{{HotelId}}/availability?roomStayStartDate={{currentdate}}&roomStayEndDate={{currentdateplus1}}&roomStayQuantity=2&adults=1&children=0&limit=5",
      "host": [
        "{{HostName}}"
      ],
      "path": [
        "par",
        "v0",
        "hotels",
        "{{HotelId}}",
        "availability"
      ],
      "query": [
        {
          "key": "roomStayStartDate",
          "value": "{{currentdate}}"
        },
        {
          "key": "roomStayEndDate",
          "value": "{{currentdateplus1}}"
        },
        {
          "key": "roomStayQuantity",
          "value": "2"
        },
        {
          "key": "adults",
          "value": "1"
        },
        {
          "key": "children",
          "value": "0"
        },
        {
          "key": "limit",
          "value": "5"
        },
        {
          "key": "childAge",
          "value": "",
          "disabled": true
        },
        {
          "key": "ratePlanCode",
          "value": "{{RatePlanCode}}",
          "description": "optional",
          "disabled": true
        },
        {
          "key": "roomType",
          "value": "DBL",
          "disabled": true
        },
        {
          "key": "includeClosedRates",
          "value": "",
          "disabled": true
        },
        {
          "key": "includeDefaultRatePlanSet",
          "value": "",
          "disabled": true
        },
        {
          "key": "initialRatePlanSet",
          "value": "",
          "disabled": true
        },
        {
          "key": "ratePlanSet",
          "value": "",
          "disabled": true
        },
        {
          "key": "pagePointerKey",
          "value": "",
          "disabled": true
        },
        {
          "key": "bucket1Count",
          "value": "",
          "disabled": true
        },
        {
          "key": "bucket2Count",
          "value": "",
          "disabled": true
        },
        {
          "key": "bucket3Count",
          "value": "",
          "disabled": true
        },
        {
          "key": "bucket4Count",
          "value": "",
          "disabled": true
        },
        {
          "key": "bucket5Count",
          "value": "",
          "disabled": true
        },
        {
          "key": "fullStayTimeSpanStartDate",
          "value": "",
          "disabled": true
        },
        {
          "key": "fullStayTimeSpanEndDate",
          "value": "",
          "disabled": true
        },
        {
          "key": "prevailingRate",
          "value": "",
          "disabled": true
        },
        {
          "key": "rateCategory",
          "value": "",
          "disabled": true
        },
        {
          "key": "rateClass",
          "value": "",
          "disabled": true
        },
        {
          "key": "rateGroup",
          "value": "",
          "disabled": true
        },
        {
          "key": "feature",
          "value": "",
          "disabled": true
        },
        {
          "key": "reservationGuestId",
          "value": "",
          "disabled": true
        },
        {
          "key": "reservationGuestIdType",
          "value": "",
          "disabled": true
        },
        {
          "key": "hotelReservationId",
          "value": "",
          "disabled": true
        },
        {
          "key": "hotelReservationIdType",
          "value": "",
          "disabled": true
        },
        {
          "key": "ratePlanInfo",
          "value": "",
          "disabled": true
        },
        {
          "key": "returnOnlyAvailableRateCodes",
          "value": "",
          "disabled": true
        },
        {
          "key": "resGuaranteeInfo",
          "value": "",
          "disabled": true
        },
        {
          "key": "roomTypeInfo",
          "value": "",
          "disabled": true
        },
        {
          "key": "membershipIdNumber",
          "value": "",
          "disabled": true
        },
        {
          "key": "smokingPreference",
          "value": "",
          "disabled": true
        }
      ]
    }
  },
  "response": [
  ]
}