SendGrid API Integration


03/02/2020 By

One of the reasons our customers choose SendGrid is that it was created by developers for developers. API integration with SendGrid is easy and fast. In this blog post, we’ll summarize some of the key components from the SendGrid documentation and cover what API integration looks like, along with specific steps you will need to take to get your integration to work.

What is API Integration?

If you are a developer, you probably are already familiar with API integration. Email API integration allows you to connect your email service provider to your existing marketing, sales, or CRM tools. This allows your systems to communicate with each other in order to leverage your technology.

SendGrid provides a series of flexible web and SMTP APIs for easy email API integration for both transactional email and marketing email including:

  • Event Webhook – This will notify a URL via HTTP POST of events that occur as SendGrid processes email. Most Event Webhook users automatically remove unsubscribes, determine unengaged recipients, identify bounced addresses, or react to spam reports.
  • Parse Webhook – Parses the attachments and contents of incoming emails and POST the parsed email to a URL. This allows users to receive mail from any of the addresses on their recipient list.
  • Allows users to specify custom-handling instructions for their email through a header inserted into the body of the message. The header can be added to any SMTP message sent to SendGrid.
  • Web API – Allows SendGrid customers to retrieve information and statistics about their account, including spam reports, bounces, and unsubscribes.

How does API Integration Work?

Your API integration follows the process listed below. For more detailed information, you can visit the documentation page for additional instructions:

Step 1: Build your API call

Your API call must have the following components:

  • A Host. The host for Web API v3 requests is always https://api.sendgrid.com/v3/
  • An Authorization Header
  • An API Key within the Authorization Header
  • A Request. When submitting data to a resource via POST or PUT, you must submit your payload in JSON.

Step 2: Send an email using the SendGrid API:

Sending email using the SendGrid API is simple. After you have built your API call, simply follow these steps to send your email:

curl --request POST \

--url https://api.sendgrid.com/v3/mail/send \

--header 'authorization: Bearer <<YOUR_API_KEY>>' \

--header 'content-type: application/json' \

--data '{"personalizations":[{"to":[{"email":"john.doe@example.com","name":"John Doe"}],"subject":"Hello, World!"}],"content": [{"type": "text/plain", "value": "Heya!"}],"from":{"email":"sam.smith@example.com","name":"Sam Smith"},"reply_to":{"email":"sam.smith@example.com","name":"Sam Smith"}}'

  1. Copy the curl example above.
  2. Paste the curl call into your favorite text editor.
  3. Copy your API key and paste it in the authorization header.
  4. In the data section, specify the "to", "from", and "reply to" names and email addresses and enter a subject.
  5. Copy the code and paste it in your terminal.
  6. Hit Enter.
  7. Check the inbox of the address you specified as the "to" email and see your message!

For more information, including API response messages, visit SendGrid’s Knowledge Center (https://sendgrid.com/docs/for-developers/sending-email/api-getting-started/#build-your-api-call) to learn more.

To see an example of API integration in action, take a look at our NudgeSpot case study to see how they took advantage of API integration to streamline their communications (https://handysends.com/casestudy/nudgespot-sendgrid/).

 

Make sure you use an email you can access.