If you're using Wix for your website and Notion for managing data, you might want to automate the process of sending form submissions from Wix directly into a Notion database. This can be achieved using Wix Velo, a powerful development platform that allows you to write custom code for your Wix site.
In this guide, we’ll walk you through the steps to set up this automation using Velo code.
Prerequisites
- Wix Account: You need a Wix site with a form.
- Notion Account: You need a Notion workspace and a database where the form data will be stored.
- Notion API Key: Generate an integration token from Notion to allow Wix to communicate with your Notion database.
- Basic Knowledge of JavaScript: Velo uses JavaScript for coding.
Step 1: Set Up Your Notion Database
- Create a Database:
- In your Notion workspace, create a new database with columns (properties) that match the fields in your Wix form (e.g., Name, Email, Message, etc.).
- For example:
- Name: Title or Text property
- Email: Email property
- Message: Text property
- Get Your Database ID:
- Open the database in Notion and copy the database ID from the URL. The ID is the part after the workspace name and slash, e.g.,
https://www.notion.so/yourworkspace/
a1b2c3d4e5f6g7h8i9j0
. - Here
a1b2c3d4e5f6g7h8i9j0
is the Notion database ID.
- Create a Notion Integration:
- Go to Notion Integrations and create a new integration.
- Publish your Integration as Internal Integration.
- Copy the Internal Integration Token (API key) for later use.
- Share the Database with Your Integration:
- Open your Notion database, click Share, and invite your integration by entering its name.
Step 2: Set Up Your Wix Form
- Add a Form to Your Wix Site:
- Use the Wix Editor to add a form to your site. Ensure the form has fields like Name, Email, and Message.
- Enable Velo Dev Mode:
- In the Wix Editor, click on the Dev Mode toggle to enable Velo.
Step 3: Write Velo Code to Send Data to Notion
- Access the Form Submission Event:
- In Velo, go to the Code Panel and locate the form on your page. Use the form’s
onSubmit
event to trigger your code.
- Add the Code:
- Replace the placeholder values (e.g.,
NOTION_API_KEY
,NOTION_DATABASE_API
) with your actual Notion API key and database ID.
import wixFetch from 'wix-fetch'; // Notion API details const NOTION_API_KEY = 'secret_your_notion_api_key'; const DATABASE_ID = 'your_database_id'; // Function to send data to Notion export function form_onSubmit(event) { const formData = event.data; // Get form data // Prepare the data for Notion const notionData = { parent: { database_id: DATABASE_ID }, properties: { "Name": { "title": [ { "text": { "content": formData.name // Map Wix form field to Notion property } } ] }, "Email": { "email": formData.email // Map Wix form field to Notion property }, "Message": { "rich_text": [ { "text": { "content": formData.message // Map Wix form field to Notion property } } ] } } }; // Send data to Notion using the Notion API wixFetch.fetch("https://api.notion.com/v1/pages", { method: "POST", headers: { "Authorization": `Bearer ${NOTION_API_KEY}`, "Content-Type": "application/json", "Notion-Version": "2022-06-28" // Use the latest Notion API version }, body: JSON.stringify(notionData) }) .then(response => response.json()) .then(data => { console.log("Data sent to Notion:", data); }) .catch(error => { console.error("Error sending data to Notion:", error); }); }
Step 4: Test the Integration
- Submit the Form:
- Go to your Wix site and submit the form with test data.
- Check Notion Database:
- Open your Notion database and verify that the form submission has been added as a new entry.
Step 5: Publish Your Site
- Once everything is working correctly, publish your Wix site to make the automation live.
Troubleshooting Tips
- Check API Key and Database ID: Ensure the Notion API key and database ID are correct.
- Permissions: Make sure your Notion integration has access to the database.
- Console Logs: Use
console.log()
to debug any issues in the Velo code.
Conclusion
By following this guide, you’ve successfully automated the process of sending Wix form records to a Notion database using Velo code. This setup eliminates manual data entry and ensures your Notion database is always up-to-date with the latest form submissions.
If you have any questions or run into issues, feel free to reach out to the NotionBees community for support!
This blog post provides a clear, step-by-step guide for your readers to implement the automation. Let me know if you need further assistance! 🚀