Integrations

Use HubSpot with Prismic

Learn how to build websites with HubSpot and Prismic.

This guide shows how to integrate HubSpot forms with Prismic to let content writers select and display forms directly in their content. You’ll learn to create a custom integration catalog that connects your HubSpot forms to Prismic’s integration fields, giving developers full control over form rendering and submission.

Prerequisites

To integrate HubSpot into your website, you’ll first need to set up HubSpot API access and configure environment variables for your project.

  • Create a HubSpot private app

    HubSpot requires a private app for API access.

    Navigate to Settings > Integrations > Private Apps in your HubSpot account and click Create a private app.

    Use the following values when creating your app:

    FieldValue
    App Name”Prismic Forms Integration” (or your preferred name)
    Description”Display forms through Prismic pages.”
    ScopesSelect forms under Other

    Click Create app to finish setup.

    Learn more about HubSpot private apps

  • Set up environment variables

    After creating your app, save your credentials as environment variables in a .env file:

    .env
    # The access token from the HubSpot private app.
    HUBSPOT_ACCESS_TOKEN=your_access_token_here
    
    # The Portal ID from the HubSpot account settings.
    HUBSPOT_PORTAL_ID=your_portal_id_here

Display HubSpot forms

Follow these steps when content writers need to display a form from a HubSpot project on your website.

  • Add an integration endpoint to your website

    Making forms available to integration fields requires a custom integration catalog.

    To begin, add an API endpoint that returns your forms.

    src/app/api/forms/route.ts
  • Deploy your website

    Your API endpoint needs to be deployed and accessible by Prismic.

    Follow the deployment instructions for Next.js, Nuxt, or SvelteKit before continuing. Remember to add your environment variables to your deployment.

    You’ll use your website’s deployed URL in the next step.

  • Create an integration catalog

    Follow the linked guide to connect the API endpoint to a custom integration catalog.

    Learn how to create a custom integration catalog

    Use the following field values when creating the catalog:

    FieldDescription
    Catalog Name”HubSpot Forms”
    Description”Forms from HubSpot.”
    EndpointThe full public URL to the API endpoint (e.g. https://example.com/api/forms)
    Access TokenAn optional secret string used to authenticate API calls.
  • Add a form field to a content model

    After creating the catalog, connect it to an integration field in a slice, page type, or custom type depending on where you need the form data.

    Learn how to add an integration field

  • Display the form

    After fetching a form from HubSpot, you need to render it on your website. The following example provides minimal, unstyled components that you can copy and customize.

    First, create an API endpoint to send form submissions to HubSpot.

    src/app/api/forms/[id]/route.ts

    Next, create the form components that handle all HubSpot field types. You can copy this entire file into your project and customize as needed:

    src/components/HubSpotForm.tsx

    Finally, display the form selected through the integration field. This example shows how to display the form in a slice.

    src/slices/Form/index.tsx
    import type { Content } from "@prismicio/client";
    import { isFilled } from "@prismicio/client";
    import type { SliceComponentProps } from "@prismicio/react";
    import type { HubSpotForm as HubSpotFormData } from "@/app/api/forms/route";
    import { HubSpotForm } from "@/components/HubSpotForm";
    
    type FormProps = SliceComponentProps<Content.FormSlice>;
    
    export default async function Form({ slice }: FormProps) {
      if (!isFilled.integration(slice.primary.form)) {
        return null;
      }
    
      // Fetch data directly in the component since this is a React Server Component.
      const res = await fetch(
        new URL(
          slice.primary.form.id as HubSpotFormData["id"],
          "https://api.hubapi.com/marketing/v3/forms/",
        ),
        {
          headers: {
            Authorization: `Bearer ${process.env.HUBSPOT_ACCESS_TOKEN}`,
          },
        },
      );
      const form = await res.json();
    
      return (
        <section>
          <HubSpotForm form={form} />
        </section>
      );
    }
  • Add a form to a page

    Test your new field by selecting a form in a page. If everything was set up correctly, you should see the form displayed on your page.

Form metadata

The form metadata returned by the custom integration catalog includes the following fields:

property
Description
Default
id
string

The form’s unique identifier from HubSpot.

Was this page helpful?