16

Is it possible to configure send grid account, that I can specify multiple Post Event URL Event notification. Or maybe is it possible to add multiple Event Notification apps?

Daniil Grankin
  • 3,841
  • 2
  • 29
  • 39

2 Answers2

15

Currently there's no way to have the Events Webhook POST events to multiple URLs.

You could write a script that'd repost data to as many URLs as you wanted and direct SendGrid to POST to it. For example, written in in PHP:

// An array of the URLs you want to POST to:
$urls = array("http://mylocation1.com/event", "http://mylocation2.com/event");

$multi_handle = curl_multi_init();
$handles = array();
// Loop through each URL and create a cURL Handle for the URL
// The cURL handle will POST data that comes to this script to the url.
foreach ($urls as $key => $url) {
    $handles[$key] = curl_init();
    curl_setopt($handles[$key], CURLOPT_URL, $url);
    curl_setopt($handles[$key], CURLOPT_POST, 1);
    curl_setopt($handles[$key], CURLOPT_POSTFIELDS, $_POST);

    curl_setopt($handles[$key], CURLOPT_RETURNTRANSFER, true);
    curl_multi_add_handle($multi_handle, $handles[$key]);
}

$running = null;
// Run through each cURL handle and execute it.
do {
    curl_multi_exec($multi_handle, $running);
} while ($running);

curl_multi_close($multi_handle);

EDIT: It's now recommended that you use Reflector.io (another SendGrid Product) to have the webhook send to multiple destinations.

Nick Q.
  • 3,947
  • 2
  • 23
  • 37
  • 1
    Thank you very much. I want to use Event Notification for diffirent environment and it is not suitable for me using code for one environment that repost data to others, but anyway thanks. – Daniil Grankin Aug 26 '13 at 13:34
  • 10
    reflector.io seems to be inactive as far as I can tell. – Toby Beresford Feb 13 '19 at 11:31
1

I also face the similar problem. In my case i had to update various environments (like stage/prod).

I choose pub/sub model.

  • Topic = "Event-Webhook"
  • subscriber1 = stage cloud function
  • subscriber2 = prod cloud function.

On sendgrid under (mail setting > web hook): I added publisher url for my topic.

Atishay
  • 41
  • 9