APIs & Integrations

alexl22
Miembro

Error when trying to use the API

resolver

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

0 Me gusta
1 Soluciones aceptada
IsaacTakushi
Solución
HubSpot Employee
HubSpot Employee

Error when trying to use the API

resolver

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

Associate Certification Manager

Ver la solución en mensaje original publicado

0 Me gusta
4 Respuestas 4
alexl22
Miembro

Error when trying to use the API

resolver

Bumping because I could really use some help.

0 Me gusta
IsaacTakushi
Solución
HubSpot Employee
HubSpot Employee

Error when trying to use the API

resolver

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

Associate Certification Manager
0 Me gusta
alexl22
Miembro

Error when trying to use the API

resolver

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!

0 Me gusta
IsaacTakushi
HubSpot Employee
HubSpot Employee

Error when trying to use the API

resolver

You're welcome, @alexl22!

Isaac Takushi

Associate Certification Manager
0 Me gusta