OpenBooking
Search…
Reference
For the convenience to our API consumers, we offer a JavaScript SDK, which enables you to set-up your custom UI quickly and connect to our real-time Socket.IO-based Pusher channel to speed up Query runtime.

Overview

1. Integrate the SDK in your website

Production Version:
1
<script src="<https://api.openbooking.ch/js/ob.min.js>"></script>
Copied!
Development Version:
1
<script src="<https://api.openbooking.ch/js/ob.dev.js>"></script>
Copied!

2. Instantiate an instance of OBManager

OBManager is the main object to communicate with the OpenBooking API client-side.
1
<script>
2
var ob = new OBManager("<https://api.openbooking.ch>", "[PUT YOUR TOKEN HERE]");
3
</script>
Copied!

Method Reference

Getting accommodation core data

setAcceptLanguage()...

countAccommodations()

Returns the number of available accommodation objects (core data) using the provided filter.
1
var filter = {
2
type: "hotel"
3
}
4
5
obManager.countAccommodations(filter: Object, cb: function(err, val))
Copied!
The filter is an Object containing filter parameters, for example { type: "apartment" } will return just the accommodations that match that criteria.
Filter Parameters: see "parameter" table below.
cb: Will be called with the results.

getAccommodations()

Fetch accommodation core objects based on an optional filter.
1
ob.getAccommodations(filter:Object, skip:Integer, limit:Integer, cb:Function(err, val))
Copied!
The filter is an Object containing filter parameters, for example { type: "apartment" } will return just the accommodations that match that criteria.
Filter Parameters: see "parameter" table below.
skip is to skip some items, if empty it will default to 0.
limit is to set the limit of the accommodations retrieved, defaults to 100.
cb will be called everytime we get accommodations, example of a cb function(err, accommodations)
1
var filter = {visible:true, features:"restaurant", ...};
2
ob.getAccommodations(filter, 10, 0, function(err, data) {
3
console.log(err);
4
console.log(data);
5
})
Copied!

getAllAccommodations()

If you need to get all the accommodations, instead of using the 2 above functions you can use this one. Will return you all the accommodations, 100 at the time, means tha cb will be called many times.
1
obManager.getAllAccommodations(filter:Object, cb:Function(err, val))
Copied!

getAccommodation()

Get a single accommodation by ID.
1
obManager.getAccommodation(id:String, cb:Function)
Copied!

Running availability queries

We offer a new way to transparently "Get accommodations" with or without availabilities with a generic response format. See getItems() below.

makeQuery()

The main feature of Openbooking is making queries. When a query is issued we will contact the Booking Engines and return the data to you.
1
obManager.makeQuery(query:Object, [options:Object], cb:Function(err, data:Array, requestid:String))
Copied!
With the options parameter, which is NOT mandatory, you can pass an object with the following fields:
  • finish a callback which is called when the Query is fully executed
  • finishProvider a finish callback for every single booking provider
  • filter a filter object, see below
  • tracktag a short string used to distinguish different queries from another. Max length 30 characters, no whitespace. Tracktags beginning with underscore are reserved for internal use.
When making a query, see example below, you will get, through the cb, the availabilities that you receive and the library stores it in a DataManager which are easily querable for you afterwards. Basicaly when a result comes you can add it to your page via jQuery or you can just load the data again from the DataManager included in the library, so you can filter and sort the data directly.
Example of a query:
1
{
2
"checkin": "2015-07-12T00:00:00.000",
3
"checkout": "2015-07-14T00:00:00.000",
4
"rooms": [{"adults": "2","children": 0}],
5
"language": "de",
6
"currency": "CHF"
7
}
Copied!
Filtering:
You can pass a filter parameter with an object with the following fields:
  • type: can be a type or all. Currently the following types are supported: hotel, appartment, offer
  • reference_id: pass an accommodationId here to get results only for a single accommodation
1
// makeQuery returns a requestid which is also passed to the callbacks
2
// Example:
3
4
var my_app_state = {};
5
var ob = new OBManager('https://api.openbooking.ch', token);
6
7
ob.finishedProviderCB = function(data) {
8
if(data.requestid == my_app_state.last_requestid) {
9
...
10
}
11
};
12
ob.finishedCB = function(data) {
13
if(data.requestid == my_app_state.last_requestid) {
14
...
15
}
16
};
17
18
var resultCB = function (err, data, requestid) {
19
if(requestid == my_app_state.last_requestid) {
20
...
21
}
22
};
23
24
var hash_or_query = ...;
25
var options = {tracktag: "mycustomtracktag"};
26
my_app_state.last_requestid = ob.makeQuery(hash_or_query, options, resultCB);
Copied!

createQuery()

Use this call to create a query and get a Query ID back without acutally executing the query.

getQuery()

Get a Query by its hash.
1
obManager.getQuery(hash:String, cb:Function(err, value))
Copied!

getResultsByOriginPerAccommodationId()

When we get availabilities and we want to book a room, maybe, if we group our availabilities by accommodation, we want to show the accommodation and all its availabilities to do this you can use this method.
1
obManager.getResultsByOriginPerAccommodationId(origin:String, accommodationId:String, cb:Function)
Copied!
origin is the hash of the query
accommodationId is the accommodationId which you want to get the availabilities for
cb is the callback that returns the availabilities. Provide a Function with the following signature:
1
function (err, data) {
2
if (err) {
3
console.log("Something went wrong, most likely the query origin did not exist");
4
return
5
}
6
7
if (data && data.length > 0) {
8
data.forEach(
9
function(aResult){
10
// do something with the results
11
}
12
)}
13
} else {
14
// No results found
15
// Query is either too old or results are expired/not cached
16
}
17
}
Copied!

