index

setBooking JSON


Instructions

Post JSON data here to create or modify a booking in a property.

See here for information about using the JSON API.

The JSON data is similar to that returned by getBookings.

If bookId is specified and exists the booking will be modified. If bookId is not set the booking will be added as a new booking.

If unitId is not set for a new booking, the booking will be auto assigned into an available unit of the specified roomId type.

It is not necessary to send unchanged fields when modifying a booking, it is better to only include the fields which have changed.

An array of up to 100 new bookings can be created using either the array or groupArray parameter. Only one of these can be specified at a time.

The groupArray parameter will create a group of linked bookings.

To create a group booking from existing bookings, identify the bookId value of the booking you wish to be the master of the group and set the masterId field of all the additional bookings in the group to this bookId value.

Bookings can be cancelled but not deleted by this function.

If guestCountry contains a country name and guestCountry2 is not used, the country code value for guestCountry2 will be deduced from the country name.

If you have a Stripe CustomerId for this booking and the Stripe account with the customer is connected to the property you can send the CustomerId with the stripeToken field. A Stripe customerId always starts with cus_ like cus_01234567890. The Stripe customer can then be charged using the chargeToStripe field.

Invoice Items

New invoice items can be added by not including an invoiceId. Invoice items can be deleted by setting the description, status, qty and price to an empty string in one operation. Charges should have a positive qty. Payments should have a negative qty (-1). The Quantity of the invoice item must be an integer. When creating a new invoice item, a special field "qtyDecimal" can be sent instead of qty and the qty value will be converted to an integer and the price adjusted to keep the total the same. If the description or status of the invoice item are set to a logical true value (value true without quotes), the property default values will be used.

Booking Info Items

Booking info items can be added by supplying the code and text or modified by including the infoItemId. To delete an info item, supply the infoItemId with the code and text both present as empty strings.

Actions

For new bookings it is possible to specify the following parameters:

The optional notifyUrl parameter can be used to disable the notify Url action.

For existing bookings the following parameters can be specified by including the bookId field.

Example Data

New Booking

{
    "authentication": {
        "apiKey": "apiKeyAsSetInAccountSettings",
        "propKey": "propKeyAsSetForTheProperty"
    },
    "roomId": "12345",
    "unitId": "1",
    "roomQty": "1",
    "status": "1",
    "firstNight": "2014-10-01",
    "lastNight": "2014-10-01",
    "numAdult": "2",
    "numChild": "0",
    "guestTitle": "Mr",
    "guestFirstName": "Joe",
    "guestName": "Smith",
    "guestEmail": "[email protected]",
    "guestPhone": "+123456789",
    "guestMobile": "09 87654321",
    "guestFax": "0123456",
    "guestAddress": "1 Big Street",
    "guestCity": "London",
    "guestPostcode": "EX 1234",
    "guestCountry": "United_Kingdom",
    "guestArrivalTime": "late, very late",
    "guestVoucher": "give me discount",
    "guestComments": "Non smoking please",
    "guestCardType": "VISA",
    "guestCardNumber": "0000000000000000",
    "guestCardName": "Mr Smith",
    "guestCardExpiry": "01\/17",
    "guestCardCVV": "000",
    "guestCardNote": "a note",
    "message": "text",
    "custom1": "text",
    "custom2": "text",
    "custom3": "text",
    "custom4": "text",
    "custom5": "text",
    "custom6": "text",
    "custom7": "text",
    "custom8": "text",
    "custom9": "text",
    "custom10": "text",
    "notes": "VIP",
    "flagColor": "ff0000",
    "flagText": "Show booking in red",
    "price": "100.00",
    "deposit": "10.00",
    "tax": "5.00",
    "commission": "15.00",
    "refererEditable": "online",
    "notifyUrl": "true",
    "notifyGuest": false,
    "notifyHost": false,
    "assignBooking": false,
    "checkAvailability": false,
    "deleteInvoice": false,
    "invoice": [
        {
            "description": "lodging",
            "status": "",
            "qty": "1",
            "price": "123.45",
            "vatRate": "10",
            "invoiceeId": ""
        }
    ],
    "infoItems": [
        {
            "code": "PAYMENT",
            "text": "Paid $100"
        }
    ]
}

Modify Booking

