Skip to main content

Getting Started

Welcome to the Autohost SDK! This guide will help you quickly integrate our SDK into your projects, ensuring a seamless setup experience.

Creating an SDK Key

Before you start, you'll need an SDK key. Create your key in the API settings section of your Autohost account:

  1. Log in to Autohost Dashboard.
  2. Navigate to Settings > API.
  3. Select Create SDK Key.
  4. (Optional) Rename the key to an appropriate name for your control and organization.
  5. Copy the key and securely store it.

Installation

Via CDN

To use the Autohost SDK, include it in your project by importing it from our CDN:

<script src="https://sdk.autohost.ai/dist/AutohostSDK.v1.bundle.js"></script>

After including the SDK, access it through the window object in your JavaScript code:

const AutohostSDK = window.AutohostSDK;

Please check our Release Notes page for the full list of available versions.

Authorization and Authentication

In this section, we detail the process of securing your integration with the Autohost SDK. Proper authorization and authentication are crucial for maintaining the security and integrity of your data, as well as ensuring that access is correctly restricted to authorized users only.

Creating a Temporary Token

NOTE: this is only required to access Admin Components.

To access features and data available via the Autohost Dashboard, which are not publicly accessible, a temporary token is required.

This token ensures that users can access only the specific resources assigned to them, with the security of a limited access window. You will need to create a short-lived API token in your backend for this purpose. The token's validity is capped at 5 minutes, ensuring tight control over data access:

Here's how you can generate this token using the Autohost SDK:

type Filter = {
scope: string; // Access scope: read, write
level: string; // Access level: reservation, listing
id: string; // ID associated with ACL
};

type ACL = {
filters: Filter[];
};

const temporaryToken = AutohostSDK.createSecuredToken(
sdkToken: string, acl: ACL
);

Backend Token Generation

If your backend is not JavaScript-based, you can generate the token directly through our API:

curl -X POST "https://embed.autohost.ai/api/auth?token=YOUR_SDK_KEY" \
-H "Content-Type: application/json" \
-d '{
"filters": [
{
"scope": "read",
"level": "reservation",
"id": "YOUR_RESERVATION_ID"
}
]
}'

Remember to set Content-Type: application/json in your headers. The request payload should include the ACL object. The response will resemble:

{
"id": "acl_c7285287-****-****-****-************",
"createdAt": 1695675463,
"token": "c7285287-****-****-****-************",
"user": "AYbNJLNg************",
"validUntil": 1695675763,
"filters": [
{
"scope": "read",
"level": "reservation",
"id": "************mQreBE_e"
}
]
}

Initializing the Client

After obtaining your temporary token, initialize the client for the Autohost SDK:

const client = AutohostSDK.init();

To integrate SDK components into your application, use the component method with the component name, options, and target DOM element. You can provide any valid selector, such as a class, but we suggest using a unique ID.

client.component("COMPONENT_NAME", options).mount("#target");
<div id="target"></div>

Click here to check the available embeddable client components.

SDK Versioning

Our SDK is regularly updated to introduce new features, improve functionality, and enhance security. It's important to be aware of the versioning to ensure compatibility and take advantage of the latest improvements.

CDN Versioning

When integrating the SDK via CDN, you have the option to use a major version or an incremental version, depending on your needs. The major version is available at:

The major version file follows the format AutohostSDK.vX.bundle.js, and the incremental version is AutohostSDK.vX.Y.Z.bundle.js. For example:

To use the version 1:

<script src="https://sdk.autohost.ai/dist/AutohostSDK.v1.bundle.js"></script>

And to use the incremental version:

<script src="https://sdk.autohost.ai/dist/AutohostSDK.v1.1.0.bundle.js"></script>

Please check our Release Notes page for the full list of available versions.

NPM Versioning

Comming soon.

Getting Support

If you need help or have any questions while integrating the Autohost SDK, please feel free to contact our support team or visit our documentation for more detailed guides and API references.