npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@naturalcycles/sendgrid-client

v6.2.5

Published

SendGrid NodeJS API client

Downloads

10

Readme

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](https://sendgrid.com/free?source=sendgrid-nodejs 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 @naturalcycles/sendgrid-client

You may also use yarn to install.

yarn add @naturalcycles/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('@naturalcycles/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(response.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');

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

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

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

SendGrid Logo