{
    "authentication": {
        "apiKey": "apiKeyAsSetInAccountSettings",
        "propKey": "propKeyAsSetForTheProperty"
    },
    "bookId": "12345678",
    "firstNight": "2014-09-30",
    "numAdult": "3",
    "invoice": [
        {
            "invoiceId": "123456789",
            "description": "deposit payment",
            "status": "",
            "qty": "-1",
            "price": "23.45",
            "vatRate": "10"
        }
    ],
    "infoItems": [
        {
            "infoItemId": "12345678",
            "code": "PAYMENT",
            "text": "Paid $200"
        }
    ]
}

Create a Group Booking

{
    "authentication": {
        "apiKey": "apiKeyAsSetInAccountSettings",
        "propKey": "propKeyAsSetForTheProperty"
    },
    "groupArray": [
        {
            "roomId": "123456",
            "firstNight": "2018-09-29",
            "lastNight": "2018-09-30",
            "numAdult": "3",
            "guestTitle": "Mr",
            "guestFirstName": "Joe",
            "guestName": "Smith",
            "guestEmail": "[email protected]"
        },
        {
            "roomId": "123457",
            "firstNight": "2018-09-30",
            "lastNight": "2018-09-30",
            "numAdult": "2",
            "guestTitle": "Mrs",
            "guestFirstName": "Jane",
            "guestName": "Jones",
            "guestEmail": "[email protected]"
        }
    ]
}

Multiple Bookings

{
    "authentication": {
        "apiKey": "apiKeyAsSetInAccountSettings",
        "propKey": "propKeyAsSetForTheProperty"
    },
    "array": [
        {
            "roomId": "123456",
            "masterId": "123455",
            "firstNight": "2018-09-29",
            "lastNight": "2018-09-30",
            "numAdult": "3",
            "guestTitle": "Mr",
            "guestFirstName": "Joe",
            "guestName": "Smith",
            "guestEmail": "[email protected]"
        },
        {
            "roomId": "123457",
            "masterId": "0",
            "firstNight": "2018-09-30",
            "lastNight": "2018-09-30",
            "numAdult": "2",
            "guestTitle": "Mrs",
            "guestFirstName": "Jane",
            "guestName": "Jones",
            "guestEmail": "[email protected]"
        }
    ]
}

Report Invalid Card to Booking.com

{
    "authentication": {
        "apiKey": "apiKeyAsSetInAccountSettings",
        "propKey": "propKeyAsSetForTheProperty"
    },
    "bookId": "12345678",
    "bookingcomInvalidCard": true
}

Report No Show to Booking.com

{
    "authentication": {
        "apiKey": "apiKeyAsSetInAccountSettings",
        "propKey": "propKeyAsSetForTheProperty"
    },
    "bookId": "12345678",
    "bookingcomNoShow": true
}

Report Cancellation Request to Booking.com

{
    "authentication": {
        "apiKey": "apiKeyAsSetInAccountSettings",
        "propKey": "propKeyAsSetForTheProperty"
    },
    "bookId": "12345678",
    "bookingcomReportCancel": true
}

Make a charge to Stripe

{
    "authentication": {
        "apiKey": "apiKeyAsSetInAccountSettings",
        "propKey": "propKeyAsSetForTheProperty"
    },
    "bookId": "12345678",
    "chargeToStripe": {
        "amount": 10,
        "description": "payment for booking",
        "capture": true
    }
}

Assign an invoice number to the booking

{
    "authentication": {
        "apiKey": "apiKeyAsSetInAccountSettings",
        "propKey": "propKeyAsSetForTheProperty"
    },
    "bookId": "12345678",
    "assignInvoiceNumber": true
}

Sample PHP code

<?php

/*
* The following sample uses a PHP array to construct the JSON data and php-curl to post it to the API.
* This sample will change the guestName of booking 12345678 to Jones
*/

$auth = array();
$auth['apiKey'] = 'apiKeyAsSetInAccountSettings';
$auth['propKey'] = 'propKeyAsSetForTheProperty';

$data = array();
$data['authentication'] = $auth;

$data['bookId'] = '12345678';
$data['guestName'] = 'Jones';

$json = json_encode($data);

$url = "http://soft.4twa.com/api/json/setBooking";

$ch=curl_init();
curl_setopt($ch, CURLOPT_POST, 1) ;
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = curl_exec($ch);
curl_close ($ch);
echo $result;	

?>