0

Create tracking identity

by
Published Oct 17, 2025

Identifies a user. The following role is required for this endpoint: org.tracking

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 tracking identity
7
 * Identifies a user.
8

9
The following role is required for this endpoint: org.tracking
10
 */
11
export async function main(
12
  auth: Kustomer,
13
  body: {
14
    remember?: false | true;
15
    trackingId?: string;
16
    sessionId?: string;
17
    name?: string;
18
    company?: string;
19
    externalId?: string;
20
    username?: string;
21
    signedUpAt?: string;
22
    birthdayAt?: string;
23
    gender?: "m" | "f";
24
    locale?: string;
25
    timeZone?: string;
26
    email?: string;
27
    phone?: string;
28
    location?: {
29
      type?: "home" | "work" | "other";
30
      name?: string;
31
      address?: string;
32
      address2?: string;
33
      address3?: string;
34
      latitude?: number;
35
      longitude?: number;
36
      countryCode?: string;
37
      countryName?: string;
38
      regionCode?: string;
39
      regionName?: string;
40
      cityName?: string;
41
      zipCode?: string;
42
      areaCode?: string;
43
    };
44
    tags?: string[];
45
    custom?: {};
46
  },
47
) {
48
  const url = new URL(`https://api.kustomerapp.com/v1/tracking/identity`);
49

50
  const response = await fetch(url, {
51
    method: "POST",
52
    headers: {
53
      "Content-Type": "application/json",
54
      Authorization: "Bearer " + auth.apiKey,
55
    },
56
    body: JSON.stringify(body),
57
  });
58
  if (!response.ok) {
59
    const text = await response.text();
60
    throw new Error(`${response.status} ${text}`);
61
  }
62
  return await response.json();
63
}
64