• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Rapid Blog

  • Enterprise
  • API Hub
  • Add Your API
  • About
  • Docs
    • API Glossary
  • Blog
    • What is an API?
    • REST API Tutorials
    • Most Popular APIs
  • Sign Up
    • Log In
Blog » Company News » SendGrid API Joins the RapidAPI Marketplace
SendGrid API on RapidAPI.com

SendGrid API Joins the RapidAPI Marketplace

By Alex Walling // July 29, 2020

Today we are thrilled to welcome the SendGrid API to the RapidAPI marketplace! The Colorado-based user communications platform is responsible for sending billions of emails for some of the best and brightest companies in the world, and is now offering its best in class email API to the RapidAPI developer community.

“SendGrid is extremely excited to be partnering with RapidAPI.  RapidAPI’s Marketplace is focused on providing better access to, and simplifying the developer’s experience with APIs.  As a developer-first company, we believe our partnership will create a seamless experience for our community.” Elliot Goldwater, Director of Business Developement @SendGrid.

With the SendGrid API now available on the RapidAPI marketplace, sending emails programmatically has never been easier. In this post we will highlight the different functionality available via the SendGrid API, and take you through the steps of testing, connecting and subscribing to the API via RapidAPI.

What Is Possible with the SendGrid API?

SendGrid has built a premiere cloud-based email service that reliably delivers emails for companies of all sizes. No matter the size of your project or company, the SendGrid API will enable you to simplify the process of programmatically sending your emails. Beyond the ability to programmatically send emails, the SendGrid API provides features like unsubscribe tracking, reputation monitoring, and an Inbound Parse Webhook.

How to Use the SendGrid API

The best way to get started is to head straight to the pricing tab for the SendGrid API. Before making any requests to the API, you’ll first need to subscribe to an API pricing plan. There are four different tiers available, so choose the plan that best suits your needs. And if you need a more customized pricing solution, just reach out to us at support@rapidapi.com and we would be happy to help!

SendGrid pricing page on RapidAPI

Once subscribed to an API plan, go to the functions page, where you’ll find all of the endpoints available to you, along with code snippets to help you get started.

How Do I Find my SendGrid API Key?

With RapidAPI, you don’t need a SendGrid API Key. Once you’re subscribed to a pricing plan, you will use your RapidAPI API key to make your requests to the SendGrid API. Your RapidAPI key is provided with every code snippet as the “X-Mashape-Key” and can also be found in your RapidAPI Dashboard under the “Security” tab of your application.

List of SendGrid API Endpoints

  • Mail
  • Blocks
  • Bounces
  • Invalid Emails
  • Spam Reports
  • Cancel Scheduled Sends
  • Unsubscribe Group
  • Suppressions (Unsubscribe)
  • Settings – Tracking
  • Settings – Mail

The first endpoint we’ll cover is the Send Mail endpoint.

How to Send Email with the SendGrid API

SendGrid send mail endpoint page on RapidAPI

With the Send Mail endpoint, you need to provide a request payload JSON object. The JSON email object tells the SendGrid API where to send the email, what the content of the email is, which unsubscribe group to use, and much more. The most basic email object you can send is one that includes: to email address, from email address, and plain text content for the email.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
{
"personalizations": [
{
"to": [
{
"email": "my_to_email@rapidapi.com"
}
],
"subject": "Hello, World!"
}
],
"from": {
"email": "my_from_email@rapidapi.com"
},
"content": [
{
"type": "text/plain",
"value": "Hello, World!"
}
]
}
{ "personalizations": [ { "to": [ { "email": "my_to_email@rapidapi.com" } ], "subject": "Hello, World!" } ], "from": { "email": "my_from_email@rapidapi.com" }, "content": [ { "type": "text/plain", "value": "Hello, World!" } ] }
{
  "personalizations": [
    {
      "to": [
        {
          "email": "my_to_email@rapidapi.com"
        }
      ],
      "subject": "Hello, World!"
    }
  ],
  "from": {
    "email": "my_from_email@rapidapi.com"
  },
  "content": [
    {
      "type": "text/plain",
      "value": "Hello, World!"
    }
  ]
}

My programming language of choice is NodeJS, so that’s what I’ll be using in this tutorial, but you can use any of the SDKs we support to do the same functionality.

SendGrid API – SDKs Supported:

  • NodeJS
  • PHP
  • Python
  • Ruby
  • Objective-C
  • Java
  • C#
  • cURL

