0

Update customer attributes

by
Published Oct 17, 2025

Updates customer attributes.

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Update customer attributes
7
 * Updates customer attributes.
8
 */
9
export async function main(
10
  auth: Kustomer,
11
  id: string,
12
  body: {
13
    name?: string;
14
    company?: string;
15
    externalId?: string;
16
    username?: string;
17
    signedUpAt?: string;
18
    lastActivityAt?: string;
19
    lastCustomerActivityAt?: string;
20
    lastSeenAt?: string;
21
    avatarUrl?: string;
22
    externalIds?: { externalId: string; verified?: false | true }[];
23
    sharedExternalIds?: { externalId: string; verified?: false | true }[];
24
    emails?: {
25
      type?: "home" | "work" | "other";
26
      email: string;
27
      verified?: false | true;
28
    }[];
29
    sharedEmails?: {
30
      type?: "home" | "work" | "other";
31
      email: string;
32
      verified?: false | true;
33
    }[];
34
    phones?: {
35
      type?: "home" | "work" | "other" | "mobile" | "fax";
36
      phone: string;
37
      verified?: false | true;
38
    }[];
39
    sharedPhones?: {
40
      type?: "home" | "work" | "other" | "mobile" | "fax";
41
      phone: string;
42
      verified?: false | true;
43
    }[];
44
    whatsapps?: { type?: "mobile"; phone: string; verified?: false | true }[];
45
    facebookIds?: { pageId: string; userId: string; name?: string }[];
46
    instagramIds?: {
47
      pageId: string;
48
      threadId: string;
49
      username: string;
50
      instagramId?: string;
51
    }[];
52
    socials?: {
53
      type: "twitter" | "facebook" | "instagram" | "linkedin" | "pinterest";
54
      userid?: string;
55
      username: string;
56
      url?: string;
57
      verified?: false | true;
58
    }[];
59
    sharedSocials?: {
60
      type: "twitter" | "facebook" | "instagram" | "linkedin" | "pinterest";
61
      userid?: string;
62
      username: string;
63
      url?: string;
64
      verified?: false | true;
65
    }[];
66
    urls?: { type?: "other" | "website" | "blog"; url: string }[];
67
    locations?: {
68
      type?: "home" | "work" | "other";
69
      name?: string;
70
      address?: string;
71
      address2?: string;
72
      address3?: string;
73
      latitude?: number;
74
      longitude?: number;
75
      countryCode?: string;
76
      countryName?: string;
77
      regionCode?: string;
78
      regionName?: string;
79
      cityName?: string;
80
      zipCode?: string;
81
      areaCode?: string;
82
    }[];
83
    locale?: string;
84
    timeZone?: string;
85
    tags?: string[];
86
    sentiment?: { polarity: 0 | 1 | -1; confidence: number };
87
    custom?: {};
88
    birthdayAt?: string;
89
    gender?: "m" | "f";
90
    createdAt?: string;
91
    importedAt?: string;
92
    rev?: number;
93
    defaultLang?: string;
94
  },
95
) {
96
  const url = new URL(`https://api.kustomerapp.com/v1/customers/${id}`);
97

98
  const response = await fetch(url, {
99
    method: "PATCH",
100
    headers: {
101
      "Content-Type": "application/json",
102
      Authorization: "Bearer " + auth.apiKey,
103
    },
104
    body: JSON.stringify(body),
105
  });
106
  if (!response.ok) {
107
    const text = await response.text();
108
    throw new Error(`${response.status} ${text}`);
109
  }
110
  return await response.json();
111
}
112