Skip to content

Booking RQ (AT_WEB)

Vasilis Mavromatis edited this page Oct 30, 2017 · 4 revisions
from __future__ import print_function
import time
import hashlib
import json
import bookingapi
from bookingapi.rest import ApiException
from pprint import pprint

# Set version (1.0 for all operations except non-CC booking request which is 1.2)
version = '1.2'  # str | Default version for this operation

# Your API Key and secret
apiKey = "xxxxxxxxxxxxxxxxxxxxxxx"
Secret = "xxxxxxxxxxxxx"

# Signature is generated by SHA256 (Api-Key + Secret + Timestamp (in seconds))
sigStr = "%s%s%d" % (apiKey, Secret, int(time.time()))
signature = hashlib.sha256(sigStr).hexdigest()

# create an instance of the API class
api_instance = bookingapi.BookingsApi()
api_instance.api_client.set_default_header('api-key', apiKey)
api_instance.api_client.set_default_header('x-signature', signature)


try:
    # Hotel Booking Confirmation Request
    holder = bookingapi.ApiHolder(name="IntegrationTestFirstName", surname="IntegrationTestLastName")
    pax = bookingapi.ApiPax(room_id="1", type="AD", name="Adult Name")
    room = bookingapi.ApiBookingRoom(rate_key="20171114|20171119|W|235|163281|DBL.2Q|GC-PPAT1|AB||1~1~0||N@8A05AD64E97247C28156F727DC8A9B791128", paxes=[pax])
    bookingRQ = bookingapi.BookingRQ(holder=holder, rooms=[room], client_reference="IntegrationAgency")
    api_response = api_instance.booking(version, bookingRQ)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling StatusApi->status: %s\n" % e)    # print full exception
    print("API error message: %s" % json.loads(e.body)['error']['message'].rstrip("\n"))   # print API error message
    print("API error code: %s" % json.loads(e.body)['error']['code'].rstrip("\n"))   # print API error code
Clone this wiki locally