When a user updates their profile, I want to get the contact ID so I can retrieve the member data using the contact ID. Then, I will update the information in my Airtable.
Basically, I am trying to sync my Airtable member information with Wix. Whenever a member updates their profile information, I will update their info in Airtable.
Becuase there is no native trigger (User Profile updated) from Wix automation. So should I do it correctly?
Sadly it does not work. Nothing is triggered⌠By the way do you know Am I using the right function wixMembers_onMemberUpdated? Or there is a more suitable one?
I donât , but I did have look at the API, and that seemed to be the only one.
I just set it up on my test site,
I do not have my own web hook server so I am just using wixâs http-functions.js to pick them up.
This is the latest code, it seems there was a clash in the timer
import { fetch } from 'wix-fetch';
const WEBHOOK_URL = "https://[mysite.com]/webhook/3324dfdfg-73a0-4eb3-a74b";
const COOLDOWN = 20 * 60 * 1000; // 20 minutes in milliseconds
const RETRY_DELAY = 10000; // 10 seconds for retry
let storedNotification = null;
let timeoutId = null;
let retryTimeoutId = null;
let hasRetried = false;
export function wixMembers_onMemberUpdated(event) {
// Store only the first notification details
if (!storedNotification) {
storedNotification = {
contactId: event.entity._id,
updatedDate: event.entity._updatedDate,
memberLoginEmail: event.entity.loginEmail
};
}
console.log('Webhook recieved :', storedNotification);
// If there's already a timeout running, return early
if (timeoutId) {
return { status: 200 };
}
// Set a timeout to send the stored notification
timeoutId = setTimeout(() => {
sendNotification();
}, COOLDOWN);
return { status: 200 };
}
// Function to send the stored notification
function sendNotification() {
if (!storedNotification) {
console.log('No notification to send');
clearTimeout(timeoutId);
timeoutId = null;
return;
}
const payload = storedNotification;
// Clear the stored notification and reset timeout IDs
storedNotification = null;
timeoutId = null;
// Reset retry state for new notifications
hasRetried = false;
// Send the webhook
fetch(WEBHOOK_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
})
.then(() => {
console.log('Webhook sent successfully');
})
.catch(error => {
console.error('Webhook error:', error);
// Retry sending the notification if it hasn't been retried yet
if (!hasRetried) {
hasRetried = true;
retryTimeoutId = setTimeout(() => {
retryNotification(payload);
}, RETRY_DELAY);
}
});
}
// Retry sending the notification
function retryNotification(payload) {
fetch(WEBHOOK_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
})
.then(() => {
console.log('Webhook retry sent successfully');
})
.catch(error => {
console.error('Webhook retry failed:', error);
// No further retries; optionally log the failure
});
}
My wixâs http-functions.js. function registered the webhook events ok. And then I get the web hook payload. in mine I set it to 2minutes for debugging. I would not set it for less than that, as I did get it firing a lot. below that.
Note although the logs show the âWebhook sent successfullyâ from the event.js after the âIncoming request bodyâ & âPrepared response body:â messages from the web hook server (http-functions.js) it was sent before them⌠just logged out of order.