Twilio SendGrid NodeJS API client
The npm package "@sendgrid/client" is a critical tool for developers looking to integrate email functionalities within their Node.js applications using the Twilio SendGrid Email API. This client module simplifies the process of connecting to the SendGrid Email API, allowing developers to easily send emails, manage contacts, and generate reports without the need for deep knowledge of HTTP clients or API specifics. The package offers a variety of features including support for all SendGrid v3 API endpoints, such as sending transactional and marketing emails, and handling email templates and attachments. By leveraging "@sendgrid/client", developers can enhance their applications with reliable email delivery, optimized for high performance and scalability.
To start using the "@sendgrid/client" in your project, the initial step is to perform the npm install @sendgrid/client command in your Node.js environment. This installation process configures the necessary dependencies and settings to enable seamless API communication. After installation, developers can utilize the comprehensive documentation provided to quickly integrate email functionalities into their applications. The package’s robust set of tools and utilities also supports customizations and advanced configurations, making it adaptable to various project requirements. This flexibility ensures that developers can manage email delivery settings, track email engagement, and access detailed analytics to optimize their email strategies effectively.
By integrating "@sendgrid/client" into your Node.js application, you are not only gaining access to a powerful email service but also ensuring that your application maintains high standards of communication and professionalism. The client’s compatibility with the latest versions of Node.js and its continuous updates from Twilio SendGrid guarantee that your email solutions are future-proof and aligned with industry best practices. This makes "@sendgrid/client" an indispensable tool for developers looking to implement efficient, scalable, and feature-rich email services in their applications.
Core dependencies of this npm package and its dev dependencies.
@babel/cli, @babel/core, @babel/node, chai, chai-as-promised, dirty-chai, eslint, istanbul, lerna, mocha, mocha-clean, mocha-sinon, moment, sinon, sinon-chai, typescript
A README file for the @sendgrid/client code repository. View Code
This package is part of a monorepo, please see this README for details.
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.
Grab your API Key from the Twilio SendGrid UI.
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
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
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);
})
client.setDefaultHeader('User-Agent', 'Some user agent string');
// or
client.setDefaultHeader({'User-Agent': 'Some user agent string'});
client.setDefaultRequest('baseUrl', 'https://api.sendgrid.com/');
// or
client.setDefaultRequest({baseUrl: 'https://api.sendgrid.com/'});
You can overwrite the promise implementation you want the client to use. Defaults to the ES6 Promise
:
global.Promise = require('bluebird');
const {Client} = require('@sendgrid/client');
const sgClient1 = new Client();
const sgClient2 = new Client();
sgClient1.setApiKey('KEY1');
sgClient2.setApiKey('KEY2');
All updates to this library are documented in our CHANGELOG and releases.
We encourage contribution to our libraries (you might even score some nifty swag), please see our CONTRIBUTING guide for details.
Please see our troubleshooting guide for common library issues.
@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!