Skip to main content

Supported products

Serverless functions built in the design manager (served from /_hcms/api/) are being sunset:
  • November 3, 2026: you can no longer create new design manager serverless functions.
  • November 17, 2026: you can no longer edit existing design manager serverless functions, including staging and deploying serverless packages through the private beta. Existing functions keep running.
  • February 1, 2027: design manager serverless functions stop running, and requests to /_hcms/api/ fail.
Learn more in the changelog announcement.Build new serverless functions with developer projects, as shown in this guide. To move existing functions, see migrate design manager serverless functions to developer projects.
Serverless functions provide a way to execute JavaScript through HubSpot on the server-side, preventing it from being exposed to the client. This can be especially important for making API requests that contain sensitive information, such as an API key or other credentials. When the function is invoked, HubSpot executes the function on its back-end, which means you don’t need to provide your own back-end servers to make requests for your CMS website. HubSpot’s serverless functions use the Node.js runtime. In this guide, you’ll walk through creating a simple serverless function that fetches a quote from a third-party service, then displays that quote on a website page. To build and deploy the serverless function to your account, you’ll use a HubSpot developer project on version 2026.09 of the developer platform. For a high-level review of serverless functions, check out the serverless functions overview.

Prerequisites

Before starting this tutorial, you’ll need:

Create a project

Start by creating a project locally so that you can build and deploy it to your account. The project contains an app with static auth and private distribution, which is the only kind of app that can include serverless functions.
  • In the terminal, navigate to the directory where you’ll be storing your project using the cd command.
  • Run the command below to create a project named zen-quote-project on version 2026.09, with an app that includes a public endpoint function.
2026.09 is the current version at the time of writing. Check developer platform versioning for the latest version, and use it for new projects. Don’t use 2025.1, which is sunset, or 2025.2, which doesn’t support serverless functions. Projects already on 2026.03 support serverless functions and run the same Node.js 24 runtime.
  • Navigate into the new project directory:

Add a serverless function to the project

Open the project in your preferred editor, such as VS Code. The CLI created the following files:
  • hsproject.json: the project configuration file. Its platformVersion field is set to 2026.09.
  • src/app/app-hsmeta.json: the app configuration file.
  • src/app/functions/: the serverless functions directory. Each function is a pair of files: a *-hsmeta.json configuration file and the JavaScript file it points to.
  • src/app/functions/package.json: the dependencies for every function in the directory.
Replace the example function with the quote function:
  • Delete endpoint-function-hsmeta.json and NewEndpointFunction.js.
  • In src/app/functions/, create fetch-quote-hsmeta.json and fetch-quote.js, then copy the code below into each file.
  • Update package.json and app-hsmeta.json as shown in their tabs.

Upload the project to HubSpot

With your changes saved, you can now upload the project to HubSpot to build and deploy the app and serverless function.
  • In the terminal, validate the project, then upload it:
  • If this is the first upload, confirm that you want to create the project in the account. The terminal displays the status of the build and deploy steps as they progress. The build is deployed as soon as it succeeds, so the function is live once the upload completes.
  • Once the upload completes, run hs project open to view the project in HubSpot.
In HubSpot, you can view the project details, build and deploy history, and the app, including the function’s logs in the app’s Logs tab. Learn more about managing apps in HubSpot.

Test the function

With the serverless function deployed, you can invoke it by calling its public URL, which has the following structure: https://<domain>/hs/serverless/<path>.
  • <domain>: any domain connected to the account. For example, if both website.com and subdomain.brand.com are connected to the account, you could call the function using https://website.com/hs/serverless/<path> or https://subdomain.brand.com/hs/serverless/<path>.
  • <path>: the value of config.endpoint.path in the function’s *-hsmeta.json file.
Based on the example code in this tutorial, the public URL to invoke the function is https://<domain>/hs/serverless/fetch-quote.
Endpoint paths are global across the account rather than scoped to an app or project. If two projects use the same path, the most recently deployed function takes precedence.
To view the function’s output, navigate to that URL in your browser, replacing the domain with one of your HubSpot-hosted domains. If you haven’t connected a custom domain, you can use the default domain that HubSpot provides: <hubId>.hs-sites.com (for example, 123456.hs-sites.com). Your browser should display the data returned by the Zen Quotes API.
Browser displaying the data returned by the Zen Quotes API
You can also call the function from the terminal:

Invoke the function from a website page

Now that you’ve created the serverless function and confirmed that it returns data, call it from a page to see the data in a more realistic context. For this tutorial, you’ll create a page template containing some HTML and JavaScript that calls the function and displays the response. First, create a new page template:
  • In your local environment, create a new directory to contain your page template, outside of this tutorial’s project directory. Page templates are uploaded to the design manager, not as part of the project.
  • In the terminal, navigate into that directory using the cd command.
  • Run the command below to create a page template named serverless-template.
  • Open the new serverless-template.html file in your editor, then replace the boilerplate code with the code below. The template calls the function with a relative URL (/hs/serverless/fetch-quote), so the request goes to the same domain as the page, whichever domain that is.
  • Save the file, then upload it to the design manager:
Next, create a new page from the template in HubSpot.
  • Navigate to the website pages dashboard of your HubSpot account by running hs open website-pages.
See the full list of available open shortcuts by running hs open --list.
  • In your browser, click Create in the upper right to create a new page.
  • In the dialog box, select a domain to use, then assign a Page name.
  • Click Create page.
  • On the template selection screen, search for your new template. You can use the label or the file name to search for the template (for example, “Serverless function example template”). The template appears under Other templates, as it’s not part of a theme.
Other templates section showing the newly created page template
  • Click Select template.
  • In the page editor, click Preview in the upper right.
Page editor preview button
  • Click Open in a new tab.
In the new tab, you should now be able to click the button to fetch and display quotes.
Demonstration of example button that fetches and displays quotes from the Zen Quotes API

Next steps

Now that you’ve created a serverless function that calls a third-party API and invoked it from a page, there are a few ways to continue building:
  • Authenticate requests to HubSpot APIs with the app’s built-in access token, or to other authenticated APIs with secrets.
  • Move the button and JavaScript into a module rather than hard-coding them in the page template. This makes the function easier to reuse, since you can add the module to any page. To do so, create a module, then add the HTML to the module’s module.html file and the JavaScript to its module.js file.
Last modified on November 3, 2026