This repository contains a collection of serverless functions written by both HubSpot and the community. It serves as a reference to be used when creating new functions, or seeking existing functions to fulfill a specific task.
Serverless functions provide a way to write server-side code that interacts with HubSpot and third-party services through APIs. APIs requiring authentication are not safe for the front-end of a website, as your credentials would be exposed. Serverless functions can act as an intermediary, enabling you to keep credentials secret. For more info, please see the HubSpot Serverless Function Docs or the HubSpot Serverless Functions: Getting Started guide.
Serverless functions were introduced in April 2020 and functionality has been expanded since then to allow custom packages, local testing, and greater visibility into logs to simplify development. Currently, we have serverless function examples that can interact with the following areas of HubSpot:
Tests are run by the test-examples github action on push.
Tests can also be run locally using npm run test.
To add tests:
- Add a test file with the extension
.test.jsin your.functionsfolder that includes your expectations using jest/jasmine (Example hello-world Test) - The serverless function will be run within the github action using the tests/globalTestSetup.js config which utilizes the serverless-dev-runtime package to run the example functions