Error response for custom code action

Hi,

New to custom code actions, hoping I’m making a rookie error that someone can help with.

I’m trying to run the below as a custom code action in a workflow. It’s purpose is to get an authentication token that would then be used in another custom code action in the same workflow.

const axios = require("axios");

const getAuthToken = async () => {
 const url = "https://auth.bizzabo.com/oauth/token";

 const data = {
 client_id: "<CLIENT_ID>", // Replace with actual Client ID
 client_secret: "<CLIENT_SECRET>", // Replace with actual Client Secret
 audience: "https://api.bizzabo.com/api",
 grant_type: "client_credentials",
 account_id: <ACCOUNT_ID> // Replace with actual Account ID
 };

 const headers = {
 "Content-Type": "application/json",
 };

 try {
 const response = await axios.post(url, data, { headers });
 console.log("Access Token:", response.data.access_token);
 return response.data;
 } catch (error) {
 console.error("Error:", error.response ? error.response.data : error.message);
 }
};

// Call the function
getAuthToken();

Client ID/Secret/Account ID all removed for obvious reasons.

When I run the equivalent cURL via postman it works fine, but in Hubspot I get this error:

2025-03-26T09:13:26.446Z ERROR Invoke Error {"errorType":"TypeError","errorMessage":"customerPayload.main is not a function","stack":["TypeError: customerPayload.main is not a function"," at exports.hubspot_handler [as handler] (/var/task/hubspotHandler.js:7:21)"," at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1173:29)"]}

Any idea where I’ve gone wrong?
Thanks!

Hey, @IanShawUnily :waving_hand: It sounds like your code can’t find the function `main`.

Have you tried adding something like:

// Your code here...

// Add this at the end
exports.main = async (event, callback) => {
 try {
 const authData = await getAuthToken();
 callback({
 outputFields: {
 access_token: authData.access_token
 }
 });
 } catch (error) {
 callback({ error: error.message });
 }
};

Talk soon! — Jaycee