Wix API Integration with Forms
TL;DR:
- Enable Dev Mode (Velo) to access Wix's coding features
- Create backend web modules to handle server-side API calls securely
- Use JavaScript's fetch() function to send form data to external APIs
- Store API keys safely using Wix's secrets manager
- Process API responses properly to handle errors and success states
Getting your Wix forms to talk to external APIs opens up loads of possibilities. You can send leads to your CRM, process payments, or sync data with other tools your business uses. Here's how to set it up properly.
Enable Dev Mode First
Before you can integrate any APIs, you need to turn on Dev Mode (also called Velo). This gives you access to Wix's coding capabilities.
Head to your Wix dashboard and look for the 'Dev Mode' button at the top. Click it and select 'Turn on Dev Mode'. Your editor will refresh and you'll see new coding options appear.
Set Up Your Backend Module
API integrations should happen on the server side, not in your frontend code. This keeps your API keys secure and gives you better control over the data flow.
In the Wix editor, find the 'Backend' section in the sidebar. Create a new web module file and give it a clear name like 'formIntegrations.jsw'. The .jsw extension tells Wix this is a web module that can be called from your frontend.
Your backend module might look something like this:
import { fetch } from 'wix-fetch';
export async function sendToAPI(formData) {
const apiKey = 'your-api-key-here';
try {
const response = await fetch('https://api.example.com/submit', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
},
body: JSON.stringify(formData)
});
return await response.json();
} catch (error) {
console.error('API call failed:', error);
throw error;
}
}
Connect Your Form
Now you need to link your form to the backend function. Add code to your page that calls your backend module when someone submits the form.
Select your form element and add an onSubmit event handler. This will grab the form data and send it to your backend function:
import { sendToAPI } from 'backend/formIntegrations';
$w.onReady(function () {
$w('#yourForm').onSubmit(async (event) => {
event.preventDefault();
const formData = {
name: $w('#nameInput').value,
email: $w('#emailInput').value,
message: $w('#messageInput').value
};
try {
await sendToAPI(formData);
// Show success message
} catch (error) {
// Show error message
}
});
});
Handle API Keys Properly
Never put API keys directly in your code where users can see them. Wix provides a secrets manager for this exact reason.
Go to your site's dashboard, then Settings > Developer Tools > Secrets Manager. Add your API key there and reference it in your backend code using getSecret()
:
import { getSecret } from 'wix-secrets-backend';
export async function sendToAPI(formData) {
const apiKey = await getSecret('myApiKey');
// rest of your code
}
Deal with Responses and Errors
APIs don't always work perfectly. Your integration needs to handle both success and failure cases gracefully.
Check the response status and provide meaningful feedback to users. If the API call fails, don't just show a generic error message. Tell users what happened and what they can do about it.
Consider adding retry logic for temporary failures, and always log errors so you can troubleshoot issues later.
Test Everything Thoroughly
Before going live, test your integration with different form inputs. Try submitting valid data, invalid data, and edge cases like empty fields or very long text.
Check that your error handling works by temporarily breaking something (like using a wrong API endpoint). Make sure users get helpful feedback in all scenarios.
FAQs
Can I send form data to multiple external APIs from one Wix form?
Yes, you can call multiple APIs from a single form submission. Just create separate backend functions for each API and call them one after another, or run them in parallel using Promise.all().
Do I need to encrypt API keys myself when using Wix?
No, Wix handles the encryption when you use their secrets manager. Just make sure you're only making API calls from backend modules, never from frontend code.
Does Wix have built-in tools for popular APIs like Mailchimp or Salesforce?
Wix offers some pre-built integrations through their App Market, but for custom API work you'll need to use Velo and write the integration yourself.
Jargon Buster
Dev Mode (Velo) – Wix's development environment that lets you add custom code to your site
Backend Web Module – Server-side JavaScript files in Wix that handle sensitive operations like API calls
Fetch() – JavaScript function for making HTTP requests to external services
Secrets Manager – Wix's secure storage system for API keys and other sensitive data
Wrap-up
API integrations can transform your basic Wix forms into powerful data collection tools that work with your existing business systems. The key is keeping everything secure by using backend modules and the secrets manager properly.
Take your time with the setup and testing phases. A well-built integration will save you hours of manual work and give your users a much smoother experience.
Ready to build more advanced Wix sites? Join Pixelhaze Academy for in-depth courses and expert guidance.