/lovable-integrations

Lovable and HubSpot integration: Step-by-Step Guide 2025

Learn how to effortlessly integrate Lovable with HubSpot using our step-by-step guide. Enhance your workflow and drive better marketing results!

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to integrate Lovable with HubSpot?

 

Creating a New HubSpot Integration File

 
  • Create a new file named hubspotIntegration.ts in your Lovable project’s code base (for example, in the src folder).
  • This file will contain the functions to interact with HubSpot's API.
  • Since Lovable does not have a terminal for dependency installation, use the built-in fetch API for HTTP requests (no extra libraries are needed).

export async function createHubSpotContact(contact: {
  email: string;
  firstName?: string;
  lastName?: string;
}): Promise<any> {
  // Replace 'YOURHUBSPOTAPI_KEY' with your actual HubSpot API key.
  const HUBSPOTAPIKEY = 'YOURHUBSPOTAPI_KEY';
  const url = https://api.hubapi.com/contacts/v1/contact/?hapikey=${HUBSPOT_API_KEY};

  const data = {
    properties: [
      {
        property: 'email',
        value: contact.email
      },
      {
        property: 'firstname',
        value: contact.firstName || ''
      },
      {
        property: 'lastname',
        value: contact.lastName || ''
      },
    ]
  };

  try {
    const response = await fetch(url, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data)
    });
    if (!response.ok) {
      throw new Error(HubSpot API error: ${response.statusText});
    }
    return await response.json();
  } catch (error) {
    console.error('Error creating HubSpot contact:', error);
    throw error;
  }
}

 

Integrating HubSpot Function in Your Main Code

 
  • Open the main TypeScript file where you handle user interactions (for example, main.ts or app.ts).
  • Import the function you just created from hubspotIntegration.ts.
  • Add an event listener to capture form submissions and call createHubSpotContact with the user-provided data.

import { createHubSpotContact } from './hubspotIntegration';

async function handleFormSubmission(event: Event): Promise<void> {
  event.preventDefault();

  // Get form input values.
  const emailInput = document.querySelector('#email') as HTMLInputElement;
  const firstNameInput = document.querySelector('#firstname') as HTMLInputElement;
  const lastNameInput = document.querySelector('#lastname') as HTMLInputElement;

  if (!emailInput || !emailInput.value) {
    alert('Please enter an email address.');
    return;
  }

  try {
    const result = await createHubSpotContact({
      email: emailInput.value,
      firstName: firstNameInput ? firstNameInput.value : '',
      lastName: lastNameInput ? lastNameInput.value : ''
    });
    console.log('HubSpot Contact Created:', result);
    alert('Contact was created successfully in HubSpot!');
  } catch (error) {
    alert('There was an error creating the contact.');
  }
}

// Attach the event listener to the form.
const form = document.querySelector('#hubspotForm') as HTMLFormElement;
if (form) {
  form.addEventListener('submit', handleFormSubmission);
}

 

Adding the HTML Contact Form

 
  • In the HTML file where you want to display the contact form (for example, index.html), add the following form markup.
  • This form should have inputs with the IDs email, firstname, and lastname to match the selectors used in the TypeScript code.

<form id="hubspotForm">
  <label for="email">Email:</label>
  <input type="email" id="email" name="email" required />

  <label for="firstname">First Name:</label>
  <input type="text" id="firstname" name="firstname" />

  <label for="lastname">Last Name:</label>
  <input type="text" id="lastname" name="lastname" />

  <button type="submit">Submit</button>
</form>

 

Finalizing the Integration

 
  • Ensure all files (hubspotIntegration.ts, your main TypeScript file, and the HTML file) are saved in your Lovable project.
  • Replace 'YOURHUBSPOTAPI_KEY' with your actual HubSpot API key in the hubspotIntegration.ts file.
  • Test the integration by running your project, filling out the contact form, and confirming the HubSpot contact creation through the console logs or HubSpot dashboard.

 

By following these steps and inserting the code snippets into the appropriate files, you will have integrated HubSpot contact creation into your Lovable project using TypeScript.

Still stuck?
Copy this prompt into ChatGPT and get a clear, personalized explanation.

This prompt helps an AI assistant understand your setup and guide you through the fix step by step, without assuming technical knowledge.

AI AI Prompt

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022