Skip to content

Added link to custom object list view in README #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Welcome to the Integrating With HubSpot I: Foundations Practicum
# Welcome to the Integrating With HubSpot I: Foundations Practicum

This repository is for the Integrating With HubSpot I: Foundations course. This practicum is one of two requirements for receiving your Integrating With HubSpot I: Foundations certification. You must also take the exam and receive a passing grade (at least 75%).

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

**Put your HubSpot developer test account custom objects URL link here:** https://app.hubspot.com/contacts/l/objects/${custom-obj-number}/views/all/list
**Put your HubSpot developer test account custom objects URL link here:** https://app-eu1.hubspot.com/contacts/146477196/objects/2-144466597/views/all/list

___
## Tips:
Expand Down
55 changes: 47 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,59 @@ 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 = '';
require('dotenv').config();
const PRIVATE_APP_ACCESS = process.env.HUBSPOT_ACCESS_TOKEN;

// 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.
app.get('/', async (req, res) => {
const url = 'https://api.hubapi.com/crm/v3/objects/2-144466597?properties=name,country,image_url,website,opening_date';
const headers = {
Authorization: `Bearer ${PRIVATE_APP_ACCESS}`,
'Content-Type': 'application/json'
}

// * Code for Route 1 goes here
try {
const resp = await axios.get(url, { headers });
const parks = resp.data.results;
res.render('homepage', { title: 'My parks', parks });
} catch (error) {
console.error('Error fetching parks:', error);
res.status(500).send('Error fetching parks data');
}
});

// 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.
app.get('/update-cobj', (req, res) => {
res.render('updates', { title: 'Update Custom Object Form | Integrating With HubSpot I Practicum'});
});

// * Code for Route 2 goes here
app.post('/update-cobj', async (req, res) => {
const { name, country, image_url, website, opening_date } = req.body;

const url = 'https://api.hubapi.com/crm/v3/objects/2-144466597';
const headers = {
Authorization: `Bearer ${PRIVATE_APP_ACCESS}`,
'Content-Type': 'application/json'
};

const data = {
properties: {
name,
country,
image_url,
website,
opening_date
}
};

try {
await axios.post(url, data, { headers });
res.redirect('/');
} catch (error) {
console.error('Error creating park:', error);
res.status(500).send('Error creating park');
}
});

// 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.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"license": "ISC",
"dependencies": {
"axios": "^1.3.5",
"dotenv": "^17.0.1",
"express": "^4.18.2",
"pug": "^3.0.2"
}
Expand Down
45 changes: 45 additions & 0 deletions views/homepage.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
doctype html
html
head
title= title
style.
table, th, td {
border: 1px solid black;
border-collapse: collapse;
padding: 8px;
}
img {
max-width: 100px;
}
body
h1= title

a(href="/update-cobj") Add to this table

if parks.length
table
thead
tr
th Name
th Country
th Website
th Image
th Opening Date
tbody
each park in parks
tr
td= park.properties.name
td= park.properties.country
td
if park.properties.website
a(href=park.properties.website target="_blank")= park.properties.website
else
| -
td
if park.properties.image_url
img(src=park.properties.image_url alt="park image")
else
| No image
td= park.properties.opening_date
else
p No parks to display.
27 changes: 27 additions & 0 deletions views/updates.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
doctype html
html
head
title= title
body
h1= title

a(href="/") Return to the homepage

form(action="/update-cobj" method="POST")
div
label(for="name") Name:
input(type="text" name="name" required)
div
label(for="country") Country:
input(type="text" name="country")
div
label(for="website") Website:
input(type="url" name="website")
div
label(for="image_url") Image URL:
input(type="url" name="image_url")
div
label(for="opening_date") Opening Date:
input(type="date" name="opening_date")
div
button(type="submit") Submit