Error when trying to use the API

SOLVE
Highlighted
New Contributor

I followed the Hubspot Academy tutorial for APIs to try and get a simple API call up and running, but I ran into a problem that I couldn't find answers to.

For context, here is my package.json code:

{
    "name": "hello_world",
    "version": "1.0.0",
    "main": "index.js",
    "license": "MIT",
    "scripts": {
        "start": "node index.js"
    },
    "dependencies": {
        "express": "^4.16.3",
        "axios": "^0.17.0"
    }
}

Along with my index.js code (api key not included, of course):

const express = require('express');
const axios = require('axios');

const app = express();

const API_KEY = "";

app.get('/contacts', async (req, res) => {
    const contacts = `https://api.hubapi.com/contacts/v1/lists/all/contacts/recent?hapikey=${API_KEY}`;
    try{
        const response = await axios.get(contacts);
        const data = response.data;
        res.json(data);
    }
    catch(err){
        console.error(err);
    }
    
});

app.listen(3000, () => console.log(`Listening on http://localhost:3000`));

After I run 'npm start' and go to localhost:3000, my screen still displays

Cannot GET /

and in my inspect element console, this is what shows.

 

Screenshot (6).png

Could someone help me debug or explain to me what this error is?

 

Thanks

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
Highlighted
HubSpot Moderator

Hey, @alexl22.

 

Thanks for reaching out. I'm happy to lend some help.

 

It looks like you're expecting the response at http://localhost:3000?

Based on yourindex.js file, though, you'll have to navigate to http://localhost:3000/contacts, since that's where the endpoint is configured.

 

Since your index.js file is based on Jeff Ausura's example in the HubSpot Academy Introduction to the HubSpot APIs course, this step can also be seen in the "Getting Started With HubSpot APIs" lesson's third video, "Building a hello world app with HubSpot APIs" at approximately 6:44.

 

Hope this helps!

Isaac Takushi

HubSpot Developer Support
Reply
0 Upvotes
4 Replies 4
Highlighted
New Contributor

Bumping because I could really use some help.

Reply
0 Upvotes
Highlighted
HubSpot Moderator

Hey, @alexl22.

 

Thanks for reaching out. I'm happy to lend some help.

 

It looks like you're expecting the response at http://localhost:3000?

Based on yourindex.js file, though, you'll have to navigate to http://localhost:3000/contacts, since that's where the endpoint is configured.

 

Since your index.js file is based on Jeff Ausura's example in the HubSpot Academy Introduction to the HubSpot APIs course, this step can also be seen in the "Getting Started With HubSpot APIs" lesson's third video, "Building a hello world app with HubSpot APIs" at approximately 6:44.

 

Hope this helps!

Isaac Takushi

HubSpot Developer Support
Reply
0 Upvotes
Highlighted
New Contributor

Oh my gosh thank you so much Isaac! I can't believe I completely mislooked that....

 

I will be sure to reach out if I have any more questions.

 

Thanks again!

Reply
0 Upvotes
Highlighted
HubSpot Moderator

You're welcome, @alexl22!

Isaac Takushi

HubSpot Developer Support
Reply
0 Upvotes