Skip to content

Commit 79eca78

Browse files
committed
Final Project
1 parent b371165 commit 79eca78

File tree

4 files changed

+107
-6
lines changed

4 files changed

+107
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This repository is for the Integrating With HubSpot I: Foundations course. This
44

55
To read the full directions, please go to the [practicum instructions](https://app.hubspot.com/academy/l/tracks/1092124/1093824/5493?language=en).
66

7-
**Put your HubSpot developer test account custom objects URL link here:** https://app.hubspot.com/contacts/l/objects/${custom-obj-number}/views/all/list
7+
**Put your HubSpot developer test account custom objects URL link here:** https://app-na2.hubspot.com/contacts/242136701/objects/2-166947950/views/all/list
88

99
___
1010
## Tips:

index.js

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,70 @@ app.use(express.urlencoded({ extended: true }));
88
app.use(express.json());
99

1010
// * Please DO NOT INCLUDE the private app access token in your repo. Don't do this practicum in your normal account.
11-
const PRIVATE_APP_ACCESS = '';
11+
const PRIVATE_APP_ACCESS = 'pat-na2-f875ecb3-354e-49a4-9119-32acd35200ad';
12+
13+
const homeURL = 'http://localhost:3007/';
1214

1315
// 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.
1416

15-
// * Code for Route 1 goes here
17+
app.get('/', async (req, res) => {
18+
const dogs = 'https://api.hubapi.com/crm/v3/objects/2-166947950?properties=name,breed,color';
19+
const headers = {
20+
Authorization: `Bearer ${PRIVATE_APP_ACCESS}`,
21+
'Content-Type': 'application/json'
22+
}
23+
try {
24+
const response = await axios.get(dogs, {headers} );
25+
const data = response.data.results;
26+
console.log('Data passed to template:', data);
27+
res.render('homepage', { title: 'Homepage | HubSpot APIs', data });
28+
} catch (error) {
29+
console.error(error);
30+
}
31+
}),
1632

1733
// 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.
1834

19-
// * Code for Route 2 goes here
35+
app.get('/update-cobj', async (req, res) => {
36+
const dogs = 'https://api.hubapi.com/crm/v3/objects/2-166947950';
37+
const headers = {
38+
Authorization: `Bearer ${PRIVATE_APP_ACCESS}`,
39+
'Content-Type': 'application/json'
40+
}
41+
try {
42+
const response = await axios.get(dogs, {headers} );
43+
const data = response.data.results;
44+
res.render('updates', { title: 'Update Custom Object Form | Integrating With HubSpot I Practicum', data });
45+
} catch (error) {
46+
console.error(error);
47+
}
48+
}),
2049

2150
// 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.
2251

23-
// * Code for Route 3 goes here
52+
app.post('/update-cobj', async (req, res) => {
53+
const create = {
54+
properties: {
55+
"name": req.body.name,
56+
"breed": req.body.breed,
57+
"color": req.body.color
58+
}
59+
}
60+
61+
const name = req.query.name;
62+
const createDog = `https://api.hubapi.com/crm/v3/objects/2-166947950/`;
63+
const headers = {
64+
Authorization: `Bearer ${PRIVATE_APP_ACCESS}`,
65+
'Content-Type': 'application/json'
66+
};
67+
try {
68+
await axios.post(createDog, create, { headers } );
69+
res.redirect(homeURL);
70+
} catch(err) {
71+
console.error(err);
72+
}
73+
74+
});
2475

2576
/**
2677
* * This is sample code to give you a reference for how you should structure your calls.
@@ -68,4 +119,4 @@ app.post('/update', async (req, res) => {
68119

69120

70121
// * Localhost
71-
app.listen(3000, () => console.log('Listening on http://localhost:3000'));
122+
app.listen(3007, () => console.log('Listening on http://localhost:3007'));

views/homepage.pug

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
doctype html
2+
html(lang='en')
3+
link(rel="stylesheet", href="/css/style.css")
4+
head
5+
title All Dogs Go to Heaven
6+
body
7+
h1 Dogs
8+
p #[a(href=`http://localhost:3007/update-cobj`) Add to this table]
9+
body
10+
main
11+
.container
12+
table.table
13+
tr
14+
th(style='width: 200px; display: left; max-width:33%;') name
15+
th(style='width: 200px; display: center; max-width:33%;') breed
16+
th(style='width: 200px; display: right; max-width:33%;') color
17+
tbody
18+
each dog in data
19+
tr
20+
li
21+
div(style='display: inline-flex; flex-direction: row; padding-left: 80px;')
22+
.name(style='width: 200px; border-radius: 1px; border:#000000; display: left; max-width:33%;')
23+
| #{dog.properties.name}
24+
.breed(style='width: 200px; display: center; max-width:33%;')
25+
| #{dog.properties.breed}
26+
.color(style='width: 200px; display: right; max-width:33%;')
27+
| #{dog.properties.color}
28+
29+

views/updates.pug

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
doctype html
2+
html(lang='en')
3+
link(rel="stylesheet", href="/css/style.css")
4+
head
5+
title= `${title}`
6+
body
7+
h1 Update Custom Object Form | Integrating With HubSpot I Practicum
8+
#form.responsive(style='width: 200px; display: center; max-width:90%;')
9+
form(method='POST')
10+
.form-row
11+
label(for='name') Name
12+
input#name(name='name' type='text' required='')
13+
.form-row
14+
label(for='breed') Breed
15+
input#breed(placeholder='Chihuahua' name='breed' type='text' required='')
16+
.form-row
17+
label(for='color') Color
18+
input#color(name='color' type='text' required='')
19+
button.btn.btn-primary(type='submit' value='Put in HubSpot' style='width: 200px; height: 35px; font-size: 20px;') Put in HubSpot
20+
21+
p Return to homepage #[a(href=`http://localhost:3007/`) here]

0 commit comments

Comments
 (0)