I’m developing a Wix app using the Wix CLI and Wix SDK that integrates with my custom PHP-based affiliate system. The app enables Wix store owners to connect their stores to my system. I need help dynamically setting up webhooks for my app.
Here’s what I’m trying to achieve:
Automatically subscribe to various webhook events so my system can track activities happening on the customer’s store.
Send webhook data to a unique subdomain for each customer (e.g., wixsiteuserdomain.mysystemdomain.com), hosted on my cloud server.
I need guidance on:
Dynamic Webhook URLs: How can I dynamically set or update the webhook URL for each store owner during app installation?
Wix API Support: Is it possible to configure webhooks dynamically using the Wix API or any other available method?
I tried to check the documentation and found that we can subscribe to webhook events and set a callback URL where the data will be sent. However, I couldn’t find any way to set this up dynamically for each store owner.
Any examples, documentation, or insights into achieving this functionality would be greatly appreciated.
So the way in which Wix lets you identify users is through a variable called instanceId. Each user will have a unique Instance ID that is generated for whenever they download your app on one of their sites, and that Instance ID will remain the same even if they uninstall it and download the app again.
In the webhook payload, Wix sends you this Instance ID every time along with the data, and using this ID, you can map which user is being referred to in that context.
This is just a brief explanation, you can learn more about that here:
Thank you for your explanation about using instanceId to identify users and dynamically route webhook data. However, I have some concerns and need clarification regarding your proposed solution:
You’re suggesting that I set up a single endpoint on my server to receive all webhook data from Wix. Based on the instanceId in the webhook payload, I should then identify the specific user (store owner) and save the data against that instanceId in my system. Is that correct?
If so, does this mean there is no functionality in Wix to subscribe to different webhooks with separate callback URLs dynamically for each store owner during app installation? For instance, I cannot have unique webhook endpoints like https://store1.mysystemdomain.com/webhook-handler and https://store2.mysystemdomain.com/webhook-handler automatically set up and subscribed for each store owner?
I couldn’t find any official documentation in the Wix Developers’ resources for subscribing to webhooks programmatically or dynamically managing webhook URLs during app installation. The only webhook options I’ve seen involve manually configuring them in the Wix App Management Dashboard, which does not support the dynamic configuration you’re implying. Could you clarify if programmatic webhook subscription is indeed supported, and if so, please provide the correct documentation or example implementation?
If Wix doesn’t allow dynamic webhook subscriptions, then routing all data through a single endpoint is indeed a workaround, but I’d like to confirm if this is the only viable option.
Yes you couldn’t find any documentation for dymamic webhooks because, like I said, there is no such thing as dynamic webhhooks for each individual site.
If you would have searched a bit further, you’d have found the relevant documentation. Nevertheless, linking it here:
Here’s some more info about handling events with Wix CLI:
Now you may use this to send a POST request or something like that to the URL of your choice, I don’t know what your setup is or what you’re trying to achieve so you’ll have to study the documentation in detail and get creative here.
You may also look up and learn more about http-funtions.js however I’m unaware if it will work with apps built using Wix CLI.