-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathklaviyo.js
42 lines (37 loc) · 1.12 KB
/
klaviyo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
export async function signUp(data) {
const url = 'https://a.klaviyo.com/api/v2/list/PuccGZ/subscribe?api_key=pk_a6470fad0ade3d42ee3db8023d4ecd5db0';
const options = {
method: 'POST',
headers: {Accept: 'application/json', 'Content-Type': 'application/json'},
body: JSON.stringify({
profiles: [
{email: data}
]
})
};
try {
const data = await fetch(url, options).then((response) =>
response.json(),
);
return data;
} catch (error) {
throw new Error("Could not fetch klavio!");
}
}
export async function sendBackInStock(email,varId) {
console.log(email)
const url = 'https://a.klaviyo.com/api/v1/catalog/subscribe';
const options = {
method: 'POST',
headers: {'Content-Type':'application/x-www-form-urlencoded'},
body:`a=PtsWTL&email=${email}&variant=${varId}&platform=shopify`
};
try {
const data = await fetch(url, options).then((response) =>
response.json(),
);
return data;
} catch (error) {
throw new Error("Could not fetch klavio!");
}
}