Add code into workflow step using API

I have a HubSpot workflow with one of the steps having a NodeJs script. This script is quite long and includes multiple API calls. Thus I want to have this code in a GitHub repo, so it’s easier to verion control it, unit test it, and have other devs on my team review it before I add it to the workflow.

After the script is reviewed and approved, I was planning on manually copy-pasting it into the appropriate step in the relevant HubSpot workflow.

Question - is there a way to automate this “sync” from GitHub to HubSpot? All I need is a HubSpot API endpoint that lets me write or overwrite all the code in a workflow step, and I should be able to take care of the rest using GitHub CI. Does such an API endpoint exist?

So far, I’ve looked through the developer docs and community pages, and haven’t found anything useful. These links seemed most relevant but the solutions don’t work:

- https://community.hubspot.com/t5/CRM/Importing-Snippets/m-p/355825

- https://community.hubspot.com/t5/APIs-Integrations/WorkFlow-Custom-Code-Update-Javascript-code-through-API/m-p/786462

- asked ChatGpt, and it gave me this endpoint that returns a 404:

`await axios.put(`https://api.hubapi.com/automation/v3/workflows/${WORKFLOW\_ID}\`, workflow, { headers: … });

Hi, @siddheshr :waving_hand: Thanks for your question. Let’s invite some of our community members to the conversation — hey @Anton @SteveHTM @JBeatty, do you have any workarounds or other suggestions for @siddheshr?

Best,

Jaycee

Thank you for looking! — Jaycee

@siddheshr - I was hopeful that the new Automation (v4) API might offer what you are looking for - but, unless I’m missing something, it seems to miss out action types related to custom code :disappointed_face:

You general idea is certainly an excellent approach to help manage the strands of code we put into tehse workflows.

Steve

Hi @Jaycee_Lewis, @SteveHTM - thanks both for looking into this. Hopefully this is implemented someday as I can imagine this being a common use case, if it isn’t already. If there’s any further steps I can take to request this as a feature or notify someone else at HubSpot as well, please let me know.

@siddheshr - I did a little follow up investigation with the v4 API. A GET on one of my existing workflows which has a Python custom code step completed and details for this code seemed to be returned in an understandable state - including:

{

“actionId”: “9”,

“type”: “CUSTOM_CODE”,

“secretNames”: [

“CUSTOM_TOKEN”

],

“sourceCode”: "#Get required Python…

The source code was complete as a long string property. So maybe the custom code support is an undocumented API feature and your update mechanics can be implemented as a part of this?

Steve

Hi @SteveHTM,

I did play around with the v4 API and unfortunately it doesn’t seem to support any PUT or PATCH methods that would help me update a workflow. The only workaround I have right now is to delete the existing workflow and create a new one with the changes I want.

That said, thanks for this deep dive. If v4 already has endpoints to get workflow details (including code!), it gives me hope that HubSpot will someday add the ability to update them as well.