To start using the API, copy the code snippet from RapidAPI into an index.js file and install the unirest npm module.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
const unirest = require(‘unirest’)
unirest.post("https://rapidprod-sendgrid-v1.p.mashape.com/mail/send")
.header("X-Mashape-Key", "********************************************")
.header("Content-Type", "application/json")
.send({"personalizations":[{"to":[{"email":"my_to_email@rapidapi.com"}],"subject":"Hello, World!"}],"from":{"email":"my_from_email@rapidapi.com"},"content":[{"type":"text/plain","value":"Hello, World!"}]})
.end(function (result) {
console.log(result.status, result.headers, result.body);
});
const unirest = require(‘unirest’) unirest.post("https://rapidprod-sendgrid-v1.p.mashape.com/mail/send") .header("X-Mashape-Key", "********************************************") .header("Content-Type", "application/json") .send({"personalizations":[{"to":[{"email":"my_to_email@rapidapi.com"}],"subject":"Hello, World!"}],"from":{"email":"my_from_email@rapidapi.com"},"content":[{"type":"text/plain","value":"Hello, World!"}]}) .end(function (result) { console.log(result.status, result.headers, result.body); });
const unirest = require(‘unirest’)

unirest.post("https://rapidprod-sendgrid-v1.p.mashape.com/mail/send")
.header("X-Mashape-Key", "********************************************")
.header("Content-Type", "application/json")
.send({"personalizations":[{"to":[{"email":"my_to_email@rapidapi.com"}],"subject":"Hello, World!"}],"from":{"email":"my_from_email@rapidapi.com"},"content":[{"type":"text/plain","value":"Hello, World!"}]})
.end(function (result) {
  console.log(result.status, result.headers, result.body);
});

Running the program will send an email to “my_to_email@rapidapi.com” with the subject “Hello, World!” and a plain text body of “Hello, World!” This is all it takes to send an email using the SendGrid API and RapidAPI! Easy!

Sending a simple text email is great, but there are other amazing ways to improve your emails with the SendGrid API which we’ll cover next. The first step would be separating the JSON object out into its own variable to make it easier to manipulate.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
const unirest = require(‘unirest’)
let emailObject = {
"personalizations":[
{
"to":[
{
"email":"my_to_email@rapidapi.com"
}
],
"subject":"Hello, World!"
}
],
"from":{
"email":"my_from_email@rapidapi.com"
},
"content":[
{
"type":"text/plain",
"value":"Hello, World!"
}
]
};
unirest.post("https://rapidprod-sendgrid-v1.p.mashape.com/mail/send")
.header("X-Mashape-Key", "********************************************")
.header("Content-Type", "application/json")
.send(emailObject)
.end(function (result) {
console.log(result.status, result.headers, result.body);
});
const unirest = require(‘unirest’) let emailObject = { "personalizations":[ { "to":[ { "email":"my_to_email@rapidapi.com" } ], "subject":"Hello, World!" } ], "from":{ "email":"my_from_email@rapidapi.com" }, "content":[ { "type":"text/plain", "value":"Hello, World!" } ] }; unirest.post("https://rapidprod-sendgrid-v1.p.mashape.com/mail/send") .header("X-Mashape-Key", "********************************************") .header("Content-Type", "application/json") .send(emailObject) .end(function (result) { console.log(result.status, result.headers, result.body); });
const unirest = require(‘unirest’)

let emailObject = {  
   "personalizations":[  
      {  
         "to":[  
            {  
               "email":"my_to_email@rapidapi.com"
            }
         ],
         "subject":"Hello, World!"
      }
   ],
   "from":{  
      "email":"my_from_email@rapidapi.com"
   },
   "content":[  
      {  
         "type":"text/plain",
         "value":"Hello, World!"
      }
   ]
};

unirest.post("https://rapidprod-sendgrid-v1.p.mashape.com/mail/send")
.header("X-Mashape-Key", "********************************************")
.header("Content-Type", "application/json")
.send(emailObject)
.end(function (result) {
  console.log(result.status, result.headers, result.body);
});

How to Send an HTML Email with the SendGrid API

