codefmt — back to formatter

hubspot ops hub code formatter & beautifier

hubspot ops hub custom code actions run on node. `event` carries `inputFields`, `object`, and `origin`. use `callback({ outputFields })` to return data. import libraries via `require` (e.g. `@hubspot/api-client`, `axios`); access secrets via `process.env`.

hubspot operations hub custom code actions let you run javascript or python in your workflows. the javascript runtime exposes event (trigger data with inputFields, object, and origin), callback (for callback-style output), process (for process.env secrets), and console. libraries like @hubspot/api-client and axios are preinstalled and loaded via require().

hubspot supports two code styles. the classic callback style uses exports.main = async (event, callback) => {} and returns data via callback(). the modern return style uses exports.main = async (event) => {} and returns data directly with a return statement. codefmt beautifies your code and handles both patterns, wrapping it in the correct structure before formatting and stripping it back.

the hubspot lint plugin catches common mistakes like missing callback calls, incorrect property access on event.inputFields, and validates globals specific to hubspot's operations hub runtime.

frequently asked questions

how do I return data from a hubspot custom code action?

hubspot supports two styles. the classic callback style uses callback({ outputFields: { key: value } }) to return data. the modern return style lets you simply return { outputFields: { key: value } } from your main function without needing the callback parameter. codefmt handles both patterns correctly.

what is event.inputFields in hubspot?

event.inputFields contains the data you configured in the workflow action settings. these are the custom properties you select when setting up the code action. you access them like event.inputFields.propertyName.

what is the difference between callback and return style in hubspot custom code?

the callback style uses exports.main = async (event, callback) => {} and you call callback({ outputFields: {} }) to return data. the modern return style uses exports.main = async (event) => {} and you return the output directly with return { outputFields: {} }. the return style is cleaner and now fully supported by hubspot. codefmt recognizes and formats both styles.

what globals are available in hubspot custom code actions?

hubspot custom code action javascript exposes event (trigger data with inputFields, object, and origin), callback (used with callback style to return data), process (for process.env secrets), and console. npm libraries like @hubspot/api-client, axios, and lodash are preinstalled and must be loaded via require() — they are NOT globals. codefmt recognizes the real globals and won't flag required modules as undefined.

does hubspot support python custom code actions?

yes. hubspot custom code actions now support python in addition to javascript. the python entrypoint is def main(event) where event exposes inputFields via event.get('inputFields'). requests and the @hubspot/api-client equivalents are preinstalled. codefmt formats hubspot python with ruff and wraps the code so return statements work correctly.

does codefmt catch common hubspot custom code mistakes?

yes. codefmt's hubspot lint plugin catches common issues like forgetting to call callback in callback style code, incorrect event.inputFields access, and missing return values in return style code. it suppresses false positive linting errors for hubspot-injected globals so you only see real issues.