0

Update company attributes

by
Published Oct 17, 2025

Updates the attributes of a company based on the company ID.

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 company attributes
7
 * Updates the attributes of a company based on the company ID.
8
 */
9
export async function main(
10
  auth: Kustomer,
11
  id: string,
12
  body: {
13
    name?: string;
14
    externalId?: string;
15
    avatarUrl?: string;
16
    emails?: {
17
      type?: "home" | "work" | "other";
18
      email: string;
19
      verified?: false | true;
20
    }[];
21
    phones?: {
22
      type?: "home" | "work" | "other" | "mobile" | "fax";
23
      phone: string;
24
      verified?: false | true;
25
    }[];
26
    whatsapps?: { type?: "mobile"; phone: string; verified?: false | true }[];
27
    socials?: {
28
      type: "twitter" | "facebook" | "instagram" | "linkedin" | "pinterest";
29
      userid?: string;
30
      username: string;
31
      url?: string;
32
      verified?: false | true;
33
    }[];
34
    urls?: { type?: "other" | "website" | "blog"; url: string }[];
35
    domains?: { domain: string }[];
36
    locations?: {
37
      type?: "home" | "work" | "other";
38
      name?: string;
39
      address?: string;
40
      address2?: string;
41
      address3?: string;
42
      latitude?: number;
43
      longitude?: number;
44
      countryCode?: string;
45
      countryName?: string;
46
      regionCode?: string;
47
      regionName?: string;
48
      cityName?: string;
49
      zipCode?: string;
50
      areaCode?: string;
51
    }[];
52
    employeeCount?: number;
53
    tags?: string[];
54
    custom?: {};
55
    defaultLang?: string;
56
    rev?: number;
57
    deleted?: false | true;
58
  },
59
) {
60
  const url = new URL(`https://api.kustomerapp.com/v1/companies/${id}`);
61

62
  const response = await fetch(url, {
63
    method: "PUT",
64
    headers: {
65
      "Content-Type": "application/json",
66
      Authorization: "Bearer " + auth.apiKey,
67
    },
68
    body: JSON.stringify(body),
69
  });
70
  if (!response.ok) {
71
    const text = await response.text();
72
    throw new Error(`${response.status} ${text}`);
73
  }
74
  return await response.json();
75
}
76