-
Notifications
You must be signed in to change notification settings - Fork 389
/
index.js
71 lines (55 loc) · 2.24 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
const express = require('express');
const axios = require('axios');
const app = express();
app.set('view engine', 'pug');
app.use(express.static(__dirname + '/public'));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
// * Please DO NOT INCLUDE the private app access token in your repo. Don't do this practicum in your normal account.
const PRIVATE_APP_ACCESS = '';
// TODO: ROUTE 1 - Create a new app.get route for the homepage to call your custom object data. Pass this data along to the front-end and create a new pug template in the views folder.
// * Code for Route 1 goes here
// TODO: ROUTE 2 - Create a new app.get route for the form to create or update new custom object data. Send this data along in the next route.
// * Code for Route 2 goes here
// TODO: ROUTE 3 - Create a new app.post route for the custom objects form to create or update your custom object data. Once executed, redirect the user to the homepage.
// * Code for Route 3 goes here
/**
* * This is sample code to give you a reference for how you should structure your calls.
* * App.get sample
app.get('/contacts', async (req, res) => {
const contacts = 'https://api.hubspot.com/crm/v3/objects/contacts';
const headers = {
Authorization: `Bearer ${PRIVATE_APP_ACCESS}`,
'Content-Type': 'application/json'
}
try {
const resp = await axios.get(contacts, { headers });
const data = resp.data.results;
res.render('contacts', { title: 'Contacts | HubSpot APIs', data });
} catch (error) {
console.error(error);
}
});
* * App.post sample
app.post('/update', async (req, res) => {
const update = {
properties: {
"favorite_book": req.body.newVal
}
}
const email = req.query.email;
const updateContact = `https://api.hubapi.com/crm/v3/objects/contacts/${email}?idProperty=email`;
const headers = {
Authorization: `Bearer ${PRIVATE_APP_ACCESS}`,
'Content-Type': 'application/json'
};
try {
await axios.patch(updateContact, update, { headers } );
res.redirect('back');
} catch(err) {
console.error(err);
}
});
*/
// * Localhost
app.listen(3000, () => console.log('Listening on http://localhost:3000'));