Chilkat Online Tools

SQL Server / ORACLE Hospitality OPERA Cloud REST API Workflows / Get available packages

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
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    DECLARE @queryParams int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @queryParams OUT

    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'fetchInstructions', 'Header'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'fetchInstructions', 'Items'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'startDate', '2021-04-07'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'endDate', '2021-04-08'
    EXEC sp_OAMethod @queryParams, 'UpdateInt', @success OUT, 'children', 0
    EXEC sp_OAMethod @queryParams, 'UpdateInt', @success OUT, 'adults', 1
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'hotelId', '{{HotelId}}'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'packageCode', 'CHAMP'

    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, 'QuickRequestParams', @resp OUT, 'GET', 'https://domain.com/rtp/v0/packages', @queryParams
    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 @queryParams
        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 @queryParams


END
GO

Curl Command

curl -G -d "fetchInstructions=Header"
	-d "fetchInstructions=Items"
	-d "startDate=2021-04-07"
	-d "endDate=2021-04-08"
	-d "children=0"
	-d "adults=1"
	-d "hotelId=%7B%7BHotelId%7D%7D"
	-d "packageCode=CHAMP"
	-H "Authorization: Bearer <access_token>"
	-H "x-hotelid: {{HotelId}}"
	-H "x-app-key: {{AppKey}}"
https://domain.com/rtp/v0/packages

Postman Collection Item JSON

{
  "name": "Get available packages",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{Token}}",
          "type": "string"
        }
      ]
    },
    "method": "GET",
    "header": [
      {
        "key": "x-hotelid",
        "type": "text",
        "value": "{{HotelId}}"
      },
      {
        "key": "x-app-key",
        "value": "{{AppKey}}",
        "type": "text"
      }
    ],
    "url": {
      "raw": "{{HostName}}/rtp/v0/packages?fetchInstructions=Header&fetchInstructions=Items&startDate=2021-04-07&endDate=2021-04-08&children=0&adults=1&hotelId={{HotelId}}&packageCode=CHAMP",
      "host": [
        "{{HostName}}"
      ],
      "path": [
        "rtp",
        "v0",
        "packages"
      ],
      "query": [
        {
          "key": "includeGroup",
          "value": "true",
          "disabled": true
        },
        {
          "key": "sellSeparate",
          "value": "true",
          "disabled": true
        },
        {
          "key": "fetchInstructions",
          "value": "Header"
        },
        {
          "key": "fetchInstructions",
          "value": "CalculatedPrice",
          "disabled": true
        },
        {
          "key": "fetchInstructions",
          "value": "Items"
        },
        {
          "key": "startDate",
          "value": "2021-04-07"
        },
        {
          "key": "endDate",
          "value": "2021-04-08"
        },
        {
          "key": "children",
          "value": "0"
        },
        {
          "key": "adults",
          "value": "1"
        },
        {
          "key": "hotelId",
          "value": "{{HotelId}}"
        },
        {
          "key": "ticketPostingRhythm",
          "value": "false",
          "disabled": true
        },
        {
          "key": "packageCode",
          "value": "CHAMP"
        },
        {
          "key": "descriptionWildCard",
          "value": "",
          "disabled": true
        }
      ]
    }
  },
  "response": [
  ]
}