Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This repository is for the Integrating With HubSpot I: Foundations course. This

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.hubspot.com/contacts/2661297/objects/2-42087112/views/all/list

___
## Tips:
Expand Down
109 changes: 53 additions & 56 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,71 +1,68 @@
const express = require('express');
const axios = require('axios');
const app = express();
const path = require('path');

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.set('views', path.join(__dirname, 'views'));



const private_app_token = ''

app.get('/homepage-projects-jp', async (req, res) => {
const projects-jpEndpoint = 'https://api.hubspot.com/crm/v3/objects/projects-jp?properties=project_name,project_description,project_notes';
const headers = {
Authorization: `Bearer ${private_app_token}`,
'Content-Type': 'application/json'
}
const params = {
properties: ['project_name', 'project_description', 'project_notes'] // Add the property names you want here
}
try {
const response = await axios.get(projects-jpEndpoint, { headers, params });
console.log('API Response:', JSON.stringify(response.data, null, 2));
const projects-jp = response.data.results;
console.log('Project data:', JSON.stringify(project, null, 2));
res.render('homepage', { project-jp: projects-jp });
} catch (error) {
console.error(error);
}
})

app.get('/update-projects-jp', (req, res) => {
try {
res.render('updates', { pageTitle: 'Update Custom Object Form | Integrating With HubSpot I Practicum' }); // Render the updates.pug template
} 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);
app.post('/update-projects-jp', async (req, res) => {
const projects-jpEndpoint = 'https://api.hubspot.com/crm/v3/objects/projects-jp';
const headers = {
Authorization: `Bearer ${private_app_token}`,
'Content-Type': 'application/json'
}
const data = {
properties: {
project_name: req.body.project_name,
project_description: req.body.project_description,
project_notes: req.body.project_notes
}

}
try {
const response = await axios.post(projects-jpEndpoint, data, { headers });
console.log('API Response:', JSON.stringify(response.data, null, 2));
res.redirect('/homepage-projects-jp'); // Redirects to home page
} catch (error) {
console.error(error);
}
});
*/


// * Localhost
app.listen(3000, () => console.log('Listening on http://localhost:3000'));
app.listen(3000, () => console.log('Server running on port 3000'));