0

Bulk batch update companies

by
Published Oct 17, 2025

Batch updates multiple companies.

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Bulk batch update companies
7
 * Batch updates multiple companies.
8
 */
9
export async function main(
10
  auth: Kustomer,
11
  body: {
12
    id: string;
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
    socials?: {
27
      type: "twitter" | "facebook" | "instagram" | "linkedin" | "pinterest";
28
      userid?: string;
29
      username: string;
30
      url?: string;
31
      verified?: false | true;
32
    }[];
33
    urls?: { type?: "other" | "website" | "blog"; url: string }[];
34
    domains?: { domain: string }[];
35
    locations?: {
36
      type?: "home" | "work" | "other";
37
      name?: string;
38
      address?: string;
39
      address2?: string;
40
      address3?: string;
41
      latitude?: number;
42
      longitude?: number;
43
      countryCode?: string;
44
      countryName?: string;
45
      regionCode?: string;
46
      regionName?: string;
47
      cityName?: string;
48
      zipCode?: string;
49
      areaCode?: string;
50
    }[];
51
    employeeCount?: number;
52
    tags?: string[];
53
    custom?: {};
54
    defaultLang?: string;
55
    deleted?: false | true;
56
  }[],
57
) {
58
  const url = new URL(`https://api.kustomerapp.com/v1/companies/bulk`);
59

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