0

Bulk create customers

by
Published Oct 17, 2025

Creates customers in bulk. Any one of the following roles is required for this endpoint: |Legacy Role|Equivalent Permission Set Role| |-----|--------| |org.user.customer.write|org.permission.customer.create|

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 create customers
7
 * Creates customers in bulk.
8

9
Any one of the following roles is required for this endpoint:
10

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

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