Step-by-step guide to integrate Lovable with Notion. Discover how to sync data, automate workflows, and boost productivity with our simple, effective tutorial.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
notionService.ts in your project (for example, under a folder named src/integrations if available).
import { Client } from 'https://cdn.skypack.dev/@notionhq/client';
notionService.ts file, create a class that will wrap your Notion API calls.your-notion-secret-token and your-database-id with your actual Notion integration token and database ID.
const NOTION_TOKEN = 'your-notion-secret-token'; // Replace with your actual Notion token
const DATABASE_ID = 'your-database-id'; // Replace with your actual database ID
export class NotionService {
private client: Client;
constructor() {
this.client = new Client({ auth: NOTION_TOKEN });
}
// Method to query the Notion database
async queryDatabase() {
try {
const response = await this.client.databases.query({
databaseid: DATABASEID
});
return response;
} catch (error) {
console.error('Error querying Notion database:', error);
throw error;
}
}
// Method to create a new page in the database
async createPage(title: string, properties: object) {
try {
const response = await this.client.pages.create({
parent: { databaseid: DATABASEID },
properties: {
Name: {
title: [
{
text: { content: title }
}
]
},
...properties
}
});
return response;
} catch (error) {
console.error('Error creating a new page in Notion:', error);
throw error;
}
}
}
app.ts or a similar file where the core logic resides).NotionService class and use it to invoke the methods you created.
import { NotionService } from './notionService';
const notion = new NotionService();
// Example function to fetch data from Notion
async function fetchNotionData() {
try {
const data = await notion.queryDatabase();
console.log('Notion data:', data);
} catch (error) {
console.error('Error fetching data from Notion:', error);
}
}
// Example trigger - you can hook this function to a button or an event within Lovable
fetchNotionData();
NOTIONTOKEN and DATABASEID values to that file.notionService.ts file with your actual Notion credentials.
fetchNotionData function).console.error statements, allowing you to troubleshoot as necessary.
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.