HTTP request failed

Hi, everyone, I have the next endpoint in mi function:

const hubspot = require('@hubspot/api-client');

exports.main = (context = {}, callback) => {
 // instantiate HubSpot node API client

 const hsClient = new hubspot.Client({ accessToken: "NOPE" });

 // Look up contact from the API
 return hsClient.crm.contacts.basicApi
 .getById(1460601)
 .then(resp => {
 // Pass the contact properties back
 callback({ results: resp.properties, body:resp });
 }) 
 .catch ((err) => {
 // Handle API call error
 console.error(err);
 // Option 1: Return no result
 callback({ results: null });
 // Option 2: Rethrow the error, which will result in an ERROR status for the function call
 throw err;
 });
};

is a simple call to crm contacts, to get a contact by id.

But I get the error:

UNHANDLED_ERROR - Execution Time: 880msRuntime.UnhandledPromiseRejection: HttpError: HTTP request failed

I’ve looking the trouble, but I don’t what is the ploblem. I hope you can help me, thank you.

Hi, @igeorge5 :waving_hand: To be safe you should rotate your Private App token ASAP as you exposed it in your original post. I removed it for you.

One suggestion on error handling to help you understand what might be happening:

  • Can you update your error handling to print out the entire error? You can also add more context. This will be useful in troubleshooting.

    console.error("Error while fetching contact by ID:", JSON.stringify(err, null, 2));
    
    

Other culprits can be — scope, rate limits, or network issues. I acknowledge these are guesses, until confirmed. The error you shared doesn’t include enough detail to narrow it down further.

Best,

Jaycee