Serverless functions i can't get the secret acces token

Why i cant get the portal secrect accesstoken:

.functions js file:

const axios = require(‘axios’);

exports.main = (context, callback) => {

const accessToken = process.env\["PRIVATE\_APP\_ACCESS\_TOKEN"];

axios.get('https://api.hubapi.com/cms/v3/hubdb/tables/3434343432423/rows', {

    headers: { Authorization: \`Bearer ${accessToken}\` }

})

.then(response => {

    callback({ body: { rows: { results: response } }, statusCode: 200 });

})

.catch(error => callback({ body: { error: error.message }, statusCode: 500 }));

};

And serverless.json:

{

“runtime”: “nodejs18.x”,

“version”: “1.0”,

“environment”: {},

“secrets”: [],

“endpoints”: {

"gethubdbcolumns": {

  "method": "GET",

  "file": "gettable.js"

}

}

}

Hi @TDwebdev,
We are glad that you asked the Community! :slightly_smiling_face:
I understand that you are using a serverless function to view information about a private app access token but you are getting a 500 error, is that right?
I found for you a similar thread, where @GRajput and @himanshurauthan contributed to the post, “Unable to get private access token information” that might be of interest.
Hi @mangelet, @Mike_Eastwood and @Teun do you have any suggestions to help @TDwebdev, please?
Also, if anybody else has anything to add and/or share, please feel free to join in the conversation :slightly_smiling_face:
Thank you and have a great day!
Best,
Bérangère

Hi @TDwebdev

I would expect to see your HubSpot Secret listed in your serverles.json file.

In this example from here it shows “secretName” as the secret in serverles.json

// serverless.json
{ 
 "runtime": "nodejs18.x",
 "version": "1.0",
 "environment": {
 "globalConfigKey": "some-value"
 },
 "secrets": ["secretName"],
 "endpoints": {
 "events": {
 "file": "function1.js",
	 "method":"GET"
 },
 "events/update": {
 "method": "POST",
 "file": "action2.js",
 "environment": {
 "CONFIG_KEY": "some-other-value"
 },
 "secrets": ["googleKeyName","otherkeyname"]
 }
 }
}

Did that work?

Mike

Here to learn more about HubSpot and share my HubSpot Knowledge. I’m the founder of Webalite a Gold HubSpot Partner Agency based in Wellington, New Zealand and the founder of Portal-iQ the world’s first automated HubSpot Portal Audit that helps you work smarter with HubSpot.

Hi @TDwebdev

Please update your code in function.js file through as mentioned in the screenshot

and update your serverless.json file as mentioned below in the screenshot.

Hope this will helps you out. Please mark it as Solution Accepted & Upvote to help other Community member.
Thanks!