@sendgrid/client
Twilio SendGrid NodeJS API client
Last updated 18 days ago by twilio-ci .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @sendgrid/client 
SYNC missed versions from official npm registry.

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 Twilio SendGrid service packages to make requests to the Twilio SendGrid v3 Web API. You can also use it independently to make custom requests to the Twilio 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, 8 or >=10
  • A Twilio 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 Twilio SendGrid UI.

Setup Environment Variables

Do not hardcode your Twilio SendGrid API Key into your code. Instead, use an environment variable or some other secure means of protecting your Twilio 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 Twilio 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

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

Change Request Defaults

client.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 maintained and funded by Twilio SendGrid, Inc. The names and logos for @sendgrid/client are trademarks of Twilio SendGrid, Inc.

If you need help installing or using the library, please check the Twilio SendGrid Support Help Center.

If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!

Twilio SendGrid Logo

Current Tags

  • 6.0.0-beta.5                                ...           beta (3 years ago)
  • 7.2.1                                ...           latest (18 days ago)

25 Versions

  • 7.2.1                                ...           18 days ago
  • 7.2.0                                ...           a month ago
  • 7.1.1                                ...           2 months ago
  • 7.1.0                                ...           2 months ago
  • 7.0.1                                ...           3 months ago
  • 7.0.0                                ...           3 months ago
  • 6.5.5                                ...           4 months ago
  • 6.5.3                                ...           5 months ago
  • 6.5.2                                ...           5 months ago
  • 6.5.1                                ...           6 months ago
  • 6.5.0                                ...           6 months ago
  • 6.4.0                                ...           a year ago
  • 6.3.0                                ...           2 years ago
  • 6.2.1                                ...           2 years ago
  • 6.2.0                                ...           2 years ago
  • 6.1.4                                ...           3 years ago
  • 6.1.3                                ...           3 years ago
  • 6.1.2                                ...           3 years ago
  • 6.1.1                                ...           3 years ago
  • 6.1.0                                ...           3 years ago
  • 6.0.0                                ...           3 years ago
  • 6.0.0-beta.5                                ...           3 years ago
  • 6.0.0-beta.4                                ...           3 years ago
  • 6.0.0-beta.2                                ...           3 years ago
  • 6.0.0-beta.0                                ...           3 years ago

Copyright 2014 - 2016 © taobao.org |