SendGrid Channel Provider

Configuration

To configure the SendGrid integration, you'll need the following data:

required fields are marked with an `*`
ParameterTypeDescription
api_keystring *The API key for Sendgrid
fromobject
└ emailstring *The email address to send from
└ name The name to send from
reply_toobject
└ emailstring *The email address to reply to
└ name The name to reply to

In the Dashboard

The easiest way to configure this integration is through the MagicBell dashboard:

  1. Log in to your MagicBell dashboard.
  2. Navigate to Channels.
  3. Find and click on this channel name in the sidebar.
  4. Click the Configure SendGrid button.
  5. Follow the on-screen instructions to complete the configuration.

Using the API

Use the API to save , list and delete SendGrid. For example, to save the integration:

Request
curl --request PUT \
  --url 'https://api.magicbell.com/v2/integrations/sendgrid' \
  --header 'content-type: application/json' \
  --header "authorization: Bearer $TOKEN" \
  --data '{"api_key":"SG.1234567890","from":{"email":"[email protected]","name":"Company Name"},"reply_to":{"email":"[email protected]","name":"Reply to Company"}}'

Usage

1. When configured with

{
  "api_key": "SG.1234567890",
  "from": {
    "email": "[email protected]",
    "name": "Company Name"
  },
  "reply_to": {
    "email": "[email protected]",
    "name": "Reply to Company"
  }
}

2. With a channel token

{
  "address": "[email protected]",
  "name": "Dan"
}

3. With Broadcast

{
  "action_url": "https://example.com",
  "category": "example",
  "content": "I come from broadcast",
  "custom_attributes": {},
  "id": "d1b3b3b3-3b3b-3b3b-3b3b-3b3b3b3b3b3b",
  "overrides": {},
  "recipients": [
    {
      "custom_attributes": {
        "plan": "enterprise",
        "preferred_pronoun": "They",
        "pricing_version": "v10"
      },
      "email": "[email protected]",
      "external_id": "83d987a-83fd034",
      "first_name": "Person",
      "last_name": "Doe",
      "phone_numbers": [
        "+1 5005550001"
      ]
    }
  ],
  "title": "Hello, World!",
  "topic": "example"
}

The channel handler triggers a HTTP request

POST https://api.sendgrid.com/v3/mail/send

With payload

{
  "content": [
    {
      "type": "text/html",
      "value": "I come from broadcast"
    }
  ],
  "from": {
    "email": "[email protected]",
    "name": "Company Name"
  },
  "personalizations": [
    {
      "to": [
        {
          "email": "[email protected]",
          "name": null
        }
      ]
    }
  ],
  "reply_to": {
    "email": "[email protected]",
    "name": "Reply to Company"
  },
  "subject": "Hello, World!"
}

Overrides

The provider overrides key in the broadcast payload can be used to change the default behavior of the channel handler.

overrides >> providers >> sendgrid

Override `from` key

Overrides

{
  "providers": {
    "sendgrid": {
      "from": {
        "email": "[email protected]"
      }
    }
  }
}

Payload

{
  "content": [
    {
      "type": "text/html",
      "value": "I come from broadcast"
    }
  ],
  "from": {
    "email": "[email protected]",
    "name": "Company Name"
  },
  "personalizations": [
    {
      "to": [
        {
          "email": "[email protected]",
          "name": null
        }
      ]
    }
  ],
  "reply_to": {
    "email": "[email protected]",
    "name": "Reply to Company"
  },
  "subject": "Hello, World!"
}

Override `custom_args` key

Overrides

{
  "providers": {
    "sendgrid": {
      "custom_args": {
        "tracking_id": "abcd1234"
      }
    }
  }
}

Payload

{
  "content": [
    {
      "type": "text/html",
      "value": "I come from broadcast"
    }
  ],
  "custom_args": {
    "tracking_id": "abcd1234"
  },
  "from": {
    "email": "[email protected]",
    "name": "Company Name"
  },
  "personalizations": [
    {
      "to": [
        {
          "email": "[email protected]",
          "name": null
        }
      ]
    }
  ],
  "reply_to": {
    "email": "[email protected]",
    "name": "Reply to Company"
  },
  "subject": "Hello, World!"
}

Debugging

To debug the integration, you can use the following tools and techniques:

  • Use the Deliveries screen in the MagicBell dashboard to monitor notification deliveries and troubleshoot issues.
  • To experiment with or test the SendGrid API, you can use the SendGrid notification tester.