Documentation
Examples
Sendgrid Email

Example: Sending Emails with SendGrid

This example shows how to send emails with Baba Tools Notifications using SendGrid as the provider.

Prerequisites

Setup

  1. Select the project you want to use and create a new notification application.

  1. Go to providers and click on SendGrid provider.
  2. Enter a name, description and the SendGrid api key.

  1. Go to templates and create a new template, select the template type email. Enter a name and description and all the other required fields in the template. Read more about templates here.

  1. Go to channels and create a new channel.
  2. Select the newly created channel and create a new connection with previously created template (email) and provider (sendgrid). Your channel is ready to go, let's send a notification to it.

Sending Notification

  1. Copy the channel id.

Channel Id

  1. To send a notification, you have to make a POST request to the following endpoint: https://app.baba.tools/api/notification-channels/notify.
curl
curl --location --request POST 'https://app.baba.tools/api/notification-channels/notify' \
    --header 'Content-Type: application/json' \
    --header 'Authorization: Bearer <YOUR_API_KEY>' \
    --data '{
    "channelId": "<YOUR_CHANNEL_ID>",
    "data": {
        "from": "<FROM_EMAIL>",
        "user": {
            "name": "John Doe",
            "email": "[email protected]"
        }
    }
}'
JavaScript/node
import axios from "axios";
 
const channelId = "<YOUR_CHANNEL_ID>";
const apiKey = "<YOUR_API_KEY>";
const payload = {
  from: "<FROM_EMAIL>",
  user: {
    name: "John Doe",
    email: "[email protected]",
  },
};
 
axios.post(
  "https://app.baba.tools/api/notification-channels/notify",
  {
    channelId: channelId,
    data: payload,
  },
  {
    headers: {
      Authorization: `Bearer ${apiKey}`,
    },
  }
);