How to set up Data hook afterinsert()

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?

If yes, post screenshots or structure of your database ( database field keys ) and point what information you are trying to send over to discord. You can send data to a discord channel/server using their REST API ( https://discord.com/developers/docs/intro ) or the NPM ( https://www.npmjs.com/package/discord.js )

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)

Click on ’ Integrations ’ and create new webhook. Copy the webhook URL so that we can use it later in our code.

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.