I have been trying to set up an afterinsert() data hook for almost 2 weeks now but can’t get it to work properly the api references are very veg I have asked multiple times from this community and each time you send me to the same reference page I already have so if that’s what you are going to do don’t bother.
I am asking for help not to be linked to some half ass reference page that explains nothing. if you can help awesome if not at this point I’m highly considering taking my site elsewhere and dropping wix completely. and honestly my decision will be on if the community actually acts like one and helps not this half ass “here’s a page figure it out” bs
side note: I have also been in contact with wix & wix coding team and they have provided shit for help and have done what EVERY single mod here has done and linked to the same bs half ass reference pages.
I don’t expect an answer. I never do from the wix community. I don’t expect anyone to help either - looking through this forum you can see how much the mods do not help you can see the frustration in the way people answer them.
We cannot help you without understanding details about your project. Just imagine you are asking ‘How to set up Data hook afterinsert()’ which is very generic question so you are getting generic answers.
What are you trying to do?
What is your goal?
I see that you have previously posted about Discord webhooks. Are you trying to send information to a Discord channel when a new submission or item is inserted into the database?
Below is an example to create a Bot on your Discord Server and setting up your Wix website to send a message to the channel whenever a database submission is made.
Example:
#corvid#discord
Go to your Discord Server and open the Server Settings as marked below (Click image to expand for better view)
On your Wix website create a data hook by clicking on the gear icon beside your database (which you are submitting to) and select ‘Add/Remove Hooks’ → Check the ‘After Insert’ checkbox & click on Add & Edit Code.
After that add a code similar to the one below to send the database content to your discord channel.
import {fetch} from 'wix-fetch';
export function myDatabase_afterInsert(item, context) {
let data = {
content: item.title //sends only the values of the title field
}
sendDiscord(data);
}
function sendDiscord(data) {
const response = fetch("YOUR_WEBHOOK_URL", {
method: 'POST',
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
});
}
You will need to modify the contents of the ‘data’ object to include values that you would like to send
After this submit something to your database and test.
Thank you for your reply, I have follow your steps here is my code below i will be removing the webhook link,
import {fetch} from 'wix-fetch';
export function Books_afterInsert(item, context) {
let data = {
content: item.bookName,
context: item.coverArt //sends only the values of the title field
}
sendDiscord(data);
}
function sendDiscord(data) {
const response = fetch("MY DISCORD URL HERE", {
method: 'POST',
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
});
}
This works ye thank you, when it comes to adding the url of the booke and an image ive found that my placement is wrong i was seeing that it should be in the JSON body to create aan embed but when I add that information in (I know it in javaScript) wix code its not the same how to do it in java below)