Sending data to a webhook

How to send data to a webhook on Palabra

Now that you've created your webhook URL, named it, and sent your first test request you are ready to start sending real user data from your app's frontend or backend.

The way webhooks work is very simple: we give you a unique URL that will be linked to a user action and you make a request to this URL with your user's email address every time your user completed that action.

Let's say we want to notify Palabra when a user validated their email address. The first step would be to create a webhook, that we will name 'User validated email address'.

After creating your webhook you'll get a URL like this: https://hooks.palabra.io/webhook?id=[UNIQUE-ID]

The next step will be to go to your app and find the method where you are validating your user's email address:

user-validation.js
const request = require('request-promise-native')

const userValidatedEmail = async ({ email }) => {
    //.. app specific logic after user validates email

    // sending request to webhook
    const response = await request({
      // get uri from https://a.palabra.io
      uri: 'https://hooks.palabra.io/webhook?id=[UNIQUE-ID]',
      method: 'POST',
      body: {
        email // required
      },
      json: true
    })
  
    if (!response) {
      throw new Error('Error triggering webhook')
    }
}

Now every time a user validates their email address you'll notify Palabra.

Important: make sure you always send an email address on your webhook's request.

Remember you can also send other user data on your body's payload. Just add other user properties to the body object.

Last updated