0

Create Token

by
Published Oct 17, 2025

Logs in to an organization with domain, email, and password. #### NOTE > **Machine tokens** can be created within the settings section by an administrator for API, tracking, and hook access

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Create Token
7
 * Logs in to an organization with domain, email, and password.
8

9
#### NOTE
10
> **Machine tokens** can be created within the settings section by an administrator for API, tracking, and hook access
11
 */
12
export async function main(
13
  auth: Kustomer,
14
  body: {} & {
15
    domain?: string;
16
    email?: string;
17
    password?: string;
18
    singleAccessToken?: string;
19
    googleAuthToken?: string;
20
    samlAuthToken?: string;
21
    remember?: false | true;
22
  },
23
) {
24
  const url = new URL(`https://api.kustomerapp.com/v1/auth/tokens`);
25

26
  const response = await fetch(url, {
27
    method: "POST",
28
    headers: {
29
      "Content-Type": "application/json",
30
      Authorization: "Bearer " + auth.apiKey,
31
    },
32
    body: JSON.stringify(body),
33
  });
34
  if (!response.ok) {
35
    const text = await response.text();
36
    throw new Error(`${response.status} ${text}`);
37
  }
38
  return await response.json();
39
}
40