Socket
Socket
Sign inDemoInstall

@sendgrid/client

Package Overview
Dependencies
6
Maintainers
13
Versions
47
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sendgrid/client


Version published
Maintainers
13
Created

Package description

What is @sendgrid/client?

The @sendgrid/client npm package is a JavaScript client for interacting with the SendGrid API. It allows developers to easily integrate SendGrid's email sending capabilities into their applications. The package provides a way to send emails, manage contacts, and perform other email-related tasks programmatically.

What are @sendgrid/client's main functionalities?

Sending Emails

This feature allows you to send emails using the SendGrid API. The code sample demonstrates how to send a simple text email.

const sgClient = require('@sendgrid/client');
sgClient.setApiKey(process.env.SENDGRID_API_KEY);
const request = {
  method: 'POST',
  url: '/v3/mail/send',
  body: {
    personalizations: [{
      to: [{ email: 'recipient@example.com' }],
      subject: 'Hello, World!'
    }],
    from: { email: 'sender@example.com' },
    content: [{ type: 'text/plain', value: 'Hello, World!' }]
  }
};
sgClient.request(request)
  .then(([response, body]) => {
    console.log(response.statusCode);
    console.log(body);
  })
  .catch(error => {
    console.error(error);
  });

Managing Contacts

This feature allows for the management of contacts within SendGrid. The code sample shows how to add a new contact to your SendGrid account.

const sgClient = require('@sendgrid/client');
sgClient.setApiKey(process.env.SENDGRID_API_KEY);
const request = {
  method: 'PUT',
  url: '/v3/marketing/contacts',
  body: {
    contacts: [{
      email: 'newcontact@example.com',
      first_name: 'First',
      last_name: 'Last'
    }]
  }
};
sgClient.request(request)
  .then(([response, body]) => {
    console.log(response.statusCode);
    console.log(body);
  })
  .catch(error => {
    console.error(error);
  });

Other packages similar to @sendgrid/client

Changelog

Source

[6.2.0] - 2018-1-13 ##

Added

  • PR #650: Expose Client and MailService classes
  • Thanks to Adam Reis for the PR!
  • PR #468: Heroku Tutorial
  • Thanks to Shawn Wang for the PR!
  • PR #477: Check if "body" on "response" is actually defined before accessing it
  • Thanks to Philipp Gröschler for the PR!
  • PR #457: Function to remove HTML tags
  • Thanks to Nathaniel Hodges for the PR!
  • PR #580: Simplify complexity in arrayToJson helpers
  • Thanks to Anthony Juan Christian for the PR!
  • PR #597: Adds file structure for USE_CASES.md
  • Thanks to Shriyash Jalukar for the PR!
  • PR #595: Added Code Review to CONTRIBUTING.md
  • Thanks to Manjiri Tapaswi for the PR!
  • PR #471: Google App Engine (GAE) Tutorial
  • Thanks to Thujeevan for the PR!
  • PR #449: Updated the endpoint which allows the retrieval of all recipients
  • Thanks to Divya Rani for the PR!
  • PR #568: Added unittest to check for specific repo files
  • Thanks to Manjiri Tapaswi for the PR!
  • PR #594: Sr. Front End Engineer job posting in Announcements
  • Thanks to Marghodk for the PR!

Fixed

  • PR #605: Chai dependency version issue
  • Thanks to Mukul Mishra for the PR!
  • PR #581: Remove .only from test
  • Thanks to Cédric Guérin for the PR!

Readme

Source

BuildStatus npm version Email Notifications Badge

This package is part of a monorepo, please see this README for details.

Client for the Sendgrid v3 Web API

This client library is used by the other SendGrid service packages to make requests to the Sendgrid v3 Web API. You can also use it independently to make custom requests to the SendGrid v3 Web API and other HTTP APIs.

To be notified when this package is updated, please subscribe to email notifications for releases and breaking changes.

Installation

Prerequisites

  • Node.js version 6, 7 or 8
  • A SendGrid account, sign up for free to send up to 40,000 emails for the first 30 days or check out our pricing.

Obtain an API Key

Grab your API Key from the SendGrid UI.

Setup Environment Variables

Do not hard code your SendGrid API Key into your code. Instead, use an environment variable or some other secure means of protecting your SendGrid API Key. Following is an example of using an environment variable.

Update the development environment with your SENDGRID_API_KEY, for example:

echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
echo "sendgrid.env" >> .gitignore
source ./sendgrid.env

Install Package

The following recommended installation requires npm. If you are unfamiliar with npm, see the npm docs. Npm comes installed with Node.js since node version 0.8.x therefore you likely already have it.

npm install --save @sendgrid/client

You may also use yarn to install.

yarn add @sendgrid/client

General v3 Web API Usage Example

Please see USAGE.md for all endpoint examples for the SendGrid v3 Web API.

const client = require('@sendgrid/client');
client.setApiKey(process.env.SENDGRID_API_KEY);
const request = {
  method: 'GET',
  url: '/v3/api_keys'
};
client.request(request)
.then(([response, body]) => {
  console.log(response.statusCode);
  console.log(body);
})

Add a Custom Default Header

sgClient.setDefaultHeader('User-Agent', 'Some user agent string');

Change Request Defaults

sgClient.setDefaultRequest('baseUrl', 'https://api.sendgrid.com/');

Overwrite Promise Implementation

You can overwrite the promise implementation you want the client to use. Defaults to the ES6 Promise:

global.Promise = require('bluebird');

Instantiate Client Instances Manually

const {Client} = require('@sendgrid/client');
const sgClient1 = new Client();
const sgClient2 = new Client();
sgClient1.setApiKey('KEY1');
sgClient2.setApiKey('KEY2');

Announcements

All updates to this library are documented in our CHANGELOG and releases. You may also subscribe to email release notifications for releases and breaking changes.

Roadmap

If you are interested in the future direction of this project, please take a look at our open issues and pull requests. We would love to hear your feedback.

How to Contribute

We encourage contribution to our libraries (you might even score some nifty swag), please see our CONTRIBUTING guide for details.

Troubleshooting

Please see our troubleshooting guide for common library issues.

About

@sendgrid/client is guided and supported by the SendGrid Developer Experience Team.

@sendgrid/client is maintained and funded by SendGrid, Inc. The names and logos for @sendgrid/client are trademarks of SendGrid, Inc.

SendGrid Logo

FAQs

Last updated on 13 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc