-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
49 lines (44 loc) · 1.34 KB
/
app.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
43
44
45
46
47
48
49
const axios = require('axios');
const express = require("express");
const app = express();
const cors = require("cors");
const dotenv = require("dotenv");
dotenv.config();
app.use(express.json());
app.use(cors());
//TESTE DO SERVIDOR
app.get("/", (request, response) => {
response.json({ message: 'Parece que você caiu de para-quedas aqui, heim :/' })
});
//Cria a conversão no RDStation
app.post("/conversion", async (req, res, next) => {
try {
let conversion = await axios({ method: 'POST', url: process.env.RD_API_CONVERSION,
header: {
"Content-Type": "application/json"
},
data: {
"event_type": "CONVERSION",
"event_family":"CDP",
"payload": {
"conversion_identifier": req.body.conversion_identifier,
"name": req.body.name,
"email": req.body.email,
"tags": req.body.tags,
"available_for_mailing": true,
}
}
}).then(response => {
return res.status(200).send('Lead criada com sucesso na RDStation.');
}).catch(error => {
console.log(error);
return res.status(500).send('Erro ao criar led na RDStation.');
});
} catch (error) {
return res.status(500).send('Erro ao criar a lead.');
}
})
//Inicia o server
app.listen(process.env.PORT || 3000, () => {
console.log("Servidor iniciado!");
});