Question

I have an existing rails3 application with SendGrid Service integration based on SMTP relay, and subscribed to Event Notification Webhooks.

I've got reminder email from Service, informing about impending change to SendGrid's service, and I need make some changes to match new version of Event Notification Webhooks v3.

Email I got contains instructions about How To Upgrade:

  • Review the documentation to understand how to consume this new version's events.
  • Implement changes on your side to handle the new in-formatting of event data.
  • Make changes on SendGrid's configuration page

I wounder, what changes now need I implement on my site? I read manual for v3, but there no information about specifications differences between old and new versions.

Was it helpful?

Solution

Previously, the SendGrid event webhook sent improper batched JSON, with documents seperated by line breaks:

{ "email": "john.doe@sendgrid.com", "timestamp": 1337197600, "smtp-id": "<4FB4041F.6080505@sendgrid.com>", "event": "processed" }
{ "email": "john.doe@sendgrid.com", "timestamp": 1337966815, "category": "newuser", "event": "click", "url": "http://sendgrid.com" }
{ "email": "john.doe@sendgrid.com", "timestamp": 1337969592, "smtp-id": "<20120525181309.C1A9B40405B3@Example-Mac.local>", "event": "processed" }

Today, with v3 it sends proper JSON as such:

[
  {
    "email": "john.doe@sendgrid.com",
    "timestamp": 1337197600,
    "smtp-id": "<4FB4041F.6080505@sendgrid.com>",
    "event": "processed"
  },
  {
    "email": "john.doe@sendgrid.com",
    "timestamp": 1337966815,
    "category": "newuser",
    "event": "click",
    "url": "http://sendgrid.com"
  },
  {
    "email": "john.doe@sendgrid.com",
    "timestamp": 1337969592,
    "smtp-id": "<20120525181309.C1A9B40405B3@Example-Mac.local>",
    "event": "processed"
  }
]

If you'd previously been dealing with non-batched events you'll need to adjust your code so that it interprets an array, rather than just a single document, and then loops through said array. Put into code:

# This
consume_data(params)

# Becomes this
params.each { |doc|
  consume_data(doc)
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top