WorkFlow Custom Code Update Javascript code through API

I have created a custom code and attached in the workflow. Now I want that custom code to be updated on a frequently manner. I’m using same custom code in multiple places so I want to know whether Hubspot is providing any API support to update Javascript code belongs to a custom code. The update is purely allign with the release cycle we have in our project.

I just want to invoke an API with latest code (or) file (or) file path from gitlab/github so the custom code should get updated.

Hello @BabuRaj86

HubSpot provides an API for updating custom code snippets, including JavaScript code snippets used in workflows. You can use the Update a Snippet API endpoint to update the code of an existing custom code snippet.

To use this API, you will need to authenticate your requests using an API key or OAuth 2.0 token. Once authenticated, you can make a PUT request to the following endpoint to update the code of a custom code snippet:

https://api.hubapi.com/crm/v3/extensions/snippets/{snippetId}

In the request body, you can provide the updated JavaScript code as a string in the source property. You can also provide other properties such as the name of the snippet and a description.

Here’s an example of what the request might look like:

PUT https://api.hubapi.com/crm/v3/extensions/snippets/12345
Authorization: Bearer YOUR_ACCESS_TOKEN
Content-Type: application/json

{
 "name": "My Custom Code Snippet",
 "description": "A description of my custom code snippet",
 "source": "console.log('Hello, world!');"
}

In the above example, the snippetId path parameter is the ID of the custom code snippet that you want to update. The source property in the request body contains the updated JavaScript code.

You can also automate this process by integrating with your GitLab/GitHub repository using a webhook or another integration tool. This way, when you push new code to your repository, a script can automatically make a request to the HubSpot API to update the custom code snippet with the latest code.

Hi @BabuRaj86

Yes, HubSpot provides an API for updating custom code associated with workflows. You can use the HubSpot Design Tools API to update a custom code file stored in your HubSpot account.

To update the custom code, you can do the following steps:

1. Store your JavaScript code file in GitLab/GitHub.

2. Use the GitLab/GitHub API to retrieve the latest version of the file.

3. Use the HubSpot API to update the custom code in your HubSpot account with the latest code.

Here’s an overview of how you can use the HubSpot API to update custom code:

1. Authenticate your API requests using an API key or OAuth 2.0.

2. Retrieve the existing custom code using the HubSpot API endpoint `GET /design-manager/v1/layouts/{layout_id}/edit-code`.

3. Update the code with the new code that you retrieved from GitLab/GitHub.

4. Update the custom code in your HubSpot account using the HubSpot API endpoint `PUT /design-manager/v1/layouts/{layout_id}/edit-code`.

Note that you will need to replace `{layout_id}` with the ID of the layout that contains the custom code file you want to update.

It’s also important to test the updated code thoroughly before deploying it in production workflows.

Please mark it as SOLUTION ACCEPTED if you like the solution.

Thank you!