### Install Dependencies
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/examples/node/README.md
Run this command in your project's root directory to install all necessary Node.js dependencies.
```bash
npm install
```
--------------------------------
### Install http-proxy
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/dist/README.md
Install the http-proxy package globally using npm. This is required for the browser demo to work.
```sh
npm install -g http-proxy
```
--------------------------------
### Send Email Example
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/docs/index.html
An example demonstrating how to send an email using the `apiConnect` method and the `send` endpoint.
```APIDOC
## Send Email
### Description
Sends an email using the Mailjet API. This example shows how to construct a request with sender, recipient, subject, and content in both plain text and HTML.
### Method
`POST /send`
### Endpoint
`/v3.1/send`
### Parameters
#### Request Body
- **Messages** (array) - An array of message objects to send.
- **From** (object) - Sender information.
- **Email** (string) - Sender's email address.
- **Name** (string) - Sender's name.
- **To** (array) - Array of recipient objects.
- **Email** (string) - Recipient's email address.
- **Name** (string) - Recipient's name.
- **Subject** (string) - The subject of the email.
- **TextPart** (string) - The plain text content of the email.
- **HTMLPart** (string) - The HTML content of the email.
### Request Example
```json
{
"Messages": [
{
"From": {
"Email": "pilot@mailjet.com",
"Name": "Mailjet Pilot"
},
"To": [
{
"Email": "passenger1@mailjet.com",
"Name": "passenger 1"
}
],
"Subject": "Your email flight plan!",
"TextPart": "Dear passenger 1, welcome to Mailjet! May the delivery force be with you!",
"HTMLPart": "
Dear passenger 1, welcome to Mailjet ! May the delivery force be with you!"
}
]
}
```
### Response
#### Success Response (200)
- **body** (object) - Contains the result of the email sending operation.
```
--------------------------------
### Initialize Package
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/dist/README.md
Run this script to perform all essential initialization steps for the project, including installing dependencies and setting up build tools.
```sh
npm run init
```
--------------------------------
### Start Development Server
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/examples/react/README.md
Run the React application in development mode. The app will automatically reload on changes.
```sh
npm start
```
--------------------------------
### Instantiate Mailjet Client
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/dist/README.md
Initialize the Mailjet client with API keys and optional configuration. Use this for basic setup.
```javascript
const mailjet = new Mailjet({
apiKey: process.env.MJ_APIKEY_PUBLIC,
apiSecret: process.env.MJ_APIKEY_PRIVATE,
config: CONFIG,
options: OPTIONS
});
const request = mailjet
.METHOD(RESOURCE, CONFIG)
.request(DATA, PARAMS, PERFORM_API_CALL)
```
--------------------------------
### GET Request - Retrieve All Contacts
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/dist/README.md
Example of how to retrieve all contacts using a GET request.
```APIDOC
## GET /contact
### Description
Retrieves a list of all contacts.
### Method
GET
### Endpoint
/contact
### Parameters
#### Query Parameters
- **IsExcludedFromCampaigns** (boolean) - Optional - Filter contacts by exclusion status.
### Request Example
```json
{}
```
### Response
#### Success Response (200)
Returns a list of contacts.
#### Response Example
```json
[
{
"Email": "passenger1@mailjet.com",
"IsExcludedFromCampaigns": false
},
{
"Email": "passenger2@mailjet.com",
"IsExcludedFromCampaigns": true
}
]
```
```
--------------------------------
### Send Email Example (v3.1)
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/docs/index.html
A comprehensive example demonstrating how to send an email using the Mailjet API v3.1, including request data structure and handling the response.
```APIDOC
## Send Email example
```javascript
import { Client, SendEmailV3_1, LibraryResponse } from 'node-mailjet';
const mailjet = new Client({
apiKey: process.env.MJ_APIKEY_PUBLIC,
apiSecret: process.env.MJ_APIKEY_PRIVATE
});
(async () => {
const data: SendEmailV3_1.Body = {
Messages: [
{
From: {
Email: 'pilot@test.com'
},
To: [
{
Email: 'passenger@test.com'
}
],
TemplateErrorReporting: {
Email: 'reporter@test.com',
Name: 'Reporter'
},
Subject: 'Your email flight plan!',
HTMLPart: 'Dear passenger, welcome to Mailjet! May the delivery force be with you!',
TextPart: 'Dear passenger, welcome to Mailjet! May the delivery force be with you!'
}
]
};
const result: LibraryResponse = await mailjet
.post('send', { version: 'v3.1' })
.request(data);
const { Status } = result.body.Messages[0];
})();
```
And `response` will have this shape:
```json
{
"response": Response,
"body": {
"Messages": [
{
"Status": string,
"Errors": Array>,
"CustomID": string,
"..."
}
]
}
}
```
```
--------------------------------
### Install Node-Mailjet SDK
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/dist/README.md
Install the Mailjet SDK using npm. This is the first step to integrate Mailjet services into your Node.js application.
```sh
npm install node-mailjet
```
--------------------------------
### Install Firebase CLI
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/examples/firebase/README.md
Install the Firebase Command Line Interface globally. This is required for managing and deploying Firebase Functions.
```bash
npm install -g firebase-tools
```
--------------------------------
### Get Contact Information
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/dist/README.md
Example of retrieving contact information using the 'get' method for the 'contact' endpoint. Query parameters can be passed to filter results.
```typescript
import { Client, Contact, LibraryResponse } from 'node-mailjet'
const mailjet = new Client({
apiKey: process.env.MJ_APIKEY_PUBLIC,
apiSecret: process.env.MJ_APIKEY_PRIVATE
});
(async () => {
const queryData: Contact.GetContactQueryParams = {
IsExcludedFromCampaigns: false,
Campaign: 2234234,
};
const result: LibraryResponse = await mailjet
.get('contact', { version: 'v3' })
.request({}, queryData);
const ContactID = result.body.Data[0].ID;
})();
```
--------------------------------
### get
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/docs/classes/index.default.html
Method to perform a GET request.
```APIDOC
## get
### Description
Performs a GET request to the Mailjet API.
### Method
GET
### Endpoint
[Specify endpoint if available in source]
### Parameters
[Specify parameters if available in source]
### Response
[Specify response details if available in source]
```
--------------------------------
### Get Contact
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/README.md
Example of retrieving contact information using the GetContact endpoint. Allows filtering contacts by various parameters.
```APIDOC
## Get Contact
### Description
Retrieves a list of contacts based on specified query parameters.
### Method
`GET`
### Endpoint
`/contact` with version `v3`
### Parameters
#### Query Parameters
- **IsExcludedFromCampaigns** (boolean) - Optional - Filter contacts by exclusion status.
- **Campaign** (number) - Optional - Filter contacts by campaign ID.
### Request Example
```json
{
"IsExcludedFromCampaigns": false,
"Campaign": 2234234
}
```
### Response
#### Success Response (200)
- **Count** (number) - The number of contacts returned in this response.
- **Total** (number) - The total number of contacts matching the query.
- **Data** (Array) - An array of contact objects.
- **ID** (number) - The unique identifier for the contact.
- **IsExcludedFromCampaigns** (boolean) - Indicates if the contact is excluded from campaigns.
- **Name** (string) - The name of the contact.
- **CreatedAt** (string) - Timestamp when the contact was created.
- **DeliveredCount** (number) - Number of emails delivered to this contact.
- **Email** (string) - The email address of the contact.
#### Response Example
```json
{
"response": {},
"body": {
"Count": 1,
"Total": 10,
"Data": [
{
"ID": 12345,
"IsExcludedFromCampaigns": false,
"Name": "John Doe",
"CreatedAt": "2023-01-01T10:00:00Z",
"DeliveredCount": 5,
"Email": "john.doe@example.com"
}
]
}
}
```
```
--------------------------------
### Get Test Coverage
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/dist/README.md
Execute this command to generate a coverage report for the project's tests.
```sh
npm run cover
```
--------------------------------
### Serve Firebase Functions Locally
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/examples/firebase/README.md
Start the Firebase Local Emulator Suite to test your functions on your local machine before deploying. This command should be run from the 'functions' directory.
```bash
firebase serve
```
--------------------------------
### Basic GET Request Structure
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/dist/README.md
Illustrates the general structure for making a GET request using the Mailjet client. The .id() method is used to retrieve a specific object.
```javascript
const request = mailjet
.get($RESOURCE, $CONFIG)
.id($ID)
.request($DATA, $PARAMS, $PERFORM_API_CALL)
```
--------------------------------
### POST Request - Create Contact
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/dist/README.md
Example of how to create a new contact using a POST request.
```APIDOC
## POST /contact
### Description
Creates a new contact in Mailjet.
### Method
POST
### Endpoint
/contact
### Request Body
- **Email** (string) - Required - The email address of the contact.
- **IsExcludedFromCampaigns** (boolean) - Optional - Whether the contact is excluded from campaigns.
- **Name** (string) - Optional - The name of the contact.
### Request Example
```json
{
"Email": "passenger@mailjet.com",
"IsExcludedFromCampaigns": true,
"Name": "New Contact"
}
```
### Response
#### Success Response (200)
Returns the details of the created contact.
#### Response Example
```json
{
"Email": "passenger@mailjet.com",
"IsExcludedFromCampaigns": true,
"Name": "New Contact"
}
```
```
--------------------------------
### Checkout Master and Pull Latest
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/dist/README.md
Before starting the release process, ensure you have the latest changes by checking out the master branch and pulling recent commits.
```sh
git checkout master
git pull
```
--------------------------------
### Mailjet Client Instantiation and API Call
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/docs/index.html
Instantiate the Mailjet client with API keys, configuration, and options. Demonstrates a generic API call structure using methods like `post`, `put`, `get`, or `delete`.
```javascript
const mailjet = new Mailjet({
apiKey: process.env.MJ_APIKEY_PUBLIC,
apiSecret: process.env.MJ_APIKEY_PRIVATE,
config: CONFIG,
options: OPTIONS
});
const request = mailjet
.METHOD(RESOURCE, CONFIG)
.request(DATA, PARAMS, PERFORM_API_CALL)
```
--------------------------------
### POST Request - Manage Contact Subscriptions
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/README.md
Example of how to manage a contact's subscription status to multiple lists using a POST request.
```APIDOC
## POST /contact/{contactID}/managecontactslists
### Description
Manages the subscription status of a contact to multiple lists.
### Method
POST
### Endpoint
/contact/{contactID}/managecontactslists
### Parameters
#### Path Parameters
- **contactID** (string) - Required - The ID of the contact.
#### Request Body
- **ContactsLists** (array) - Required - A list of contact list actions.
- **ListID** (string) - Required - The ID of the list.
- **Action** (string) - Required - The action to perform (e.g., "addnoforce").
### Request Example
```json
{
"ContactsLists": [
{
"ListID": "$listID",
"Action": "addnoforce"
}
]
}
```
### Response
#### Success Response (200)
Details of the subscription status update.
#### Response Example
```json
{
"Status": "success"
}
```
```
--------------------------------
### POST Request - Manage Contact Lists
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/dist/README.md
Example of how to manage a contact's subscription status to multiple lists using a POST request with actions.
```APIDOC
## POST /contact/{contactID}/managecontactslists
### Description
Manages the subscription status of a contact to multiple lists.
### Method
POST
### Endpoint
/contact/{contactID}/managecontactslists
### Parameters
#### Path Parameters
- **contactID** (string) - Required - The ID of the contact.
#### Request Body
- **ContactsLists** (array) - Required - A list of contact list actions.
- **ListID** (string) - Required - The ID of the list.
- **Action** (string) - Required - The action to perform (e.g., "addnoforce").
### Request Example
```json
{
"ContactsLists": [
{
"ListID": "$listID",
"Action": "addnoforce"
}
]
}
```
### Response
#### Success Response (200)
Returns the result of the contact list management operation.
#### Response Example
```json
{
"Status": "success"
}
```
```
--------------------------------
### SendStartAt
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/docs/interfaces/types_api_Campaign.SentCampaign.Campaign.html
Specifies the start date and time for sending a campaign. It is a string value, typically in ISO format.
```APIDOC
## Type: SendStartAt
### Description
Specifies the date and time when the campaign sending is scheduled to start. This is represented as a string.
### Type
`string`
```
--------------------------------
### Send Email using SendEmailV3_1 API in TypeScript
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/docs/index.html
An example demonstrating how to send an email using the SendEmailV3_1 API. It includes setting up the client, defining the email data, and making the request. The response structure is also outlined.
```typescript
import { Client, SendEmailV3_1, LibraryResponse } from 'node-mailjet';
const mailjet = new Client({
apiKey: process.env.MJ_APIKEY_PUBLIC,
apiSecret: process.env.MJ_APIKEY_PRIVATE,
});
(async () => {
const data: SendEmailV3_1.Body = {
Messages: [
{
From: {
Email: 'pilot@test.com',
},
To: [
{
Email: 'passenger@test.com',
},
],
TemplateErrorReporting: {
Email: 'reporter@test.com',
Name: 'Reporter',
},
Subject: 'Your email flight plan!',
HTMLPart: 'Dear passenger, welcome to Mailjet! May the delivery force be with you!',
TextPart: 'Dear passenger, welcome to Mailjet! May the delivery force be with you!',
},
],
};
const result: LibraryResponse = await mailjet
.post('send', { version: 'v3.1' })
.request(data);
const { Status } = result.body.Messages[0];
})();
```
--------------------------------
### Send Email using SendEmailV3_1
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/dist/README.md
Example of sending an email using the SendEmailV3_1 endpoint. Ensure your API keys are set in environment variables.
```typescript
import { Client, SendEmailV3_1, LibraryResponse } from 'node-mailjet';
const mailjet = new Client({
apiKey: process.env.MJ_APIKEY_PUBLIC,
apiSecret: process.env.MJ_APIKEY_PRIVATE
});
(async () => {
const data: SendEmailV3_1.Body = {
Messages: [
{
From: {
Email: 'pilot@test.com',
},
To: [
{
Email: 'passenger@test.com',
},
],
TemplateErrorReporting: {
Email: 'reporter@test.com',
Name: 'Reporter',
},
Subject: 'Your email flight plan!',
HTMLPart: 'Dear passenger, welcome to Mailjet! May the delivery force be with you!',
TextPart: 'Dear passenger, welcome to Mailjet! May the delivery force be with you!',
},
],
};
const result: LibraryResponse = await mailjet
.post('send', { version: 'v3.1' })
.request(data);
const { Status } = result.body.Messages[0];
})();
```
--------------------------------
### Run http-server with Proxy
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/dist/README.md
Start the http-server from the mailjet-apiv3-nodejs directory, configuring it to proxy requests to the Mailjet API. This is necessary for the browser demo to bypass CORS restrictions.
```sh
http-server -p 4001 --proxy="https://api.mailjet.com"
```
--------------------------------
### SMS API - Send SMS Example
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/dist/README.md
This snippet shows how to authenticate with the SMS API using a Bearer token and send an SMS message.
```APIDOC
## SMS API - Send SMS
### Description
This endpoint allows you to send SMS messages using the Mailjet SMS API. Authentication is handled via a Bearer token.
### Method
POST
### Endpoint
`/sms-send`
### Parameters
#### Query Parameters
None explicitly mentioned for this operation.
#### Request Body
- **Text** (string) - Required - The content of the SMS message.
- **To** (string) - Required - The recipient's phone number.
- **From** (string) - Required - The sender ID or phone number.
### Request Example
```javascript
const Mailjet = require('node-mailjet');
const mailjet = Mailjet.smsConnect(process.env.MJ_API_TOKEN, {
config: {
version: 'v4'
}
});
const request = mailjet
.post('sms-send')
.request({
Text: "Have a nice SMS flight with Mailjet !",
To: "+33600000000",
From: "MJPilot"
})
request
.then((result) => {
console.log(result.body)
})
.catch((err) => {
console.log(err.statusCode)
})
```
### Response
#### Success Response (200)
- **body** (object) - Contains the response details of the SMS sending operation.
```
--------------------------------
### Send Message v3
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/README.md
Example of sending a simple message using the SendMessage endpoint. This is a more basic method compared to SendEmailV3_1.
```APIDOC
## Send Message v3
### Description
Sends a basic message using the v3 API version. Suitable for simpler text-based messages.
### Method
`POST`
### Endpoint
`/contact` with version `v3`
### Request Body
- **From** (string) - Required - Sender's email address.
- **To** (string) - Required - Recipient's email address.
- **Text** (string) - Required - The text content of the message.
### Request Example
```json
{
"From": "some@email.com",
"To": "some2@email.com",
"Text": "Test"
}
```
### Response
#### Success Response (200)
- **From** (string) - Sender's email.
- **To** (string) - Recipient's email.
- **Text** (string) - The sent text content.
- **MessageID** (string | number) - The unique identifier for the message.
- **SMSCount** (number) - The number of SMS messages sent.
- **CreationTS** (number) - Timestamp of message creation.
- **SentTS** (number) - Timestamp when the message was sent.
- **Cost** (Object) - Cost details of the message.
- **Value** (number) - The cost value.
- **Currency** (string) - The currency of the cost.
- **Status** (Object) - The status of the message.
- **Code** (number) - Status code.
- **Name** (string) - Status name.
- **Description** (string) - Description of the status.
#### Response Example
```json
{
"response": {},
"body": {
"From": "some@email.com",
"To": "some2@email.com",
"Text": "Test",
"MessageID": 12345,
"SMSCount": 1,
"CreationTS": 1678886400,
"SentTS": 1678886405,
"Cost": {
"Value": 0.05,
"Currency": "EUR"
},
"Status": {
"Code": 200,
"Name": "success",
"Description": "Message sent successfully"
}
}
}
```
```
--------------------------------
### Send Email v3.1
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/README.md
Example of sending an email using the SendEmailV3_1 endpoint. This method allows for detailed email content, including HTML and text parts, and template error reporting.
```APIDOC
## Send Email v3.1
### Description
Sends an email using the v3.1 API version. Supports HTML and Text parts, and template error reporting.
### Method
`POST`
### Endpoint
`/send` with version `v3.1`
### Request Body
- **Messages** (Array) - Required - An array of message objects to be sent.
- **From** (Object) - Required - Sender's email address.
- **Email** (string) - Required - Sender's email.
- **To** (Array) - Required - Recipient list.
- **Email** (string) - Required - Recipient's email.
- **TemplateErrorReporting** (Object) - Optional - Email address for error reports.
- **Email** (string) - Required - Error reporting email.
- **Name** (string) - Optional - Name for error reporting.
- **Subject** (string) - Required - Email subject.
- **HTMLPart** (string) - Required - Email content in HTML format.
- **TextPart** (string) - Required - Email content in plain text format.
### Request Example
```json
{
"Messages": [
{
"From": {
"Email": "pilot@test.com"
},
"To": [
{
"Email": "passenger@test.com"
}
],
"TemplateErrorReporting": {
"Email": "reporter@test.com",
"Name": "Reporter"
},
"Subject": "Your email flight plan!",
"HTMLPart": "Dear passenger, welcome to Mailjet! May the delivery force be with you!",
"TextPart": "Dear passenger, welcome to Mailjet! May the delivery force be with you!"
}
]
}
```
### Response
#### Success Response (200)
- **Messages** (Array) - An array containing the status of each sent message.
- **Status** (string) - The status of the message (e.g., 'success').
- **Errors** (Array) - An array of errors encountered, if any.
- **CustomID** (string) - A custom ID associated with the message.
#### Response Example
```json
{
"response": {},
"body": {
"Messages": [
{
"Status": "success",
"Errors": [],
"CustomID": "some-custom-id"
}
]
}
}
```
```
--------------------------------
### Send Email using Mailjet Node.js SDK
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/README.md
Send an email using the Mailjet Node.js SDK. This example demonstrates setting sender, recipient, subject, and content in both plain text and HTML.
```javascript
const Mailjet = require('node-mailjet');
const mailjet = Mailjet.apiConnect(
process.env.MJ_APIKEY_PUBLIC,
process.env.MJ_APIKEY_PRIVATE,
);
const request = mailjet
.post('send', { version: 'v3.1' })
.request({
Messages: [
{
From: {
Email: "pilot@mailjet.com",
Name: "Mailjet Pilot"
},
To: [
{
Email: "passenger1@mailjet.com",
Name: "passenger 1"
}
],
Subject: "Your email flight plan!",
TextPart: "Dear passenger 1, welcome to Mailjet! May the delivery force be with you!",
HTMLPart: "Dear passenger 1, welcome to Mailjet ! May the delivery force be with you!"
}
]
});
request
.then((result) => {
console.log(result.body)
})
.catch((err) => {
console.log(err.statusCode)
})
```
--------------------------------
### DELETE Request Example
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/dist/README.md
This snippet demonstrates how to delete a resource, such as an email template, using the Mailjet Node.js SDK. It shows the basic structure of a DELETE request and how to handle the response.
```APIDOC
## DELETE Request
### Description
This endpoint allows for the deletion of a specific resource.
### Method
DELETE
### Endpoint
`/resource/{id}`
### Parameters
#### Path Parameters
- **id** (string) - Required - The unique identifier of the object to delete.
#### Request Body
- **DATA** (object) - Empty for DELETE requests.
### Request Example
```javascript
const Mailjet = require('node-mailjet');
const mailjet = new Mailjet({
apiKey: process.env.MJ_APIKEY_PUBLIC,
apiSecret: process.env.MJ_APIKEY_PRIVATE
});
const request = mailjet
.delete('template')
.id($templateID)
.request()
request
.then((result) => {
console.log(result.body)
})
.catch((err) => {
console.log(err.statusCode)
})
```
### Response
#### Success Response (204)
No Content. The request was successful, but there is no response body.
```
--------------------------------
### Client Initialization with Config
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/docs/index.html
Demonstrates how to initialize the Mailjet client with custom configuration options for host, API version, and output format.
```APIDOC
## Client Initialization with Config
You can pass `config` on init `client` and this `config` will use for each `request`:
```javascript
const mailjet = new Mailjet({
apiKey: process.env.MJ_APIKEY_PUBLIC,
apiSecret: process.env.MJ_APIKEY_PRIVATE,
config: {
host: 'api.mailjet.com',
version: 'v3',
output: 'text',
}
});
```
```
--------------------------------
### GET Request - Retrieve Specific Contact
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/dist/README.md
Example of how to retrieve a specific contact by its ID using a GET request.
```APIDOC
## GET /contact/{contactID}
### Description
Retrieves a specific contact by its ID.
### Method
GET
### Endpoint
/contact/{contactID}
### Parameters
#### Path Parameters
- **contactID** (string) - Required - The ID of the contact to retrieve.
### Request Example
```json
{}
```
### Response
#### Success Response (200)
Returns the details of the specified contact.
#### Response Example
```json
{
"Email": "passenger@mailjet.com",
"IsExcludedFromCampaigns": false,
"Name": "John Doe"
}
```
```
--------------------------------
### Build for Prepublish
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/examples/react/README.md
Prepare the library for publishing after building development bundles.
```sh
npm run build:prepublish
```
--------------------------------
### Filter Contacts with Mailjet GET Request
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/docs/index.html
Retrieve contacts using a `GET` request with query parameters. This example filters contacts to exclude those in the campaign exclusion list by passing `{ IsExcludedFromCampaigns: false }` as parameters.
```javascript
const Mailjet = require('node-mailjet')
const mailjet = new Mailjet({
apiKey: process.env.MJ_APIKEY_PUBLIC,
apiSecret: process.env.MJ_APIKEY_PRIVATE
});
const request = mailjet
.get('contact')
.request({}, { IsExcludedFromCampaigns: false })
request
.then((result) => {
console.log(result.body)
})
.catch((err) => {
console.log(err.statusCode)
})
```
--------------------------------
### Constructor
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/docs/classes/client.default.html
Initializes a new instance of the default Mailjet client.
```APIDOC
## constructor
### Description
Initializes a new instance of the default Mailjet client.
### Parameters
#### params
- **params** (ClientParams) - Required - The parameters for initializing the client.
### Returns
- **default** - A new instance of the default client.
```
--------------------------------
### Build for Release
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/dist/README.md
Execute this command to build the project for release, which includes minimizing the code.
```sh
npm run build
```
--------------------------------
### GET Request - Retrieve All Contacts
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/docs/index.html
Retrieves a list of all contacts in the Mailjet account using the `get` method without any specific filters.
```APIDOC
## GET /contact
### Description
Retrieves a list of all contacts.
### Method
GET
### Endpoint
/contact
### Response
#### Success Response (200)
A list of contact objects.
#### Response Example
```json
[
{
"ID": "123",
"Email": "test@example.com"
}
]
```
```
--------------------------------
### Create Environment File
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/examples/node/README.md
Create a .env file based on the .env.sample file, replacing placeholders with your actual Mailjet API credentials.
```bash
cp .env.sample .env
```
--------------------------------
### Run User Info Script
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/examples/node/README.md
Execute this command to retrieve user information using the prepared script.
```bash
npm run start:user
```
--------------------------------
### Configuration and Options
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/docs/classes/client.default.html
Methods for managing client configuration and options.
```APIDOC
## getConfig
### Description
Retrieves the current configuration of the client.
### Returns
- **RequestConfig** - The client's request configuration.
```
```APIDOC
## getOptions
### Description
Retrieves the current options of the client.
### Returns
- **RequestOptions** - The client's request options.
```
```APIDOC
## setConfig
### Description
Sets the configuration for the client.
### Parameters
#### config
- **config** (RequestConfig) - Required - The new request configuration.
### Returns
- **this** - The client instance for chaining.
```
```APIDOC
## setOptions
### Description
Sets the options for the client.
### Parameters
#### options
- **options** (RequestOptions) - Required - The new request options.
### Returns
- **this** - The client instance for chaining.
```
--------------------------------
### Client Instantiation
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/dist/README.md
Instantiate the Mailjet client with your API keys and optional configuration.
```APIDOC
## Client Instantiation
### Description
Instantiate the Mailjet client with your API keys and optional configuration.
### Code
```javascript
const mailjet = new Mailjet({
apiKey: process.env.MJ_APIKEY_PUBLIC,
apiSecret: process.env.MJ_APIKEY_PRIVATE,
config: CONFIG,
options: OPTIONS
});
```
```
--------------------------------
### GET Request with Mailjet Client
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/docs/index.html
Use the `get` method to retrieve data from the Mailjet API. The `$PARAMS` parameter in `.request` can contain query parameters for filtering. Define `.id` to retrieve a specific object.
```javascript
const Mailjet = require('node-mailjet')
const mailjet = new Mailjet({
apiKey: process.env.MJ_APIKEY_PUBLIC,
apiSecret: process.env.MJ_APIKEY_PRIVATE
});
const request = mailjet
.get('contact')
.request()
request
.then((result) => {
console.log(result.body)
})
.catch((err) => {
console.log(err.statusCode)
})
```
--------------------------------
### constructor
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/docs/classes/index.default.html
Initializes a new instance of the default class with the provided parameters.
```APIDOC
## constructor
### Description
Initializes a new instance of the default class.
### Parameters
* **params** (ClientParams) - Required - Parameters for the client.
### Returns
* **default** - An instance of the default class.
```
--------------------------------
### Retrieve Single Contact with Mailjet GET Request
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/docs/index.html
Retrieve a specific contact by its ID using the `get` method and chaining `.id($contactID)`. The `.request()` method is called without additional parameters for a direct retrieval.
```javascript
const Mailjet = require('node-mailjet')
const mailjet = new Mailjet({
apiKey: process.env.MJ_APIKEY_PUBLIC,
apiSecret: process.env.MJ_APIKEY_PRIVATE
});
const request = mailjet
.get('contact')
.id($contactID)
.request()
request
.then((result) => {
console.log(result.body)
})
.catch((err) => {
console.log(err.statusCode)
})
```
--------------------------------
### Run Release
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/dist/README.md
Execute this command to perform the release process, including updating the changelog and versioning.
```sh
npm run release
```
--------------------------------
### Build for Development
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/dist/README.md
Use these commands to build the project for development purposes, excluding code minimization, and preparing for pre-publication.
```sh
npm run build:dev && npm run build:prepublish
```
--------------------------------
### get
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/docs/classes/index.default.html
Retrieves a resource from the Mailjet API.
```APIDOC
## get
### Description
Retrieves a resource from the Mailjet API.
### Method
GET
### Endpoint
/[resource]
### Parameters
#### Path Parameters
- **resource** (string) - Required - The resource to retrieve.
#### Query Parameters
- **config** (RequestConstructorConfig) - Optional - Configuration for the request.
### Returns
- [default](request.default.html)
```
--------------------------------
### getUserAgent
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/docs/classes/request.default.html
Gets the user agent string for the request.
```APIDOC
## getUserAgent
### Description
Gets the user agent string for the request.
### Returns
- **string** - The user agent string.
```
--------------------------------
### Initialize Mailjet Client
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/README.md
Instantiate the Mailjet client with API keys and optional configuration. Use environment variables for sensitive credentials.
```javascript
const mailjet = new Mailjet({
apiKey: process.env.MJ_APIKEY_PUBLIC,
apiSecret: process.env.MJ_APIKEY_PRIVATE,
config: CONFIG,
options: OPTIONS
});
```
--------------------------------
### Get Email Templates
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/examples/browser/www/index.html
Retrieves a list of all email templates and their configuration settings.
```APIDOC
## GET /template
### Description
Retrieve a list of all templates and their configuration settings.
### Method
GET
### Endpoint
/template
### Parameters
#### Query Parameters
- **filters** (object) - Optional - Allows filtering of templates.
### Request Example
```json
{
"filters": {
"Name": "Welcome Email"
}
}
```
### Response
#### Success Response (200)
- **Count** (integer) - The total number of templates returned.
- **Total** (integer) - The total number of templates available matching the filter.
- **Data** (array) - An array of template objects.
- **ID** (integer) - The unique identifier for the template.
- **Name** (string) - The name of the template.
- **Subject** (string) - The subject line of the template.
- **CreatedAt** (string) - The timestamp when the template was created.
#### Response Example
```json
{
"Count": 1,
"Total": 1,
"Data": [
{
"ID": 44556,
"Name": "Welcome Email",
"Subject": "Welcome to our service!",
"CreatedAt": "2023-10-27T10:00:00Z"
}
]
}
```
```
--------------------------------
### Get Contacts
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/examples/browser/www/index.html
Retrieves a list of all contacts, including their status and creation/activity timestamps.
```APIDOC
## GET /contact
### Description
Retrieve a list of all contacts. Includes information about contact status and creation / activity timestamps.
### Method
GET
### Endpoint
/contact
### Parameters
#### Query Parameters
- **filters** (object) - Optional - Allows filtering of contacts.
### Request Example
```json
{
"filters": {
"IsExcludedFromCampaigns": "false"
}
}
```
### Response
#### Success Response (200)
- **Count** (integer) - The total number of contacts returned.
- **Total** (integer) - The total number of contacts available matching the filter.
- **Data** (array) - An array of contact objects.
- **ID** (integer) - The unique identifier for the contact.
- **Email** (string) - The contact's email address.
- **Status** (string) - The current status of the contact (e.g., 'subscribed', 'unsubscribed').
- **CreatedAt** (string) - The timestamp when the contact was created.
- **UpdatedAt** (string) - The timestamp when the contact was last updated.
#### Response Example
```json
{
"Count": 1,
"Total": 1,
"Data": [
{
"ID": 67890,
"Email": "contact@example.com",
"Status": "subscribed",
"CreatedAt": "2023-10-27T10:00:00Z",
"UpdatedAt": "2023-10-27T10:00:00Z"
}
]
}
```
```
--------------------------------
### getOptions
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/docs/classes/index.default.html
Retrieves the client options.
```APIDOC
## getOptions
### Description
Retrieves the options configured for the Mailjet client.
### Returns
* **[ClientOptions](../interfaces/client_Client.ClientOptions.html)** - The client options object.
```
--------------------------------
### Get Contact Lists
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/docs/modules/types_api_Contact.ContactList.html
Retrieves a list of contact lists. Supports filtering and pagination.
```APIDOC
## GET /contactlist
### Description
Retrieves a list of contact lists. Supports filtering and pagination.
### Method
GET
### Endpoint
/contactlist
### Parameters
#### Query Parameters
- **Address** (string) - Optional - Filter by email address.
- **ExcludeID** (number) - Optional - Exclude a specific contact list ID.
- **IsDeleted** (boolean) - Optional - Filter by deleted status.
- **Name** (string) - Optional - Filter by contact list name.
- **Limit** (number) - Optional - Number of results to return.
- **Offset** (number) - Optional - Offset for pagination.
### Response
#### Success Response (200)
- **Count** (number) - The total number of contact lists.
- **Data** (array) - An array of contact list objects.
### Response Example
{
"Count": 1,
"Data": [
{
"ID": 12345,
"Name": "My Test List",
"IsDeleted": false,
"CreatedAt": "2023-10-27T10:00:00Z",
"UpdatedAt": "2023-10-27T10:00:00Z"
}
]
}
```
--------------------------------
### Build with Watch and Hot-Reload
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/dist/README.md
Run this script to build the project with watching enabled for hot-reloading during development.
```sh
npm run build:watch
```
--------------------------------
### GetCampaignOverview
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/docs/modules/types_api_Statistic.Statistic.html
Retrieves an overview of campaign statistics. This endpoint allows you to get a summary of campaign performance.
```APIDOC
## GetCampaignOverview
### Description
Retrieves an overview of campaign statistics.
### Method
GET
### Endpoint
/campaignoverview
### Parameters
#### Query Parameters
- **CampaignsList** (string) - Optional - List of Campaign IDs to filter results.
- **StartDate** (string) - Optional - Start date for the statistics.
- **EndDate** (string) - Optional - End date for the statistics.
### Response
#### Success Response (200)
- **CampaignOverview[]** (Array of CampaignOverview objects) - Contains detailed campaign statistics.
```
--------------------------------
### Constructor
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/docs/classes/request.default.html
Initializes a new instance of the Request class. It takes the Mailjet client, HTTP method, resource name, and optional configuration as arguments.
```APIDOC
## constructor
### Description
Initializes a new instance of the Request class.
### Parameters
* **client**: [default](client.default.html) - The Mailjet client instance.
* **method**: [default](../enums/request_HttpMethods.default.html) - The HTTP method for the request (e.g., GET, POST).
* **resource**: string - The Mailjet API resource to interact with.
* **config?**: [RequestConstructorConfig](../modules/request_Request.html#RequestConstructorConfig) - Optional configuration for the request.
### Returns
* [default](request.default.html) - A new instance of the Request class.
```
--------------------------------
### Configure Client with Options
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/dist/README.md
Instantiate the Mailjet client with a comprehensive set of options, including timeout, body/content length limits, custom headers, and proxy configuration. These options apply to all subsequent requests.
```javascript
const mailjet = new Mailjet({
apiKey: process.env.MJ_APIKEY_PUBLIC,
apiSecret: process.env.MJ_APIKEY_PRIVATE,
options: {
timeout: 1000,
maxBodyLength: 1500,
maxContentLength: 100,
headers: {
'X-API-Key': 'foobar',
},
proxy: {
protocol: 'http',
host: 'www.test-proxy.com',
port: 3100,
}
}
});
```
--------------------------------
### Run Sender Info Script
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/examples/node/README.md
Execute this command to retrieve sender information by email using the prepared script.
```bash
npm run start:sender
```
--------------------------------
### Publish to npm
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/dist/README.md
After completing the release process and navigating to the `dist` directory, log in to npm and publish the package.
```sh
npm login
npm publish
```
--------------------------------
### Get Open Statistics
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/examples/browser/www/index.html
Retrieves a list of all open events and details about them, including message, campaign, and contact IDs, and timestamp.
```APIDOC
## GET /openinformation
### Description
Retrieve a list of all open events and details about them - message, campaign and contact IDs, timestamp etc.
### Method
GET
### Endpoint
/openinformation
### Parameters
#### Query Parameters
- **filters** (object) - Optional - Allows filtering of open statistics.
### Request Example
```json
{
"filters": {
"CampaignID": "12345"
}
}
```
### Response
#### Success Response (200)
- **Count** (integer) - The total number of open events returned.
- **Total** (integer) - The total number of open events available matching the filter.
- **Data** (array) - An array of open event objects.
- **MessageID** (integer) - The ID of the message associated with the open.
- **CampaignID** (integer) - The ID of the campaign associated with the open.
- **ContactID** (integer) - The ID of the contact who opened the message.
- **EventTimestamp** (string) - The timestamp when the open event occurred.
#### Response Example
```json
{
"Count": 1,
"Total": 1,
"Data": [
{
"MessageID": 12345,
"CampaignID": 9876,
"ContactID": 67890,
"EventTimestamp": "2023-10-27T10:02:00Z"
}
]
}
```
```
--------------------------------
### Get Click Statistics
Source: https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/examples/browser/www/index.html
Retrieves a list of all click events and details about them, including message and contact IDs, timestamp, and URL.
```APIDOC
## GET /clickstatistics
### Description
Retrieve a list of all click events and details about them - message and contact IDs, timestamp, URL and click delay.
### Method
GET
### Endpoint
/clickstatistics
### Parameters
#### Query Parameters
- **filters** (object) - Optional - Allows filtering of click statistics.
### Request Example
```json
{
"filters": {
"StartDate": "2023-10-26T00:00:00Z"
}
}
```
### Response
#### Success Response (200)
- **Count** (integer) - The total number of click events returned.
- **Total** (integer) - The total number of click events available matching the filter.
- **Data** (array) - An array of click event objects.
- **MessageID** (integer) - The ID of the message associated with the click.
- **ContactID** (integer) - The ID of the contact who clicked the link.
- **EventTimestamp** (string) - The timestamp when the click event occurred.
- **URL** (string) - The URL that was clicked.
- **ClickDelay** (integer) - The delay in seconds between sending and clicking.
#### Response Example
```json
{
"Count": 1,
"Total": 1,
"Data": [
{
"MessageID": 12345,
"ContactID": 67890,
"EventTimestamp": "2023-10-27T10:05:00Z",
"URL": "https://example.com/link",
"ClickDelay": 300
}
]
}
```
```