#Authentication
Programs authenticate with API keys. People sign in to the panel with an emailed link or a password, and get a session; the panel uses a session the way you use a key.
#API keys
Send the key in the Authorization header of every request:
Authorization: Bearer cm_prod_ab12cd34_0123456789abcdef0123456789abcdefA key looks like cm_<env>_<prefix>_<secret>. env is prod, test or dev (the environment that made it). The 8-character prefix is public: it is how you recognise a key in a list. The 32-character secret is shown once, when the key is made. Antero Connect stores only a hash, so a lost key cannot be recovered; make a new one and revoke the old.
| Who | May |
|---|---|
| A person signed in as owner or admin | create, list and revoke keys (panel: Settings › Developers, or the API with a session) |
| A key | never create, list or revoke keys: a key that could make keys could widen itself |
A key can carry only permissions the person who made it has. A key stops working the moment it is revoked.
#Scopes
A key carries scopes: the things it may do. write:x does not include read:x; ask for both if you need both. A call outside the key's scopes is 403 forbidden_scope.
| Scope | Allows |
|---|---|
read:catalog | read properties, room types, rate plans, and the booking page settings |
write:catalog | create and change them |
read:ari | read availability, rates, restrictions, the calendar, explain |
write:ari | push availability, rates and restrictions |
read:reservations | read bookings and the reservation feed |
read:reservations.personal | also see the guest of a booking (name, email, phone, country). Without it the guest field is absent. |
write:reservations | make, change and cancel bookings, report the hotel system's own bookings, move a booking, send a guest confirmation |
read:channels / write:channels | channel connections: look, and create, change, map, switch on and off |
read:sync | the state of what was sent to each channel |
read:webhooks / write:webhooks | receivers of signed webhooks to you, and their deliveries |
read:decisions / write:decisions | the board of things that need a person, and settling them |
read:closures / write:closures | close room types at channels, and read what was closed |
write:holds | release rooms held for your hotel software by hand (a key must ask for it; owners and admins have it) |
Give a key the least it needs. A reporting tool needs read:reservations; a hotel system needs read:ari, write:ari, read:reservations, read:reservations.personal and write:reservations.
#Limiting a key to some properties
A key is tied to some properties (property_ids) or to all of them (all_properties: true); a request that says neither is refused, so a slip never makes the widest key. For every other property it behaves as if the property did not exist: 404 not_found, never 403. That means nobody can learn which ids exist.
#See what a key may do
export CHANNEL_MANAGER=https://api.anteromas.com # the address of your Channel Manager service
export KEY=cm_prod_ab12cd34_0123456789abcdef0123456789abcdef # your API key
curl -s -X GET "$CHANNEL_MANAGER/v1/whoami" \
-H "Authorization: Bearer $KEY"import os
import requests
CHANNEL_MANAGER = os.environ["CHANNEL_MANAGER"] # the address of your Channel Manager service
KEY = os.environ["KEY"] # your API key
r = requests.get(
f"{CHANNEL_MANAGER}/v1/whoami",
headers={"Authorization": f"Bearer {KEY}"},
)
r.raise_for_status()
print(r.status_code, r.text)// Node.js 18 or newer (fetch is built in); save as a .mjs file
const CHANNEL_MANAGER = process.env.CHANNEL_MANAGER; // the address of your Channel Manager service
const KEY = process.env.KEY; // your API key
let r; // the last answer
r = await fetch(`${CHANNEL_MANAGER}/v1/whoami`, {
method: "GET",
headers: { Authorization: `Bearer ${KEY}` },
});
if (!r.ok) throw new Error(await r.text());
console.log(r.status, await r.text());<?php
$CHANNEL_MANAGER = getenv("CHANNEL_MANAGER"); // the address of your Channel Manager service
$KEY = getenv("KEY"); // your API key
$ch = curl_init("{$CHANNEL_MANAGER}/v1/whoami");
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer {$KEY}"],
]);
$out = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status >= 400) { throw new RuntimeException($out); }
echo $status, " ", $out, "\n";If a later call says 403 forbidden_scope, compare it with scopes here.
#Keep keys safe
- Keep a key on a server. Never put it in a web page, a mobile app, or a repository.
- Use one key for each system, named for it, so you can revoke one without breaking another.
- Rotate by making the new key, switching the system over, then revoking the old key.
- Every key use is recorded;
last_used_atin the key list shows a key nobody uses, which is one to revoke. - If a key may have leaked, revoke it now. It stops working at once.
#People: sign-in and sessions
These endpoints are for the panel and for tools that act for a person. Programs use keys.
| Step | Endpoint | |
|---|---|---|
| 1 | POST /v1/auth/magic-link | emails a sign-in link (valid 15 minutes). The answer is the same whether or not the address has an account. |
| 2 | POST /v1/auth/verify | exchanges the link's token for a session, or POST /v1/auth/password/login with a password |
| 3 | POST /v1/auth/organization | chooses the organization when the person belongs to several |
POST /v1/auth/logout | ends the session at once |
A session token is used like a key (Authorization: Bearer kses_…), has the person's role instead of scopes, and ends after a time without use. Sign-in attempts are limited per address and per email (see Limits).
#The booking page needs no key
The guest-facing calls of the booking engine (/book-api/{slug}) are public on purpose: a guest has no key. They are held to limits per address instead, and they can only do what a guest may do.