-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (33 loc) · 959 Bytes
/
index.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
/**
* Responds to any HTTP request.
*
* @param {!express:Request} req HTTP request context.
* @param {!express:Response} res HTTP response context.
*/
const axios = require("axios");
exports.klaviyo = (req, res) => {
res.header("Content-Type", "application/json");
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Content-Type");
let key = req.query.key || req.body.key;
let email = req.query.email || req.body.email;
let variant = req.query.variant || req.body.variant;
let data =
"a=" +
key +
"&email=" +
email +
"&variant=" +
variant +
"&platform=shopify";
axios
.post("https://a.klaviyo.com/api/v1/catalog/subscribe", data)
.then(function(response) {
console.log(response);
res.status(200).send(response.data);
})
.catch(function(error) {
console.log(error);
res.status(400).send({ message: "API Failed" });
});
};