0

Request Profile Deletion

by
Published Apr 8, 2025

Request a deletion for the profiles corresponding to one of the following identifiers: `email`, `phone_number`, or `id`.

Script klaviyo Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Klaviyo = {
3
  apiKey: string;
4
};
5
/**
6
 * Request Profile Deletion
7
 * Request a deletion for the profiles corresponding to one of the following identifiers: `email`, `phone_number`, or `id`.
8
 */
9
export async function main(
10
  auth: Klaviyo,
11
  revision: string,
12
  body: {
13
    data: {
14
      type: "data-privacy-deletion-job";
15
      attributes: {
16
        profile: {
17
          data: {
18
            type: "profile";
19
            id?: string;
20
            attributes: { email?: string; phone_number?: string };
21
          };
22
        };
23
      };
24
    };
25
  },
26
) {
27
  const url = new URL(`https://a.klaviyo.com/api/data-privacy-deletion-jobs`);
28

29
  const response = await fetch(url, {
30
    method: "POST",
31
    headers: {
32
      revision: revision,
33
      "Accept": "application/vnd.api+json",
34
      "Content-Type": "application/vnd.api+json",
35
      Authorization: "Klaviyo-API-Key " + auth.apiKey,
36
    },
37
    body: JSON.stringify(body),
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45