How to Send WhatsApp Messages via Mercuri API in Wix Automation
This guide explains how to use the Mercuri API to send WhatsApp messages through Wix Automations.
1. Prepare Your API Token
Go to API Management in Mercuri Dashboard and click on Create token.

Now, enter the description and expiration duration of the API token and then click on Create Token.

After creating the token, copy the token from the API Token Management dashboard.
Open your Wix Dashboard → Developer Tools → Secrets Manager.

Click on Add Secret, paste your Mercuri API token in the Value field, and assign a Secret Name (for example:
MERCURI_MESSAGING_API_KEY
). Keep this name handy, as you will need to use the same Secret Name in your Velo code in the following steps.

2. Set Up Wix Automation
Go to Automations in the Wix Dashboard and then click on Create Automation.
Select the automation you want to trigger (e.g., Cart Abandonment)
Add a Velo Code Action and add a .js file containing the following code:
import { secrets } from 'wix-secrets-backend.v2';
import { elevate } from 'wix-auth';
import { fetch } from 'wix-fetch';
// Create elevated versions of secrets functions
const elevatedGetSecretValue = elevate(secrets.getSecretValue);
/**
* Autocomplete function declaration, do not delete
* @param {import('./__schema__.js').Payload} options
*/
export const invoke = async ({ payload }) => {
try {
// Get bearer token securely with elevation
const bearerToken = await elevatedGetSecretValue('MERCURI_MESSAGING_API_KEY');
console.log("Bearer Token",bearerToken)
// Extract contact data
const firstName = payload.contact?.name?.first || '';
const lastName = payload.contact?.name?.last || '';
const recipient = payload.contact?.phone || '';
if (!recipient) {
console.error('Recipient phone number missing.');
return {};
}
const apiPayload = {
phoneNumberId: "xxxxxxxxxxxxxxxxxxx",
channel: "whatsapp",
recipient: recipient,
message: {
type: "template",
template: {
templateId: "xxxxxxxxxxxxxxxxxxx",
parameters: [
{
firstName: firstName,
lastName: lastName
}
]
}
},
saveToInbox: true
};
// Call Mercuri API
const response = await fetch('https://api.mercuri.cx/v1/send_message', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${bearerToken}`
},
body: JSON.stringify(apiPayload)
});
if (!response.ok) {
const errorMsg = await response.text();
console.error(`Mercuri API error: ${response.status} - ${errorMsg}`);
} else {
const respData = await response.json();
console.log('Message sent successfully:', respData);
}
} catch (error) {
console.error('Error in invoke:', error);
}
return {}; // Required empty return object
};
3. Final Steps
After uploading the Velo code, save your changes.
Activate the automation in Wix.
Optionally, test with a sample contact to ensure the messages are sent correctly.
Once these steps are completed, you have successfully set up Wix Automation to send WhatsApp messages using the Mercuri API.
Last updated