Edit Page

Webhook Plugin - Tutorials Cloud

Overview

Step-by-step integration examples for Slack notifications and email services.

Prerequisites

⚡ Setup Guide

To run the examples on this page, you need a RESTHeart Cloud service.

Sign up at cloud.restheart.com and create a free API service in minutes.

Set up your root user following the Root User Setup guide.

Tip
All code examples on this page will automatically use your configured RESTHeart Cloud credentials.

Tutorial 1: Slack Notifications

Send notifications to Slack when events occur in your RESTHeart API.

Create Slack Webhook

  1. Go to https://api.slack.com/messaging/webhooks

  2. Click Create New AppFrom scratch

  3. Name your app and select workspace

  4. Click Incoming Webhooks → Toggle ON

  5. Click Add New Webhook to Workspace

  6. Select channel and allow

  7. Copy the webhook URL

Configure RESTHeart Webhook

From RESTHeart Cloud → Service → Plugins → Webhook Plugin:

Name: New User Slack Notification

URL: Your Slack webhook URL

Condition: path('/users') and method('POST') and response-code(201)

Timeout: 5000

Transform: Enable and use this template

{
  "text": "New User Registered",
  "blocks": [{
    "type": "header",
    "text": {
      "type": "plain_text",
      "text": ":tada: New User Registered"
    }
  }, {
    "type": "section",
    "fields": [
      {
        "type": "mrkdwn",
        "text": "*Name:*\n"
      },
      {
        "type": "mrkdwn",
        "text": "*Email:*\n"
      }
    ]
  }, {
    "type": "context",
    "elements": [{
      "type": "mrkdwn",
      "text": "Service:  | Time: "
    }]
  }]
}

Click Test Webhook and check Slack for the message.

Test with Real Request

curl -X POST "https://your-service.cloud.restheart.com/users" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "Jane Smith", "email": "jane@example.com"}'

More Slack Examples

Order Notification:

{
  "text": "New Order",
  "blocks": [{
    "type": "section",
    "text": {
      "type": "mrkdwn",
      "text": ":shopping_cart: *Order #*\nCustomer: \nTotal: $"
    }
  }]
}

Condition: path('/orders') and method('POST') and response-code(201)

Error Alert:

{
  "text": "API Error",
  "blocks": [{
    "type": "section",
    "text": {
      "type": "mrkdwn",
      "text": ":warning: *Error*\nEndpoint:  \nStatus: "
    }
  }]
}

Condition: response-code(500) or response-code(503)

Tutorial 2: Email via Mailjet

Send emails using Mailjet’s API when events occur.

Setup Mailjet

  1. Sign up at https://www.mailjet.com

  2. Navigate to Account SettingsAPI Key Management

  3. Copy API Key and Secret Key

  4. Go to Sender Addresses and verify your sending email

Encode Credentials

echo -n "YOUR_API_KEY:YOUR_SECRET_KEY" | base64

Configure RESTHeart Webhook

Name: Welcome Email via Mailjet

Condition: path('/users') and method('POST') and response-code(201)

Timeout: 10000

Headers:

{
  "Authorization": "Basic YOUR_BASE64_CREDENTIALS",
  "Content-Type": "application/json"
}

Transform: Enable and use this template

{
  "Messages": [{
    "From": {
      "Email": "noreply@yourdomain.com",
      "Name": "Your App"
    },
    "To": [{
      "Email": "",
      "Name": ""
    }],
    "Subject": "Welcome to Our Service!",
    "TextPart": "Hi ,\n\nWelcome to our service!\n\nBest regards,\nThe Team",
    "HTMLPart": "<h1>Welcome !</h1><p>We're excited to have you on board.</p><p>Best regards,<br>The Team</p>"
  }]
}

Click Test Webhook and check the test email is received.

Test with Real Request

curl -X POST "https://your-service.cloud.restheart.com/users" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "John Doe", "email": "john@example.com"}'

More Email Examples

Order Confirmation:

{
  "Messages": [{
    "From": {"Email": "orders@yourdomain.com", "Name": "Your Store"},
    "To": [{"Email": "", "Name": ""}],
    "Subject": "Order Confirmation #",
    "HTMLPart": "<h1>Thank you!</h1><p>Order #</p><p>Total: $</p>"
  }]
}

Condition: path('/orders') and method('POST') and response-code(201)

Password Reset:

{
  "Messages": [{
    "From": {"Email": "security@yourdomain.com", "Name": "Security"},
    "To": [{"Email": ""}],
    "Subject": "Password Reset Request",
    "HTMLPart": "<h1>Password Reset</h1><p>Token: </p><p>Expires in 1 hour.</p>"
  }]
}

Condition: path('/auth/reset-password') and method('POST')

Tutorial 3: Email via SendGrid

Alternative email provider with similar setup.

Headers:

{
  "Authorization": "Bearer YOUR_SENDGRID_API_KEY",
  "Content-Type": "application/json"
}

Transform:

{
  "personalizations": [{
    "to": [{"email": "", "name": ""}]
  }],
  "from": {"email": "noreply@yourdomain.com", "name": "Your App"},
  "subject": "Welcome!",
  "content": [{
    "type": "text/html",
    "value": "<h1>Welcome !</h1>"
  }]
}

Testing Webhooks

Use HTTPBin to test configurations before connecting real services:

Point webhook to https://httpbin.org/post and it echoes back the received payload. Verify webhooks trigger, conditions work, transformations produce expected output, and headers are sent correctly.

Other Integrations

Discord: Create webhook in channel settings, use blocks format similar to Slack

Microsoft Teams: Create incoming webhook connector, use MessageCard format

Custom APIs: Study target API documentation, build matching transformation template, test with HTTPBin first

Best Practices

Start with simple webhooks without transformation. Test thoroughly before production. Use recording feature to see actual request structure. Monitor logs regularly for failures. Keep transformations simple and focused on data reshaping.

Troubleshooting

401 Unauthorized: Verify API keys and authentication header format

400 Bad Request: Check transformation output matches target API requirements

Emails not delivered: Verify sender address, check spam folder, review Mailjet dashboard

Slack rejects payload: Validate against Slack Block Kit Builder at https://app.slack.com/block-kit-builder

See User Guide Troubleshooting for more help.