Learn how to connect Lovable with Autopilot using our step-by-step guide. Streamline your automation and drive better results today.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
In your Lovable project, create a new TypeScript file named autopilotIntegration.ts in your project’s source folder. This file will contain all the code needed to communicate with Autopilot’s API. Copy and paste the following code into that file:
export class AutopilotIntegration {
apiKey: string;
baseUrl: string;
constructor(apiKey: string) {
this.apiKey = apiKey;
// Replace with the actual Autopilot API endpoint if different
this.baseUrl = 'https://api.autopilothq.com/v1/';
}
// Function to add a new contact to Autopilot
async addContact(contactData: Record<string, any>): Promise<any> {
const response = await fetch(this.baseUrl + 'contact', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'autopilotapikey': this.apiKey
},
body: JSON.stringify(contactData)
});
if (!response.ok) {
throw new Error('Error adding contact to Autopilot: ' + response.statusText);
}
return response.json();
}
}
This file defines a class that initializes with your Autopilot API key and exposes a method (addContact) that sends contact details to Autopilot using the Fetch API.
Locate your main application file (for example, main.ts or index.ts) in your Lovable project. Insert the following code in that file to use the Autopilot integration. Place it at a location where your application handles contact submissions or lead generation:
import { AutopilotIntegration } from './autopilotIntegration';
// Replace 'Your-Autopilot-API-Key' with your actual Autopilot API key
const autopilot = new AutopilotIntegration('Your-Autopilot-API-Key');
// Example function to push a new contact to Autopilot
async function sendNewLead() {
const contact = {
email: '[email protected]',
firstname: 'John',
lastname: 'Doe'
// Add other contact fields as required by Autopilot
};
try {
const result = await autopilot.addContact(contact);
console.log('Contact added successfully:', result);
} catch (error) {
console.error('Failed to add contact:', error);
}
}
// Call sendNewLead at the appropriate place in your app logic, for example when a user signs up
sendNewLead();
This snippet imports the AutopilotIntegration class, creates an instance with your API key, and defines a function that sends a new contact to Autopilot. Adjust the function invocation to align with your application's logic (for example, within an event handler).
Since Lovable does not have a terminal to install dependencies manually, you can add the Fetch API polyfill directly in your code if needed. If your project does not support the native Fetch API (e.g., when using Node.js), insert the following code snippet at the top of your autopilotIntegration.ts file:
// If you need a fetch polyfill, you can use this approach.
// This example uses 'node-fetch'. In Lovable, mimic this behavior by including the library code manually.
import fetch from 'node-fetch';
// If your environment already supports fetch, you can remove this import.
Additionally, if your project uses a package.json file, add the following dependency manually by editing the file. Open package.json and add the dependency inside the dependencies section:
{
"dependencies": {
"node-fetch": "^2.6.1"
// Include other dependencies as needed
}
}
Lovable should automatically pick up these changes. If your project doesn’t run a package manager, ensure that the required library code is bundled with your project.
Review your project to determine where contact data is collected or leads are generated. At the point immediately after collecting the necessary data, call the sendNewLead function or integrate similar logic. For instance:
// Example integration in an event handler
const submitButton = document.getElementById('submit-contact');
if (submitButton) {
submitButton.addEventListener('click', async () => {
const contactData = {
email: (document.getElementById('email') as HTMLInputElement).value,
firstname: (document.getElementById('firstname') as HTMLInputElement).value,
lastname: (document.getElementById('lastname') as HTMLInputElement).value
// Gather additional form data as required
};
try {
const result = await autopilot.addContact(contactData);
console.log('Contact added successfully:', result);
} catch (error) {
console.error('Failed to add contact:', error);
}
});
}
Place this code snippet in the file where you manage user interactions (for example, in a file responsible for handling form submissions). Adjust HTML element selectors as needed.
After inserting all the code as described, save all changes in your Lovable project. Test your application to ensure that contact data is sent to Autopilot correctly. Monitor the console logs for success or error messages. Adjust any parameters or error handling as needed to fit your project’s requirements.
This prompt helps an AI assistant understand your setup and guide you through the fix step by step, without assuming technical knowledge.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.