Serverless publish function migration secret key to private app

Hi everyone,
I contact you because on the support I wasn’t able to get some explain on what’s wrong.
I used the secret key to publish some content, I used it for many things and I did the migrate to the private app which work for everythings except the publish and I wanted to share the old code, the new one.
I get an error 500 with the new one without logs which can help to figure out what can be the issue.
Here is the code before migration:

// Require axios library to make API requests
const axios = require('axios');

// This function is executed when a request is made to the endpoint associated with this file in the serverless.json file
exports.main = ({ body }, sendResponse) => {
 if(body.tableId){
 tableId = body.tableId; 
 }

 // Format API URLs
 // Requires HubDB table with name donations. Columns: name (text), amount (number)
 const API_HUBDB_BASE = 'https://api.hubapi.com/cms/v3/hubdb/tables/' + tableId;
 const PUBLISH_TABLE_API_URI = API_HUBDB_BASE + '/draft/push-live?hapikey=' + process.env.API_KEY_LIVE;

 axios
 .post(PUBLISH_TABLE_API_URI, {
 headers: {
 'Content-Type': 'application/json',
 },
 })
 .then(function(response) {
 // Log success response of the publish HubDB table API call
 console.log(response);
 sendResponse({
 body: { response: 'success update' },
 statusCode: 200,
 });
 /* console.log(response.statusText);
 console.log(response.status);*/
 })
 .catch(function(error) {
 // sendResponse is what you will send back to services hitting your serverless function
 console.log(error);
 sendResponse({
 body: { response: error },
 statusCode: 500,
 });
 });

};

That is the new code using private app(That process work on all my serverless except publish, which let me guess the issue might be the url itself

exports.main = ({ body }, sendResponse) => {
 if(body.tableId){
 tableId = body.tableId; 
 }
 // Format API URLs
 const API_HUBDB_BASE = `https://api.hubapi.com/cms/v3/hubdb/tables/${tableId}/draft/push-live`;
 const config = {
 headers: {
 'Content-Type': 'application/json',
 'Authorization': `Bearer ${process.env.SG_SECRET}`
 }
 };
 axios.post(API_HUBDB_BASE, config)
 .then(response => {
 console.log(response);
 sendResponse({
 body: { response: 'success update' },
 statusCode: 200
 });
 })
 .catch(error => {
 console.log(error);
 sendResponse({
 body: { response: error },
 statusCode: 500
 });
 });
};

If someone encountered the same issue during his migration and got some idea on the reason, it will be thanksfull.
Just another things to add, I checked the right on private app and the issue shouldn’t come from that.
Kind regards.
Joan

Hi, @joan1 :waving_hand: Thanks for including your details. Let’s see if the community has any feedback they can share — hey @Teun @jonchim, do you have any experience here?

Best,

Jaycee

Hi Jaycee,
I come back with a solution, a bit tricky since by moving from api key to private app need some change on the code (url + way to post data)
Here is a working example:

// Format API URLs
 const API_HUBDB_BASE = `https://api.hubapi.com/cms/v3/hubdb/tables/${tableId}/draft/publish`;
 const config = {
 headers: {
 'Content-Type': 'application/json',
 'Authorization': `Bearer ${process.env.SG_PRIVATE}`
 }
 };
 axios.post(API_HUBDB_BASE,{}, config)

- The push Live has to be removed from the url
Axios post need an empty {} as second parameters, then it work.
Kind regards.
Joan