The next improvement is to use an HTML email instead of a plain text email. To do this, I’m going to use the Responsive HTML Email Template created by leemunroe. To do so, download the email.html file from the GitHub repo into your projects directory, then load it into your index.js file by using the fs node module. Once the HTML file is loaded in, change the content value of your emailObject to use the new emailHTML variable:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
const unirest = require(‘unirest’);
const fs = require('fs');
let emailHTML = fs.readFileSync(email.html', 'utf8');
let emailObject = {
"personalizations":[
{
"to":[
{
"email":"my_to_email@rapidapi.com"
}
],
"subject":"Hello, World!"
}
],
"from":{
"email":"my_from_email@rapidapi.com"
},
"content":[
{
"type": "text/html",
"value": emailHTML
}
]
}
unirest.post("https://rapidprod-sendgrid-v1.p.mashape.com/mail/send")
.header("X-Mashape-Key", "********************************************")
.header("Content-Type", "application/json")
.send(emailObject)
.end(function (result) {
console.log(result.status, result.headers, result.body);
});
const unirest = require(‘unirest’); const fs = require('fs'); let emailHTML = fs.readFileSync(email.html', 'utf8'); let emailObject = { "personalizations":[ { "to":[ { "email":"my_to_email@rapidapi.com" } ], "subject":"Hello, World!" } ], "from":{ "email":"my_from_email@rapidapi.com" }, "content":[ { "type": "text/html", "value": emailHTML } ] } unirest.post("https://rapidprod-sendgrid-v1.p.mashape.com/mail/send") .header("X-Mashape-Key", "********************************************") .header("Content-Type", "application/json") .send(emailObject) .end(function (result) { console.log(result.status, result.headers, result.body); });
const unirest = require(‘unirest’);
const fs = require('fs');

let emailHTML = fs.readFileSync(email.html', 'utf8');
let emailObject = {  
   "personalizations":[  
      {  
         "to":[  
            {  
               "email":"my_to_email@rapidapi.com"
            }
         ],
         "subject":"Hello, World!"
      }
   ],
   "from":{  
      "email":"my_from_email@rapidapi.com"
   },
   "content":[  
        {
            "type": "text/html",
            "value": emailHTML
        }
   ]
}

unirest.post("https://rapidprod-sendgrid-v1.p.mashape.com/mail/send")
.header("X-Mashape-Key", "********************************************")
.header("Content-Type", "application/json")
.send(emailObject)
.end(function (result) {
  console.log(result.status, result.headers, result.body);
});

SendGrid Unsubscribe Groups

The last feature of the SendGrid API I want to show off is the unsubscribe groups functionality. To start, you’ll first need to create a new unsubscribe group. You can do this by using the Create a new suppression group endpoint. Simply call the endpoint through the browser, a cURL command, or in the programming language of your choice.

Terminal running the Create a new unsubscribe group endpoint

By calling the endpoint, the API will create a new unsubscribe group for your account and the API response will include the id of your new group. Make sure to copy the unsubscribe group id into your application so you can use it later. If you forget to copy the unsubscribe group id into your application or accidentally delete it, use the Retrieve all suppression groups associated with the user endpoint to locate the id once again.

You need to add this new unsubscribe group id to your emailObject using the “asm” value. Your code should now look something like this.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
const unirest = require(‘unirest’);
const fs = require('fs');
let asmGroupId = 78227;
let emailHTML = fs.readFileSync(email.html', 'utf8');
let emailObject = {
"personalizations":[
{
"to":[
{
"email":"my_to_email@rapidapi.com"
}
],
"subject":"Hello, World!"
}
],
"from":{
"email":"my_from_email@rapidapi.com"
},
"content":[
{
"type": "text/html",
"value": emailHTML
}
],
"asm": {
"group_id": asmGroupId
}
}
unirest.post("https://rapidprod-sendgrid-v1.p.mashape.com/mail/send")
.header("X-Mashape-Key", "********************************************")
.header("Content-Type", "application/json")
.send(emailObject)
.end(function (result) {
console.log(result.status, result.headers, result.body);
});
const unirest = require(‘unirest’); const fs = require('fs'); let asmGroupId = 78227; let emailHTML = fs.readFileSync(email.html', 'utf8'); let emailObject = { "personalizations":[ { "to":[ { "email":"my_to_email@rapidapi.com" } ], "subject":"Hello, World!" } ], "from":{ "email":"my_from_email@rapidapi.com" }, "content":[ { "type": "text/html", "value": emailHTML } ], "asm": { "group_id": asmGroupId } } unirest.post("https://rapidprod-sendgrid-v1.p.mashape.com/mail/send") .header("X-Mashape-Key", "********************************************") .header("Content-Type", "application/json") .send(emailObject) .end(function (result) { console.log(result.status, result.headers, result.body); });
const unirest = require(‘unirest’);
const fs = require('fs');

let asmGroupId = 78227;
let emailHTML = fs.readFileSync(email.html', 'utf8');
let emailObject = {  
   "personalizations":[  
      {  
         "to":[  
            {  
               "email":"my_to_email@rapidapi.com"
            }
         ],
         "subject":"Hello, World!"
      }
   ],
   "from":{  
      "email":"my_from_email@rapidapi.com"
   },
   "content":[  
        {
            "type": "text/html",
            "value": emailHTML
        }
   ],
    "asm": {
        "group_id": asmGroupId
    }
}

unirest.post("https://rapidprod-sendgrid-v1.p.mashape.com/mail/send")
.header("X-Mashape-Key", "********************************************")
.header("Content-Type", "application/json")
.send(emailObject)
.end(function (result) {
  console.log(result.status, result.headers, result.body);
});

When you provide an asm group in your email request, SendGrid automatically appends unsubscribe links to the end of your email.

Email Template

If you want to customize where the unsubscribe link is located, use the <%asm_group_unsubscribe_raw_url%> tag as the href link in your HTML file.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!-- START FOOTER -->
<div class="footer">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="content-block">
<span class="apple-link">RapidAPI, 164 Townsend St. Apt. B, San Francisco CA 94102</span>
<br> Don't like these emails? <a href="<%asm_group_unsubscribe_raw_url%>">Unsubscribe</a>.
</td>
</tr>
</table>
</div>
<!-- END FOOTER -->
<!-- START FOOTER --> <div class="footer"> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td class="content-block"> <span class="apple-link">RapidAPI, 164 Townsend St. Apt. B, San Francisco CA 94102</span> <br> Don't like these emails? <a href="<%asm_group_unsubscribe_raw_url%>">Unsubscribe</a>. </td> </tr> </table> </div> <!-- END FOOTER -->
<!-- START FOOTER -->
<div class="footer">
    <table border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td class="content-block">
                <span class="apple-link">RapidAPI, 164 Townsend St. Apt. B, San Francisco CA 94102</span>
                <br> Don't like these emails? <a href="<%asm_group_unsubscribe_raw_url%>">Unsubscribe</a>.
            </td>
        </tr>
    </table>
</div>
<!-- END FOOTER -->

SendGrid automatically populates this tag with the unsubscribe URL for the asm group provided so your email recipients can unsubscribe with ease!

Conclusion

As you can see, there’s a lot you can do with the SendGrid API, and we couldn’t be more excited to have it now live and available to our developer community on RapidAPI. We’d love to learn about your use case and how you’ve been using the API so please don’t hesitate to shoot us a note at community@rapidapi.com!

Read more SendGrid API Documentation.

5/5 - (50 votes)
« The Top 9 Payment APIs To Manage Your Payments
Top Finance APIs You Should Be Using [2019] »

Filed Under: APIs, Company News Tagged With: API Announcement, api tutorial, developer, Email, email api, Email APIs, Programming, RapidAPI, SendGrid, SendGrid API

Alex Walling

Developer Advocate at RapidAPI

Reader Interactions

Comments

  1. Scott says

    October 22, 2019 at 2:26 pm

    Thank you this helped me !

    Reply
    • RapidAPI Staff says

      October 22, 2019 at 2:48 pm

      No problem Scott.

      Glad we could help!

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Build anything with APIs, faster.

Discover, evaluate, and integrate with any API. RapidAPI is the world’s largest API Hub with over 4 Million developers and 35,000 APIs.

Browse APIs »

APIs mentioned in this article

Connect to the SendGrid API
Connect to the SendGrid API

Footer

  • API Guides
  • API Courses
  • API Glossary
  • API Testing
  • API Management
  • Most Popular APIs
  • Free APIs List
  • How to use an API
  • Learn REST API
  • Build API’s
  • About
  • Build APIs
  • Careers
  • Contact Us
  • Write for Us
  • API Directory
  • Press Room
  • Privacy Policy
  • Terms of Use

© 2025 RapidAPI. All rights reserved.

Building an Enterprise API Program
Learn More

×