forked from dered-dev/apihub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
79 lines (63 loc) · 1.78 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var express = require('express');
var bodyParser = require('body-parser');
const cors = require('cors');
const certifier = require('@api/certifier');
var app = express();
app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.get('/', (request, response) => {
response.send('pagina Principal');
});
app.post('/', function (req, res) {
var email = req.body.email
const myHeaders = new Headers()
myHeaders.append("Content-Type", "application/json")
myHeaders.append("Authorization", "Bearer " + process.env.HSAPIKEY)
const raw = JSON.stringify({
"filters": [{
"propertyName": "email",
"operator": "EQ",
"value": email
}]
})
const requestOptions = {
method: "POST",
headers: myHeaders,
body: raw,
redirect: "follow"
}
fetch("https://api.hubapi.com/crm/v3/objects/contacts/search", requestOptions)
.then((response) => response.text())
.then((result) => {
res.end(result)
})
.catch((error) => console.error(error))
})
// certifier
app.post('/certifier', function (req, res) {
const { name, email, issueDate, expiryDate } = req.body;
// Autenticación con Certifier
certifier.auth(process.env.CERTTOKEN);
// Crear y enviar la credencial
certifier.createIssueSendACredential({
recipient: {
name: name,
email: email
},
issueDate: issueDate,
expiryDate: expiryDate
}, { 'Certifier-Version': '2022-10-26' })
.then(({ data }) => res.json(data))
.catch(err => {
console.error(err);
res.status(500).send('Error processing request');
});
});
// certifier
app.listen(
3000,
() => {
console.log('Server listen in port 3000')
}
)