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 easily in the API settings section of your Autohost account. Follow these steps:

  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.bundle.js"></script>

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

const AutohostSDK = window.AutohostSdk;

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

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({
apiToken: temporaryToken
});

To integrate SDK components into your application, use the component method with the component name, options, and target DOM element.

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 the latest version or a specific version, depending on your needs. The latest version is always available at:

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

For specific versions, you can refer to the versioned files. Each versioned file follows the format AutohostSDK.vX.bundle.js, where X denotes the version number. For example:

Version 1: <script src="https://sdk.autohost.ai/dist/AutohostSDK.v1.bundle.js"></script> ...and so on for subsequent versions.

Please note that with each new release, there may be breaking changes compared to previous versions. It's advisable to review the release notes before upgrading to a newer version.

NPM Versioning

For NPM users, version management is handled through the package manager. You can specify the desired version of the Autohost SDK in your package.json file or update it to the latest version using standard NPM commands.

Remember to check our release notes for detailed information about each version's changes and potential breaking changes.

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.