@qbtech/tmt-api-sdk
v1.0.0-alpha.4
Published
Software Development Kit for the Trust My Travel API.
Downloads
7
Readme
TMT API SDK for JavaScript
This is the server-side JavaScript SDK for the TMT API. The intention is that this provides a wrapper with a simplified interface for end users to interact with the TMT API. Currently only limited access to the bookings endpoint is supported.
Requirements
Installation
Install the package with:
npm install @qbtech/tmt-api-sdk
# or
yarn add @qbtech/tmt-api-sdk
Usage
The SDK needs to be configured with an API token and your site path. You will also need the ID of the channel you wish to create a booking in and the currency code for the base currency of that channel. The library exports an Enums
helper for the currency, country and language fields.
Example for when using CJS modules:
const TMT = require("@qbtech/tmt-api-sdk");
const Enums = require("@qbtech/tmt-api-sdk").Enums;
const tmtServerSdk = new TMT({
apiToken: "123|abcDEFg1Hfjk...",
sitePath: "path-of-site",
});
tmtServerSdk
.createBooking({
title: "Booking title",
firstname: "John",
surname: "Doe",
email: "[email protected]",
date: "2025-01-31",
total: 1000,
currencies: Enums.Currency.USD,
channels: 1234,
content: "Holiday for two in London",
pax: 2,
reference: "someinternalreference",
countries: Enums.Country.US,
})
.then((booking) => console.log(booking.id))
.catch((error) => console.error(error));
Or using ES modules and async
/await
:
import TMT, { Enums } from "@qbtech/tmt-api-sdk";
const tmtServerSdk = new TMT({
apiToken: "123|abcDEFg1Hfjk...",
sitePath: "path-of-site",
});
const booking = await tmtServerSdk.createBooking({
title: "Booking title",
firstname: "John",
surname: "Doe",
email: "[email protected]",
date: "2025-01-31",
total: 1000,
currencies: Enums.Currency.USD,
channels: 1234,
content: "Holiday for two in London",
pax: 2,
reference: "someinternalreference",
countries: Enums.Country.US,
});
console.log(booking.id);
You can also update an existing booking, or retrieve a booking using its id:
tmtServerSdk.updateBooking(id, { reference: "editedreference" });
tmtServerSdk.getBookingById(id);
Module support
We support both CommonJS modules and ECMAScript modules. Please see the node documentation for more context on how these module systems are utilized and how to correctly configure your project to use them. If using TypeScript, note that enabling esModuleInterop
could result in your project using an export not intended for your module system. This might work but should ideally not be used as this as is workaround and may result in unexpected behaviour.
Version support
The latest major version of the @qbtech/tmt-api-sdk
package introduces new features and addresses bugs. To access these enhancements and bug fixes, including those for security issues, it's advisable to upgrade from older versions. Although older major versions remain accessible, they won't receive further updates.
Note that this library was developed using Node v21 and is meant to be run server-side, in a Node environment, and not in a browser i.e. client-side. If you need support for a specific Node version, please contact support.
Development
Run all tests:
$ npm install
$ npm test