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 tmt-api-sdk
yarn add tmt-api-sdk
Usage
The SDK needs to be configured with an API token and your site path. The library also exports an Enums
helper for the currency, country and language fields.
Example for when using CJS modules:
const TMT = require("tmt-api-sdk");
const Enums = require("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: "jd@somedomain.com",
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 "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: "jd@somedomain.com",
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 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.
Development
Run all tests:
$ npm install
$ npm test
Detailed development documentation here.