Hi there,
I’m a marketing ops person with no code experience. We have a workflow with a custom code to send marketing emails from HubSpot over to Planhat (that part is ok, code provided by old partner). The idea for this is that our support agents can check the latest mkt communications received in PlanHat & dn’t have to go to HubSpot all the time.
However, since most our customers receive our newsletters at the same time, they all enroll in the workflow at the same time & the custom code throws the error of too many API calls at once -->
Error while retrieving email: You have reached your ten_secondly_rolling limit.
I thought it’d be a good idea to use the custom code used in the “Workflows Deep Dive” class from HubSpot, where there is a part to create a custom coded action for a weighted lead rotation.
The idea is that people who enroll in the workflow will then be split up in 5 different groups, I’d then send them down 5 different branches with the same custom code from Planhat but with different delays; hoping not to encounter the “ten_secondly_rolling limit” error.
So looking at the code from the HS training, gave me something like this:
exports.main = async (event, callback) => {
return callback({
outputFields:{
test: event.object.hs_object_id % 5
}
});
I have defined the data type & name of the output (number & test) in the output fields; but when I test this piece of custom code; I get an error that it’s not defined in the code.
Custom code action - Workflows Deep Dive example
Not defined in code error?
I then asked ChatGpt “can you write me a Node.js 16.x custom coded script for HubSpot Client v8 that divides the number in ‘hs_object_id’ until it’s a number less than 5 ? I want the result to be in an output called ‘test’. This is for a custom coded workflow in HubSpot”
& I got this code
exports.main = async (event, callback) => {
try {
const hsObjectId = event.object.hs_object_id;
let result = hsObjectId;
while (result >= 5) {
result /= 5;
}
const output = {
test: result,
};
return callback({
outputFields: output,
});
} catch (error) {
return callback({
outputFields: {
error: error.message,
},
});
}
};
Unfortunately, this gave me the same error as in the example from the HubSpot training.
Can anyone please help me figure out why it doesn’t work?

