Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SendGrid API Workshop v2

Swift
May 08, 2013

SendGrid API Workshop v2

These are my slides from SendGrid delivered Boston

Swift

May 08, 2013
Tweet

More Decks by Swift

Other Decks in Technology

Transcript

  1. What is SendGrid? • Cloud-based SMTP provider • Massively scalable

    • Analytics on emails you send • Robust APIS for developers to integrate
  2. What APIs does SendGrid Offer? API • Subuser API •

    Credentials API • Event Webhook • Inbound Parse Webhook • SMTP API • Web API • Newsletter API • Reseller API APIs Overview
  3. Q: Why should I care about the SendGrid APIs? A:

    There are a lot of reasons, but the short list is... • Reduce code complexity • Deeper analytics & tracking • Less resource consumption • Better UX APIs Overview
  4. SMTP API Custom SMTP header that contains instructions on how

    to process your email Add extra information, filters, & manipulations: • Define multiple recipients • Text Substitutions • Categories • Unique arguments / Identifiers X-SMTPAPI: { ... }
  5. SMTP API Example: Billing notification X-SMTPAPI: { "to": ["[email protected]"], "category":

    "billing_notifications", "unique_args": { "user_id": "12345" } }
  6. SMTP API X-SMTPAPI: { "to": ["[email protected]","[email protected]"], "sub": { "-intro-": ["-greetGuy-",

    "-greetGirl-"], "-name-": ["John", "Jane"], }, "section": { "-greetGuy-": "Mr. -name-", "-greetGirl-": "Ms. -name-" } }
  7. Web API Send mail or manipulate SendGrid settings via HTTP

    Anything (almost) you can do from the SendGrid dashboard, you can do from the Web API • Edit profile / account information • Add new Incoming Parse endpoints • Retrieve stats • Manage lists (Bounces, Blocks, Unsubscribes, etc.) • Add / Remove filters (apps)
  8. Web API Web API endpoints have the following format: https://sendgrid.com/api/<MODULE>.<ACTION>.<FORMAT>

    Example: Send Email over HTTP curl -X POST http://sendgrid.com/api/mail.send.json \ -d “[email protected]” \ -d “[email protected]” \ -d “subject=hello world email” \ -d “text=some body text” \ -d “api_user=your_sendgrid_username” \ -d “api_key=your_sendgrid_key”
  9. Web API vs. SMTP API Q: Why would I use

    HTTP instead of SMTP? (Don’t worry, this is a really common question) A: Normally, you won’t have to. Unless... • Your ISP is blocking common SMTP ports • There is high latency between your app and SendGrid • Difficult to install / configure SMTP drivers • Simplicity for developers
  10. Newsletter API Access the SendGrid newsletter app via the API

    You can create & manage... • Newsletter content • Recipient lists • Sender identities • Scheduled deliveries https://sendgrid.com/api/newsletter/<ACTION>.<FORMAT>
  11. Webhooks Q: What are Webhooks? A: Webhooks are like inverse

    API calls; you tell us where the data needs to go, we send it there. WEB HOOK
  12. •Processed •Dropped •Delivered •Bounced •Opened •Clicked •Spam Reported •Unsubscribed POST

    Your Application receives an event POST (like a form submit) Receive notifications when SendGrid events happen Event Notification Webhook
  13. What does an event notification look like? { "email":"[email protected]", "timestamp":

    1322000095, "unique_arg":"some argument", "category":"billing_notification", "event":"delivered" } Event Notification Webhook
  14. Q: Why would I want to use the event webhook?

    A: Use it to enhance your existing email functionality and gain smart customer insight. Event Notification Webhook (It’s a very reactive API)
  15. Lets you receive email in your application EMAIL JSON 1.

    User sends an email to *@yourapplication.com 2. SendGrid parses the email and attachments 3. You receive a JSON POST to your application Inbound Parse Webhook
  16. 2. Point your domain’s MX records at SendGrid Type Value

    MX 0 mx.sendgrid.net 3. Return a 200 status code from your application 1. Configure your hostname and URL settings http://sendgrid.com/developer/reply Inbound Parse Webhook
  17. { "to":["[email protected]", "[email protected]"], "from":"Swift <[email protected]>", "subject":"SendGrid <3’s thoughbot", "text":"This is

    some text body action", "html":"Supports <em>HTML</em> as well.", "attachments": 1, // ... } Inbound Parse Webhook
  18. Additional APIs Subuser API • Manage and control subuser accounts

    Reseller API • For partners who want to integrate their platform directly Multiple Credentials API • Add new API keys and users to your account
  19. Pro Tip #1 UNOFFICIAL EVENT METRICS Delivered - Opened =

    Time to Read Opened - Last Click = Time Spent Reading Processed - Delivered = SendGrid Delay For example: Opened + Clicks - (Click ∩ Opened) = Unofficial Clicks
  20. Pro Tip #4 ENABLE / DISABLE FILTERS X-SMTPAPI: { "filters":

    { "footer": { "settings": { "enable": 1, "text/plain": "Sent from my flip phone." } } } }