0

Bulk Import Profiles

by
Published Apr 8, 2025

Create a bulk profile import job to create or update a batch of profiles. Accepts up to 10,000 profiles per request. The maximum allowed payload size is 5MB. To learn more, see our [Bulk Profile Import API guide](https://developers.klaviyo.com/en/docs/use_klaviyos_bulk_profile_import_api).*Rate limits*:Burst: `10/s`Steady: `150/m` **Scopes:** `lists:write` `profiles:write`

Script klaviyo Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Klaviyo = {
3
  apiKey: string;
4
};
5
/**
6
 * Bulk Import Profiles
7
 * Create a bulk profile import job to create or update a batch of profiles.
8

9
Accepts up to 10,000 profiles per request. The maximum allowed payload size is 5MB.
10

11
To learn more, see our [Bulk Profile Import API guide](https://developers.klaviyo.com/en/docs/use_klaviyos_bulk_profile_import_api).*Rate limits*:Burst: `10/s`Steady: `150/m`
12

13
 */
14
export async function main(
15
  auth: Klaviyo,
16
  revision: string,
17
  body: {
18
    data: {
19
      type: "profile-bulk-import-job";
20
      attributes: {
21
        profiles: {
22
          data: {
23
            type: "profile";
24
            id?: string;
25
            attributes: {
26
              email?: string;
27
              phone_number?: string;
28
              external_id?: string;
29
              anonymous_id?: string;
30
              _kx?: string;
31
              first_name?: string;
32
              last_name?: string;
33
              organization?: string;
34
              locale?: string;
35
              title?: string;
36
              image?: string;
37
              location?: {
38
                address1?: string;
39
                address2?: string;
40
                city?: string;
41
                country?: string;
42
                latitude?: string | number;
43
                longitude?: string | number;
44
                region?: string;
45
                zip?: string;
46
                timezone?: string;
47
                ip?: string;
48
              };
49
              properties?: {};
50
            };
51
            meta?: {
52
              patch_properties?: {
53
                append?: {};
54
                unappend?: {};
55
                unset?: string | string[];
56
              };
57
            };
58
          }[];
59
        };
60
      };
61
      relationships?: { lists?: { data?: { type: "list"; id: string }[] } };
62
    };
63
  },
64
) {
65
  const url = new URL(`https://a.klaviyo.com/api/profile-bulk-import-jobs`);
66

67
  const response = await fetch(url, {
68
    method: "POST",
69
    headers: {
70
      revision: revision,
71
      "Accept": "application/vnd.api+json",
72
      "Content-Type": "application/vnd.api+json",
73
      Authorization: "Klaviyo-API-Key " + auth.apiKey,
74
    },
75
    body: JSON.stringify(body),
76
  });
77
  if (!response.ok) {
78
    const text = await response.text();
79
    throw new Error(`${response.status} ${text}`);
80
  }
81
  return await response.json();
82
}
83