Make your first call
Developer·4 minutes to read
What this does for you
You go from no credential to one authenticated request and the answer it returns.
Before you start
- A Botseon account. On your own you are your personal organisation's owner, so you create every kind of key. In a team, any member who is not a guest creates
ReadandRead and writekeys that act as them, with nobody to ask — unless an administrator has limited key creation to administrators. AnAdminkey and an organisation key are an administrator's, and a guest creates none (Authentication and keys). - The API keys page in the app: Settings → API keys (
/settings/api-keys). On a team it is also in the organisation nav, as API keys. It is where a key is created. - The address your install answers on. The samples below read it from
BOTSEON_API_URL— the same variable the SDKs read — and the key fromBOTSEON_API_KEY; a page never prints the value of either. - A terminal, or Node with
@botseon/sdkinstalled (The TypeScript SDK and headless mode).
Steps
These steps are followed at a terminal and on the API keys page; the API itself has no screen of its own, so no screenshot is shown here.
- Open Settings → API keys. If the page says only administrators can create keys, ask an administrator to make one for you or to lift that restriction.
- Give the key a Name of 1 to 60 characters, choose a Scope, and choose when it Expires. The scope is
Read,Read and writeorAdmin(offered to administrators only), andReadis the default; the expiry is 7, 30, 90, 180 or 365 days, and 90 days is the default. An administrator on a team also chooses the Owner:Me, orOrganisationfor a key that keeps working when its maker leaves. - Press Create key. The full key is shown once, under Copy your key now. Copy it, then press Done.
- Put the key in your shell's environment under
BOTSEON_API_KEY, and your install's address underBOTSEON_API_URL. Do not pass a key on a command line: a command line is visible to every process and every log. - Send one read request. The answer is a JSON body with
dataandnextCursor, and the response carries anx-request-idheader you can quote in a support request. - When you are finished with the key, press Revoke on its row in the Keys list on the same page. A revoked key is refused on the next request.
A worked example
List the bots your key's person can see:
curl -sS "$BOTSEON_API_URL/api/v1/bots?limit=5" \
-H "authorization: Bearer $BOTSEON_API_KEY" \
-H "accept: application/json"
The same call from Node, reading the two variables from the environment:
const res = await fetch(`${process.env.BOTSEON_API_URL}/api/v1/bots?limit=5`, {
headers: {
authorization: `Bearer ${process.env.BOTSEON_API_KEY}`,
accept: 'application/json',
},
});
if (!res.ok) throw new Error(`bots: ${res.status}`);
const page = (await res.json()) as { data: Array<{ id: string; name: string }>; nextCursor: string | null };
for (const bot of page.data) console.log(bot.id, bot.name);
What can go wrong
The first cell is the code the error envelope carries; the sentence beside it in error.message is fixed and nothing interpolates into it.
| What you see | Why | What to do |
|---|---|---|
unauthenticated | No key, a malformed bearer, an unknown, revoked or expired key, a key used on a route its class does not reach, a scope too narrow for the route, a key whose creator is no longer a member or is a guest, or an admin key whose creator is no longer an administrator. | Check the header spelling, then the key's row on Settings → API keys. A scope mismatch answers the same way as no credential on purpose, so a probe learns nothing. |
not_found | The row is not there, or it is there and your key's person may not read it. | Read the id from a list call rather than guessing it. A bot another member owns and has not shared reads the same way here as in the app. |
invalid_request | The body failed the schema, or a required header is missing. | Read details, which carries the failing paths and their messages. It never carries a value you sent. |
payment_required | The organisation needs a trial or a payment before this write. | Settle the account in the app, then retry. |
rate_limited | A bucket is full. | Wait the number of seconds in Retry-After and retry. |
See also
Last verified against build c0f77aa.