Doing both: get Accommodations and Availabilities in a single request

getItems( parameters, options ) -> Items

getItems() returns an instance of the Items objects, which allows you to easily paginate and sort.
Example:
1
var items = ob.getItems({
2
types: ["apartment"],
3
checkin: "",
4
checkout: "",
5
rooms: [{
6
adults: 2,
7
children: 0,
8
childrens_age: []
9
}]
10
}, {
11
tracktag: "",
12
pageSize: 15
13
}).sortBy("price")
Copied!
parameters can contain the following keys:
Parameter
Required?
Type
Example
types
yes
string[]
["apartment"]
language
yes
string
de
currency
yes
string
CHF
checkin
no
string
2020-10-30
checkout
no
string
2020-10-31
rooms
no
Room[]
TODO
facts_bedrooms
no
int
2
facts_maxadults
no
int
2
facts_type
no
string
visible
no
boolean
true
quality
no
int[]
2,3,4
places
no
string[]
place IDs
st_code
no
string
DEPRECATED
Use tag search in form of "stcode:123456"
classification
no
int[]
Only for apartments with STV classification
DEPRECATED
Use tag search in form of "stv:classification:1"
price_min
no
int
150
price_max
no
int
300
features
no
string[]
["feature1","feature2"]
accommodationid
no
string[]
["57a9e5033d53230c10227f26"]
exclude_accommodationid
no
string[]
["57a9e5033d53230c10227f26"]
provider_name
no
string
reka
position
no
float64[]
47.3825516,8.5280023 (lat/lng)
radius
no
int
in meters, use together with position
bbox
no
float64[]
46.451062,9.766425,46.594009,9.985023 (left upper lat/lng, right lower lat/lng)
fulltext
no
string
i.e. chalet mary
See Fulltext Query Syntax for all possibilities
tags
no
string[]
optionscan contain the follow keys:
Parameter
Type
Default
Description
pageSize
int
100
Max. 100
tracktag
string
resolve_features
boolean
false
resolve_places
boolean
false
lowest_price_only
boolean
false
One return the cheapest offer(result) per accommodation
additional_properties
boolean
false
Fetch additional fields:
'group', 'provider', 'street', 'phone', 'email', 'media', 'onDemand', "terms", "description_rate_code"
trackingurl
boolean
false

Items.sortBy( sortString ) -> Items

sortString can be one of the following values.
Default sort order is ascending. For descending sort order add prefix -
Sort type
Note
name
price
classification
apartments only
quality
facts_bedrooms
apartments only
facts_maxadults
apartments only
random
position
used together with position/radius filter. The order is always "nearest first", descending is not supported
contentscore
sort by content quality
Example:
1
.sortBy("-price")
Copied!

Items.page( pageIndex, cb ) -> promise

Items.nextPage( cb ) -> promise

Items.prevPage( cb ) -> promise

Items.reset()

Items.currentPage( cb ) -> promise

Items.pageCount( cb ) -> promise

Items.count( cb ) -> promise

Items Callback

Callback signature:
1
function(err, page) {}
Copied!
Page is an array of a "light" accommodation objects:
1
[{
2
"id": "",
3
"name": {},
4
"name_add": {},
5
"images": [],
6
"imagesServices": [],
7
"ranks": [],
8
"provider_name": "",
9
"features": [],
10
"quality": "",
11
"superior": true,
12
"position": {},
13
"visible":true,
14
"type":"apartment",
15
"city":"Nendaz",
16
"city_normalized":"",
17
"externals":[],
18
"hookData":{},
19
"price":{},
20
...
21
}, ...]
Copied!

Retrieve Availability calendar for a single accommodation

getAvailabilities(accommodationId, cb) -> promise

You can pass a callback cb or leave it undefined to get a promise as return value. Returns a calendar with Arrival days, available days and minimum stays in this format:
1
[{
2
accommodation: "57a9d0c58f28830d008c7302",
3
arrival: [161128,161129,161130,161201,161202,161203,161204,161205,161206,161207,161208,161209,161210,161211,161212,161213,161214,161215,161216,161217,161218,161219,161220,161221,161222,161223,161224,161231,170121,170211,170318,170325,170401,170415,170429],
4
free: [161128,161129,161130,161201,161202,161203,161204,161205,161206,161207,161208,161209,161210,161211,161212,161213,161214,161215,161216,161217,161218,161219,161220,161221,161222,161223,161224,161225,161226,161227,161228,161229,161230,161231,170101,170102,170103,170104,170105,170106,170121,170122,170123,170124,170125,170126,170127,170211,170212,170213,170214,170215,170216,170217,170318,170319,170320,170321,170322,170323,170324,170325,170326,170327,170328,170329,170330,170331,170401,170402,170403,170404,170405,170406,170407,170415,170416,170417,170418,170419,170420,170421,170429,170430],
5
minstay: [3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,7,7,7,7,7,7,7,7],
6
provider: "57a9d0b173de570c00977fee"
7
}, ...]
Copied!
  • The dates in arrival and free are integers in the format yymmdd
  • For each date in arrival there is a matching minstay element, denoting the number of minimum stay days for a particular arrival day
  • different providers can report different availability data
Example:
1
ob.getAvailabilities(id).then(function(availabilities) {
2
if(availabilities.length > 0) {
3
...
4
} else {
5
console.log("for accommodation '"+id+"' there is currently no availability data");
6
}
7
})
Copied!
Last modified 1yr ago