Chilkat Online Tools

unicodeC / ORACLE Hospitality OPERA Cloud REST API Workflows / 03. Booking - getHotelAvailability

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW queryParams;
    HCkHttpResponseW resp;

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

    http = CkHttpW_Create();

    queryParams = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(queryParams,L"roomStayStartDate",L"{{currentdate}}");
    CkJsonObjectW_UpdateString(queryParams,L"roomStayEndDate",L"{{currentdateplus1}}");
    CkJsonObjectW_UpdateInt(queryParams,L"adults",1);
    CkJsonObjectW_UpdateInt(queryParams,L"children",0);
    CkJsonObjectW_UpdateInt(queryParams,L"roomStayQuantity",1);
    CkJsonObjectW_UpdateInt(queryParams,L"limit",10);
    CkJsonObjectW_UpdateString(queryParams,L"ratePlanCode",L"{{RatePlanCode}}");

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

    resp = CkHttpW_QuickRequestParams(http,L"GET",L"https://domain.com/par/v0/hotels/{{HotelId}}/availability",queryParams);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(queryParams);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(queryParams);

    }

Curl Command

curl -G -d "roomStayStartDate=%7B%7Bcurrentdate%7D%7D"
	-d "roomStayEndDate=%7B%7Bcurrentdateplus1%7D%7D"
	-d "adults=1"
	-d "children=0"
	-d "roomStayQuantity=1"
	-d "limit=10"
	-d "ratePlanCode=%7B%7BRatePlanCode%7D%7D"
	-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": "03. Booking - getHotelAvailability",
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "exec": [
          "var moment = require('moment');\r",
          "pm.environment.set('currentdate', moment().format((\"YYYY-MM-DD\")));\r",
          "\r",
          "var moment = require('moment');\r",
          "pm.environment.set('currentdateplus1', moment().add(1,'days').format((\"YYYY-MM-DD\")));"
        ],
        "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",
        "type": "text",
        "value": "application/json"
      },
      {
        "key": "x-hotelid",
        "type": "text",
        "value": "{{HotelId}}"
      },
      {
        "key": "x-app-key",
        "type": "text",
        "value": "{{AppKey}}"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{HostName}}/par/v0/hotels/{{HotelId}}/availability?roomStayStartDate={{currentdate}}&roomStayEndDate={{currentdateplus1}}&adults=1&children=0&roomStayQuantity=1&limit=10&ratePlanCode={{RatePlanCode}}",
      "host": [
        "{{HostName}}"
      ],
      "path": [
        "par",
        "v0",
        "hotels",
        "{{HotelId}}",
        "availability"
      ],
      "query": [
        {
          "key": "roomStayStartDate",
          "value": "{{currentdate}}"
        },
        {
          "key": "roomStayEndDate",
          "value": "{{currentdateplus1}}"
        },
        {
          "key": "adults",
          "value": "1"
        },
        {
          "key": "children",
          "value": "0"
        },
        {
          "key": "roomStayQuantity",
          "value": "1"
        },
        {
          "key": "limit",
          "value": "10"
        },
        {
          "key": "ratePlanCode",
          "value": "{{RatePlanCode}}"
        }
      ]
    }
  },
  "response": [
  ]
}