Sendgrid provides email service which we can use for sending emails from our app and we can even track every details of
any email sent through our Sendgrid account like whether it is delivered, opened, dropped and details of unsubscribed email
addresses etc.

There are also API endpoints provided by Sendgrid to access user subscribe/unsubscribe related data and email event data
with respect to emails sent through your sendgrid account for which documentation link is provided at bottom.

To understand this lets go through simple example to fetch sendgrid subscription groups data from your sendgrid account -

  • Generate API key in your Sendgrid account and store it in your app based on different environments for which you use that Sendgrid account. While generating API key for your account you can set access permission as per your requirement for that API key. For example I just set Read permissions for Suppression Management Service for my API key as I will be just reading suppression groups data from my account. You can any time change permissions for you API key once it is generated.


all: &ALL
url: ""
<<: *ALL
<<: *ALL
<<: *ALL

  • Request to any available Sendgrid V3 API endpoints by using API key in following way -

Example curl request to send email -

  curl --request POST \
  --url \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{"personalizations": [{"to": [{"email": ""}]}],
  "from": {"email":     ""},"subject": "Hello, World!","content": [{"type": "text/plain", "value": "Heya!"}]}'

Rails service using Net HTTP library to access Sendgrid suppression management endpoint to get suppression groups -
Here I have written service to make make get request only, you can make any other request as well using Net HTTP library and modify following snippet as per your need.

class SendgridApiService
  SENDGRID_CONFIG = YAML::load(, 'config', 'sendgrid_v3_api_config.yml'))).result)[Rails.env]

  attr_accessor :api_key, :endpoint_url

  def get_response
    response = request_object.request(request_with_auth_header)
    return unless response.is_a?(Net::HTTPSuccess)
    response.body and JSON.parse(response.body)

  def initialize(api_endpoint)
    self.api_key = SENDGRID_CONFIG['api_key']
    self.endpoint_url = SENDGRID_CONFIG['url'] + api_endpoint

  def new_uri

  def request_object
    http_obj =, new_uri.port)
    http_obj.use_ssl = true
    http_obj.verify_mode = OpenSSL::SSL::VERIFY_NONE

  def request_with_auth_header
    request =
    request['Authorization'] = "Bearer #{api_key}"
    request['content-type']  = "application/json"

And now you can pass any endpoint available for get request to above service and read from that endpoint.
For example in above case to fetch subscription groups data from sendgrid asm groups endpoint -"/asm/groups").get_response

Sendgrid V3 API documentation