### Install Node Dependencies
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
Install all necessary Node.js dependencies for the project. This is a standard step for Node.js projects.
```sh
npm install
```
--------------------------------
### Webhook Get Response Example
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
This is an example of the JSON response structure when retrieving details for a specific webhook.
```JS
{
'open': { 'url': 'http://requestb.in', 'urls': ['trackclick.com'] }
}
```
--------------------------------
### Webhook Create Response Example
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
This is an example of the JSON response structure after successfully creating a webhook.
```JS
{
'open': { 'url': 'http://requestb.in', 'urls': ['http://requestb.in'] }
}
```
--------------------------------
### Example Get Mailing List Response Structure
Source: https://github.com/mailgun/mailgun.js/blob/master/README.md
Illustrates the typical JSON structure returned when getting a specific mailing list.
```json
{
access_level: 'readonly',
address: 'noreply@sample.com',
created_at: 'Thu, 28 Oct 2021 00:16:56 -0000',
description: '',
members_count: 0,
name: '',
reply_preference: 'list'
}
```
--------------------------------
### Proxy Configuration Example
Source: https://github.com/mailgun/mailgun.js/blob/master/docs/README.md
Example of configuring the SDK to use a proxy for network requests. Authentication details for the proxy can be optionally provided.
```js
import Mailgun from 'mailgun.js';
const mailgun = new Mailgun(FormData);// or import FormData from 'form-data';
const mg = mailgun.client({
username: 'api',
key: process.env.MAILGUN_API_KEY || 'MAILGUN_API_KEY',
proxy: {
protocol: 'https' // 'http' ,
host: '127.0.0.1', // use your proxy host here
port: 9000, // use your proxy port here
auth: { // may be omitted if proxy doesn't require authentication
username: 'user_name', // provide username
password: 'user_password' // provide password
},
},
});
```
--------------------------------
### Browser File Input Handling
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
Example of handling file selection in a browser using an input tag. It shows how to get the file Blob from the event.
```javascript
const handleFileSelected = async (event) => {
const files = Array.from(event.target.files)
const fileBuffer = await files[0];
}
```
--------------------------------
### Install http-proxy
Source: https://github.com/mailgun/mailgun.js/blob/master/examples/index.html
Install the http-proxy package globally using npm. This is required to set up a local proxy for Mailgun API requests.
```bash
npm install -g http-proxy
```
--------------------------------
### Install Mailgun.js SDK
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
Install the mailgun.js package using npm. This command is for Node.js environments.
```SH
npm install mailgun.js
```
--------------------------------
### Example Domain Object with Extended and DNS Info
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
This is an example of a domain object returned when requesting extended details and DNS records.
```json
{
name: 'testing.example.com',
require_tls: true,
skip_verification: true,
state: 'unverified',
wildcard: true,
spam_action: 'disabled',
created_at: new Date('Sun, 19 Oct 2014 18:49:36 GMT'),
smtp_password: undefined,
smtp_login: 'postmaster@testing.example.com',
type: 'custom',
receiving_dns_records: [ // may be null if with_dns is set to false.
{
is_active: true,
cached: [],
priority: '10',
record_type: 'TXT',
valid: "unknown",
value: "dns_record_value"
},
...
],
sending_dns_records: [ // may be null if with_dns is set to false.
{
is_active: true,
cached: [],
name: 'dns_record_name',
record_type: 'CNAME',
valid: 'unknown',
value: 'dns_record_value'
},
...
],
id: '697d01d38712cf0322bb24d1',
is_disabled: false,
web_prefix: 'email',
web_scheme: 'http',
use_automatic_sender_security: true,
dkim_host: 'dkim_host_value', // absent if 'extended' was not set to true.
mailfrom_host: 'mailfrom_host_value', // absent if 'extended' was not set to true.
}
```
--------------------------------
### Domain Template with Active Version Object Structure
Source: https://github.com/mailgun/mailgun.js/blob/master/docs/README.md
Example structure of a domain template object including its active version, as returned by the 'get' method.
```json
{
name: 'template_name',
description: 'This is the description of the template',
createdAt: new Date('2021-08-24T22:26:55.000Z'),
createdBy: '',
id: '46565d87-68b6-4edb-8b3c-34554af4bb77',
version: {
tag: 'tag',
template: 'template content',
engine: 'handlebars',
mjml: '',
createdAt: new Date('2021-08-22T22:26:55.000Z'),
comment: 'Version comment',
active: true,
id: '3efd2b85-0f41-4a1d-9898-05d7e7459c4a',
headers: {
From: 'from value'
}
}
}
```
--------------------------------
### Webhook List Response Example
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
This is an example of the JSON response structure when listing webhooks for a domain.
```JS
{
open: { 'url': 'http://requestb.in' },
click: { 'url': 'http://requestb.in' },
bounce: { 'url': 'http://requestb.in' },
deliver: { 'url': 'http://requestb.in' },
drop: { 'url': 'http://requestb.in' },
spam: { 'url': 'http://requestb.in' },
unsubscribe: { 'url': 'http://requestb.in' },
click: { 'url': 'http://requestb.in' },
open: { 'url': 'http://requestb.in' },
}
```
--------------------------------
### Domain Object Example
Source: https://github.com/mailgun/mailgun.js/blob/master/README.md
An example of the structure of a domain object returned by the API. This includes details like name, state, and DNS record information.
```javascript
[{
name: 'testing.example.com',
require_tls: true,
skip_verification: true,
state: 'unverified',
wildcard: true,
spam_action: 'disabled',
created_at: 'Sun, 19 Oct 2014 18:49:36 GMT',
smtp_password: undefined,
smtp_login: 'postmaster@testing.example.com',
type: 'custom',
receiving_dns_records: null,
sending_dns_records: null,
id: '697d01d38712cf0322bb24d1',
is_disabled: false,
web_prefix: 'test',
web_scheme: 'https',
use_automatic_sender_security: true
}]
```
--------------------------------
### Create Bounce Suppression Response Example
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
Example response after successfully creating a bounce suppression entry.
```js
{
message: "1 address has been added to the bounces table"
}
```
--------------------------------
### Get Suppression Response Example
Source: https://github.com/mailgun/mailgun.js/blob/master/docs/README.md
Example of the JSON response when retrieving a single suppression record.
```json
{
"type": "bounces",
"address": "address?@unknown.com",
"tags": [ "*" ],
"created_at": "Fri Oct 21 2011 05:02:55 GMT-0700 (PDT)"
}
```
--------------------------------
### Get Suppression Response Example
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
Example structure of the response when retrieving a single suppression entry.
```JS
{
type: "bounces",
address: "address?@unknown.com",
tags: [ "*" ],
created_at: Fri Oct 21 2011 05:02:55 GMT-0700 (PDT)
}
```
--------------------------------
### Example Create Mailing List Response Structure
Source: https://github.com/mailgun/mailgun.js/blob/master/README.md
Illustrates the typical JSON structure returned after creating a mailing list.
```json
{
access_level: 'readonly',
address: 'reply@sample.com',
created_at: 'Thu, 28 Oct 2021 03:12:17 -0000',
description: 'Mailing lists for repliable address',
members_count: 0,
name: 'Reply Address',
reply_preference: 'list'
}
```
--------------------------------
### Test Webhook Creation
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
This example demonstrates how to test the creation of a webhook. It sends a test request to the specified URL.
```JS
mg.webhooks.get('foobar.example.com', 'open', 'http://requestb.in', true) // bounce, deliver, drop, spam, unsubscribe, click, open
.then(msg => console.log(msg)) // logs response data
.catch(err => console.error(err)); // logs any error
```
--------------------------------
### Get Account Metrics
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
Retrieves filtered metrics for an account. Use this to get data like 'opened_count' for a specific domain and time range. The method accepts a query object with start and end dates, resolution, metrics to include, and filtering options.
```javascript
mg.metrics.getAccount({
start: '2024-12-16T10:47:51.661Z',
end: '2024-12-23T10:47:51.661Z',
resolution: 'hour',
metrics: ['opened_count'],
filter: {
AND: [{
attribute: 'domain',
comparator: 'contains',
values: [{
value: 'mailgun'
}]
}]
},
include_subaccounts: true,
include_aggregates: true
})
.then(data => console.log(data)) // logs response data
.catch(err => console.error(err)); //logs any error
```
--------------------------------
### create
Source: https://github.com/mailgun/mailgun.js/blob/master/docs/interfaces/definitions.Interfaces.IDomainKeysClient.md
Creates a new domain key.
```APIDOC
## create
### Description
Creates a new domain key.
### Method
POST (Assumed based on typical API patterns for creation)
### Endpoint
/domains/{domain}/keys (Assumed based on typical API patterns)
### Parameters
#### Request Body
- **data** (DomainKeyCreateData) - Required - The data for creating the domain key.
### Returns
`Promise`
#### Success Response (200)
- **DomainKeyCreateDataResult** - The result of the domain key creation.
```
--------------------------------
### constructor
Source: https://github.com/mailgun/mailgun.js/blob/master/docs/classes/index.default.md
Initializes a new instance of the default class with form data.
```APIDOC
## constructor `new default(FormData)`
### Description
Initializes a new instance of the default class.
### Parameters
#### Parameters
- **FormData** (InputFormData) - Description of the FormData parameter.
#### Defined in
[index.ts:9](https://github.com/mailgun/mailgun.js/blob/428d668/lib/index.ts#L9)
```
--------------------------------
### Setup Mailgun Client (Node.js)
Source: https://github.com/mailgun/mailgun.js/blob/master/docs/README.md
Instantiate the Mailgun client with your API key. For Node.js, you can use the built-in FormData or the 'form-data' library. For EU infrastructure, specify the EU API endpoint.
```javascript
import formData from 'form-data';
import Mailgun from 'mailgun.js';
const mailgun = new Mailgun(formData);
// For public/private key authentication
const client = mailgun.client({
username: 'api',
key: 'YOUR_MAILGUN_API_KEY',
});
// For EU infrastructure
// const client = mailgun.client({
// username: 'api',
// key: 'YOUR_MAILGUN_API_KEY',
// url: 'https://api.eu.mailgun.net'
// });
```
--------------------------------
### Get Domain Tracking Status Response
Source: https://github.com/mailgun/mailgun.js/blob/master/README.md
Example of the JSON response when retrieving domain tracking status. It indicates whether click, open, and unsubscribe tracking are active and includes footer content if configured.
```json
{
"click": {
"active": false
},
"open": {
"active": false
},
"unsubscribe": {
"active": false,
"html_footer": "\n \n
\n",
"text_footer": "\n\nTo unsubscribe click: <%unsubscribe_url%}\n\n"
}
}
```
--------------------------------
### routes.create
Source: https://github.com/mailgun/mailgun.js/blob/master/docs/README.md
Creates a new route.
```APIDOC
## routes.create
### Description
Creates a new route.
### Method
POST
### Endpoint
/routes
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
(Details not provided in source)
### Request Example
(Details not provided in source)
### Response
#### Success Response (200)
(Details not provided in source)
#### Response Example
(Details not provided in source)
```
--------------------------------
### Get Account Usage Metrics
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
Retrieves filtered usage metrics for an account. Similar to getAccount, but specifically for usage-related data. It accepts a query object with parameters like start date, end date, resolution, and metrics.
```javascript
mg.metrics.getAccountUsage({
start: '2024-12-16T10:47:51.661Z',
end: '2024-12-23T10:47:51.661Z',
resolution: 'hour',
metrics: ['opened_count'],
filter: {
AND: [{
attribute: 'domain',
comparator: 'contains',
values: [{
value: 'mailgun'
}]
}]
},
include_subaccounts: true,
include_aggregates: true
})
.then(data => console.log(data)) // logs response data
.catch(err => console.error(err)); //logs any error
```
--------------------------------
### Get Mailgun Events with Date and Filter Field
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
This example demonstrates retrieving delivered events within a specific date range and limit. Ensure the date is correctly formatted for the `begin` parameter and consider using `ascending` for time range direction.
```javascript
const date = new Date(2023, 7, 2, 0, 0, 0, 0); // Wed Aug 02 2023 00:00:00 GMT+0300
const events = await mg.events.get('foobar.example.com', {
begin: date.toUTCString(), // 'Tue, 01 Aug 2023 21:00:00 GMT'
ascending: 'yes',
limit: 5,
event: 'delivered'
});
```
--------------------------------
### Build for Release
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
Build the project for release, including code minimization. This prepares the project for deployment.
```sh
npm run build:release
```
--------------------------------
### Run Release Script
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
Execute the release script to prepare for a new version. This typically involves version bumping and changelog generation.
```sh
npm run release
```
--------------------------------
### Webhook Destroy Response Example
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
This is an example of the JSON response structure after successfully deleting a webhook.
```JS
{
'open': { 'url': 'http://requestb.in', 'urls': ['http://requestb.in']}
}
```
--------------------------------
### Initialize Mailgun Client and Fetch Domains
Source: https://github.com/mailgun/mailgun.js/blob/master/examples/index.html
Initializes the Mailgun client using a provided API key and the local proxy URL. It then fetches the list of domains associated with the account and updates the scope.
```javascript
$scope.setClient = function() {
if($scope.form.key){
$scope.mg = mailgun.client({url: 'http://0.0.0.0:4001', username: 'api', key: $scope.form.key});
}
$scope.mg.domains.list()
.then(domains => {
$scope.domains = domains;
$scope.emailForm.selectedDomain = $scope.domains[0];
$scope.updateDomain();
$scope.$apply();
})
.catch(err => console.log(err));
};
```
--------------------------------
### Run Tests
Source: https://github.com/mailgun/mailgun.js/blob/master/README.md
Execute the project's test suite. This is a manual step as the CI process is not currently active.
```sh
npm run test
```
--------------------------------
### Example Domain Object Structure
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
This is an example of the structure of a domain object returned by the Mailgun.js Domains API.
```json
[{
name: 'testing.example.com',
require_tls: true,
skip_verification: true,
state: 'unverified',
wildcard: true,
spam_action: 'disabled',
created_at: 'Sun, 19 Oct 2014 18:49:36 GMT',
smtp_password: undefined,
smtp_login: 'postmaster@testing.example.com',
type: 'custom',
receiving_dns_records: null,
sending_dns_records: null,
id: '697d01d38712cf0322bb24d1',
is_disabled: false,
web_prefix: 'test',
web_scheme: 'https',
use_automatic_sender_security: true
}]
```
--------------------------------
### create
Source: https://github.com/mailgun/mailgun.js/blob/master/docs/interfaces/definitions.Interfaces.IDomainTemplatesClient.md
Creates a new domain template. Requires the domain name and template data.
```APIDOC
## create
### Description
Creates a new domain template.
### Method
POST
### Endpoint
/domains/{domain}/templates
### Parameters
#### Path Parameters
- **domain** (string) - Required - The domain name.
#### Request Body
- **data** (DomainTemplateData) - Required - The data for the new template.
### Response
#### Success Response (200)
- **template** (IDomainTemplate) - The created domain template.
### Request Example
```json
{
"name": "my-template",
"subject": "Hello {{name}}",
"html": "
",
"createdAt": "2023-10-27T10:00:00Z"
}
],
"createdAt": "2023-10-27T10:00:00Z"
}
}
```
```
--------------------------------
### Webhook Test Creation Response Example
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
This is an example of the JSON response structure when a webhook creation test fails.
```JS
{
'code': '500',
'message': 'Hi!'
}
```
--------------------------------
### Suppression List Response Example
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
Example structure of the response when listing suppressions, including items and pagination details.
```JS
{
items: [
{
type: "bounces",
address: "unknown@unknown.com",
code: 550,
error: "No such mailbox",
created_at: Fri Oct 21 2011 04:02:55 GMT-0700 (PDT)
}],
pages: {
first: { id: "first", page: "", address: "", url: "apiurl" },
last: { id: "last", page: "", address: "", url: "apiurl" },
next: { id: "next", page: "", address: "", url: "apiurl" },
previous: { id: "prev", page: "", address: "", url: "apiurl" }
}
}
```
--------------------------------
### routes.list
Source: https://github.com/mailgun/mailgun.js/blob/master/docs/README.md
Lists all routes.
```APIDOC
## routes.list
### Description
Lists all routes.
### Method
GET
### Endpoint
/routes
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
(Details not provided in source)
### Response
#### Success Response (200)
(Details not provided in source)
#### Response Example
(Details not provided in source)
```
--------------------------------
### create
Source: https://github.com/mailgun/mailgun.js/blob/master/docs/interfaces/definitions.Interfaces.IRoutesClient.md
Creates a new route with the provided data.
```APIDOC
## create
### Description
Creates a new route with the provided data.
### Method
POST (assumed based on common REST patterns for creating resources)
### Endpoint
/routes
### Parameters
#### Request Body
- **data** (CreateUpdateRouteData) - Required - The data for the new route.
### Request Example
```json
{
"data": { "priority": 1, "description": "New Route", "url": "http://new.example.com", "expression": "catch_all()" }
}
```
### Returns
#### Success Response
- **route** (Route) - The newly created Route object.
### Response Example
```json
{
"route": { "id": "route3", "url": "http://new.example.com", "priority": 1, "description": "New Route" }
}
```
```
--------------------------------
### Webhook Update Multiple URLs Response Example
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
This is an example of the JSON response structure after updating a webhook to use multiple URLs.
```JS
{
'open': { 'url': 'http://requestb.in', 'urls': ['http://requestb.in', 'http://requestb1.in'] }
}
```
--------------------------------
### listAll
Source: https://github.com/mailgun/mailgun.js/blob/master/docs/interfaces/definitions.Interfaces.IDomainKeysClient.md
Lists all domain keys with optional query parameters.
```APIDOC
## listAll
### Description
Lists all domain keys with optional query parameters.
### Method
GET (Assumed based on typical API patterns for listing)
### Endpoint
/domains/keys (Assumed based on typical API patterns)
### Parameters
#### Query Parameters
- **query** (DomainKeysListAllQuery) - Required - The query parameters for listing domain keys.
### Returns
`Promise`
#### Success Response (200)
- **DomainKeysListAllResult** - The list of all domain keys.
```
--------------------------------
### domainKeys.create
Source: https://github.com/mailgun/mailgun.js/blob/master/docs/README.md
Creates a domain key.
```APIDOC
## domainKeys.create
### Description
Creates a domain key.
### Method
POST
### Endpoint
/domains/{domain}/keys
### Parameters
#### Path Parameters
- **domain** (string) - Required - The domain name.
#### Query Parameters
None
#### Request Body
(Details not provided in source)
### Request Example
(Details not provided in source)
### Response
#### Success Response (200)
(Details not provided in source)
#### Response Example
(Details not provided in source)
```
--------------------------------
### Domain Stats Response Example
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
An example of the JSON response structure when fetching domain statistics. It includes time-based event counts.
```json
{
"start": "Sun Mar 15 2015 17:00:00 GMT-0700 (PDT)",
"end": "Sun Mar 22 2015 17:00:00 GMT-0700 (PDT)",
"resolution": "day",
"stats": [{
"time": "Sun Mar 15 2015 17:00:00 GMT-0700 (PDT)",
"delivered": { "smtp": 2, "http": 1, "total": 3 }
}]
}
```
--------------------------------
### domains.create
Source: https://github.com/mailgun/mailgun.js/blob/master/docs/README.md
Creates a new domain.
```APIDOC
## domains.create
### Description
Creates a new domain.
### Method
POST
### Endpoint
/domains
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
(Details not provided in source)
### Request Example
(Details not provided in source)
### Response
#### Success Response (200)
(Details not provided in source)
#### Response Example
(Details not provided in source)
```
--------------------------------
### Get Specific Inbox Placement Attribute
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
Retrieves details for a specific attribute. Provide the attribute name to get its possible values and description.
```javascript
mg.inboxPlacements.results.attributes.get('attribute_name')
.then(data => console.log(data)) // logs response data
.catch(err => console.error(err)); //logs any error
```
--------------------------------
### Update Open Tracking Settings Response
Source: https://github.com/mailgun/mailgun.js/blob/master/README.md
Example response after updating open tracking settings. Confirms the update and shows the new active status and placement preference.
```json
{
"message": "Tracking settings have been updated",
"open": {
"active": true,
"place_at_the_top": true,
}
}
```
--------------------------------
### Example Metrics API Response
Source: https://github.com/mailgun/mailgun.js/blob/master/docs/README.md
This example demonstrates the structure of the response when querying Mailgun metrics. It includes details on dimensions, metrics, aggregates, and status.
```json
{
"start": new Date('2024-12-16T01:00:00.000Z'),
"end": new Date('2024-12-23T00:00:00.000Z'),
"resolution": "hour",
"dimensions": [ "time" ],
"pagination": { "sort": "", "skip": 0, "limit": 1500, "total": 1 },
"items": [
{
"dimensions": [
{
"dimension": "time",
"value": "Sat, 21 Dec 2024 17:00:00 +0000",
"display_value": "Sat, 21 Dec 2024 17:00:00 +0000"
}
],
"metrics": { "opened_count": 1 }
},
...
],
"aggregates": { "metrics": { "opened_count": 1 } },
"status": 200
}
```
--------------------------------
### mg.routes.create(options)
Source: https://github.com/mailgun/mailgun.js/blob/master/docs/README.md
Creates a new route with the specified options.
```APIDOC
## POST /v3/routes
### Description
Creates a new route with the specified options.
### Method
POST
### Endpoint
/v3/routes
### Parameters
#### Request Body
- **priority** (integer) - Required - The priority of the route.
- **description** (string) - Optional - Description of the route.
- **expression** (string) - Required - The routing expression.
- **action** (array) - Required - List of actions for the route.
### Request Example
```javascript
mg.routes.create({
priority: 0,
description: 'sample',
expression: 'match_recipient(".*@example.org")',
action: ['forward("http://myhost.com/messages/")', 'stop()']
})
.then(data => console.log(data))
.catch(err => console.error(err));
```
### Response
#### Success Response (200)
- **actions** (array) - List of actions for the route.
- **created_at** (string) - Timestamp of route creation.
- **description** (string) - Description of the route.
- **expression** (string) - The routing expression.
- **id** (string) - The unique identifier for the route.
- **priority** (integer) - The priority of the route.
#### Response Example
```json
{
"actions": [ "forward(\"http://myhost.com/messages/\")", "stop()" ],
"created_at": "Mon, 26 Oct 2015 03:56:51 GMT",
"description": "sample",
"expression": "match_recipient(\".*@example.com\")",
"id": "562da483125730608a7d1719",
"priority": 0
}
```
```
--------------------------------
### Inbox Placements Sharing Get
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
Retrieves the sharing status of a specific inbox placement result. Use this to check if a result is shared and get its details.
```APIDOC
## Inbox Placements Sharing Get
### Description
Retrieves the sharing status of a specific inbox placement result. Use this to check if a result is shared and get its details.
### Method
`mg.inboxPlacements.results.sharing.get(result_id)`
### Parameters
#### Path Parameters
- **result_id** (string) - Required - The ID of the inbox placement result.
### Response
#### Success Response (200)
- **result_id** (string) - The ID of the result.
- **expires_at** (Date) - The expiration date of the shared link.
- **enabled** (boolean) - Indicates if sharing is enabled.
- **url_id** (string) - The ID for the shared URL.
- **url** (string) - The URL to the shared result page.
- **api_url** (string) - The API URL for the shared result.
### Response Example
```json
{
"status": 200,
"result_id": "result_id",
"expires_at": "2024-08-12T14:32:57.183Z",
"enabled": true,
"url_id": "result_sharing_id",
"url": "url-to-shared-result-page",
"api_url": "url-shared-result-page-in-json"
}
```
```
--------------------------------
### List All Routes
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
Fetches a list of all configured routes. Handles both successful responses and errors.
```javascript
mg.routes.list()
.then(data => console.log(data)) // logs response body
.catch(err => console.error(err)); // logs any error
```
--------------------------------
### create
Source: https://github.com/mailgun/mailgun.js/blob/master/docs/interfaces/definitions.Interfaces.IWebHooksClient.md
Creates a new webhook for a given domain. It allows specifying the webhook URL and a test mode.
```APIDOC
## create
### Description
Creates a new webhook for a given domain. It allows specifying the webhook URL and a test mode.
### Method
Not applicable (SDK method)
### Endpoint
Not applicable (SDK method)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Parameters
- **domain** (string) - Required
- **id** (string) - Required
- **url** (string) - Required
- **test** (boolean) - Required
### Returns
`Promise` with either `WebhookValidationResponse` or `WebhookResult`
### Request Example
None provided in source.
### Response
#### Success Response
- `WebhookValidationResponse` or `WebhookResult`
#### Response Example
None provided in source.
```
--------------------------------
### DKIM Rotate Immediately Result Example
Source: https://github.com/mailgun/mailgun.js/blob/master/docs/README.md
Example structure of the response data when immediately rotating a DKIM key. It typically confirms the action with a simple message.
```json
{
"message": "ok"
}
```
--------------------------------
### Inbox Placements Attribute Get
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
Fetches details for a specific inbox placement attribute, including its possible values. Use this to get more information about a particular attribute.
```APIDOC
## Inbox Placements Attribute Get
### Description
Fetches details for a specific inbox placement attribute, including its possible values. Use this to get more information about a particular attribute.
### Method
`mg.inboxPlacements.results.attributes.get(attribute_name)`
### Parameters
#### Path Parameters
- **attribute_name** (string) - Required - The name of the attribute to retrieve details for.
### Response
#### Success Response (200)
- **items** (object) - An object containing the attribute name and its possible values.
### Response Example
```json
{
"status": 200,
"items": {
"attribute": "attribute_name",
"values": ["attribute_value", ...]
}
}
```
```
--------------------------------
### Setup Mailgun Client with ES Modules (Node.js)
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
Instantiate the Mailgun client using ES Module imports. Ensure FormData is available, either built-in or from the 'form-data' library.
```JS
import Mailgun from 'mailgun.js';
const mailgun = new Mailgun(FormData); // or import formData from 'form-data';
const mg = mailgun.client({username: 'api', key: process.env.MAILGUN_API_KEY || 'MAILGUN_API_KEY'});
```
--------------------------------
### Create Route
Source: https://github.com/mailgun/mailgun.js/blob/master/README.md
Creates a new route with the specified options.
```APIDOC
## POST /v3/routes
### Description
Creates a new route with the specified options.
### Method
POST
### Endpoint
/v3/routes
### Parameters
#### Request Body
- **priority** (integer) - Required - The priority of the route.
- **description** (string) - Optional - A description of the route.
- **expression** (string) - Required - The routing expression.
- **action** (array) - Required - A list of actions for the route.
### Request Example
```javascript
mg.routes.create({
priority: 0,
description: 'sample',
expression: 'match_recipient(".*@example.org")',
action: ['forward("http://myhost.com/messages/")', 'stop()']
})
.then(data => console.log(data))
.catch(err => console.error(err));
```
### Response
#### Success Response (200)
- **actions** (array) - List of actions for the route.
- **created_at** (string) - The timestamp when the route was created.
- **description** (string) - A description of the route.
- **expression** (string) - The routing expression.
- **id** (string) - The unique identifier of the route.
- **priority** (integer) - The priority of the route.
#### Response Example
```json
{
"actions": [ "forward(\"http://myhost.com/messages/\")", "stop()" ],
"created_at": "Mon, 26 Oct 2015 03:56:51 GMT",
"description": "sample",
"expression": "match_recipient(\".*@example.com\")",
"id": "562da483125730608a7d1719",
"priority": 0
}
```
```
--------------------------------
### Get Inbox Placement Seed List Attributes
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
Retrieves attributes for inbox placement seed lists. Use this method to get specific attribute details and their possible values.
```javascript
mg.inboxPlacements.seedsLists.attributes.get('attribute_name')
```
```javascript
mg.inboxPlacements.seedsLists.attributes.get('attribute_name')
.then(data => console.log(data)) // logs response data
.catch(err => console.error(err)); //logs any error
```
--------------------------------
### get
Source: https://github.com/mailgun/mailgun.js/blob/master/docs/interfaces/definitions.Interfaces.IDomainsClient.md
Retrieves the details of a specific domain.
```APIDOC
## get
### Description
Retrieves the details of a specific domain.
### Method
Not specified (SDK method)
### Parameters
#### Path Parameters
None
#### Query Parameters
- **query** (object) - Optional. An object containing query parameters for filtering the domain details.
#### Request Body
None
### Parameters
- **domain** (string) - The name of the domain to retrieve.
- **query** (object) - Optional. An object containing query parameters.
### Returns
`Promise` - A promise that resolves with the domain object.
### Request Example
```javascript
// Example usage (assuming domainsClient is an instance of IDomainsClient)
domainsClient.get('example.com');
// With query parameters
domainsClient.get('example.com', { include_subaccounts: true });
```
### Response
#### Success Response
- **TDomain** (object) - The domain object with its details.
#### Response Example
```json
{
"name": "example.com",
"smtp_username": "postmaster@example.com"
}
```
```
--------------------------------
### get
Source: https://github.com/mailgun/mailgun.js/blob/master/docs/interfaces/definitions.Interfaces.ISubaccountsClient.md
Retrieves a specific subaccount by its ID.
```APIDOC
## get
### Description
Retrieves a specific subaccount by its ID.
### Method
GET
### Endpoint
/subaccounts/{id}
### Parameters
#### Path Parameters
- **id** (string) - Required - The ID of the subaccount to retrieve.
#### Query Parameters
None
#### Request Body
None
### Response
#### Success Response (200)
- **id** (string) - The ID of the subaccount.
- **name** (string) - The name of the subaccount.
#### Response Example
```json
{
"id": "subaccount_id",
"name": "example_subaccount_name"
}
```
```
--------------------------------
### Create Route
Source: https://github.com/mailgun/mailgun.js/blob/master/dist/README.md
Creates a new route with specified options including priority, description, expression, and actions.
```APIDOC
## Create Route
### Description
Creates a new route with specified options including priority, description, expression, and actions.
### Method
POST
### Endpoint
/v3/routes
### Parameters
#### Request Body
- **priority** (integer) - Required - The priority of the route.
- **description** (string) - Optional - Description of the route.
- **expression** (string) - Required - The expression that matches recipients for this route.
- **action** (array) - Required - List of actions to perform for the route.
### Request Example
```javascript
mg.routes.create({
priority: 0,
description: 'sample',
expression: 'match_recipient(".*@example.org")',
action: ['forward("http://myhost.com/messages/")', 'stop()']
})
.then(data => console.log(data))
.catch(err => console.error(err));
```
### Response
#### Success Response (200)
- **actions** (array) - List of actions for the route.
- **created_at** (string) - Timestamp when the route was created.
- **description** (string) - Description of the route.
- **expression** (string) - The expression that matches recipients for this route.
- **id** (string) - The unique identifier for the route.
- **priority** (integer) - The priority of the route.
#### Response Example
```json
{
"actions": [ "forward(\"http://myhost.com/messages/\")", "stop()" ],
"created_at": "Mon, 26 Oct 2015 03:56:51 GMT",
"description": "sample",
"expression": "match_recipient(\".*@example.com\")",
"id": "562da483125730608a7d1719",
"priority": 0
}
```
```
--------------------------------
### get
Source: https://github.com/mailgun/mailgun.js/blob/master/docs/interfaces/definitions.Interfaces.IRoutesClient.md
Retrieves a specific route by its ID.
```APIDOC
## get
### Description
Retrieves a specific route by its ID.
### Method
GET (assumed based on common REST patterns for retrieving a single resource)
### Endpoint
/routes/{id}
### Parameters
#### Path Parameters
- **id** (string) - Required - The unique identifier of the route.
### Returns
#### Success Response
- **route** (Route) - The Route object.
### Response Example
```json
{
"route": { "id": "route1", "url": "http://example.com", "priority": 1, "description": "Route 1" }
}
```
```
--------------------------------
### create
Source: https://github.com/mailgun/mailgun.js/blob/master/docs/interfaces/definitions.Interfaces.IDomainCredentials.md
Creates new domain credentials for a given domain.
```APIDOC
## create
### Description
Creates new domain credentials for a given domain.
### Method
Not specified (SDK method)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Parameters
- **domain** (string) - The domain for which to create credentials.
- **data** (DomainCredentials) - The data for the new domain credentials.
### Returns
`Promise` - A promise that resolves with the result of the creation.
### Defined in
[Interfaces/Domains/DomainCredentials.ts:11](https://github.com/mailgun/mailgun.js/blob/428d668/lib/Interfaces/Domains/DomainCredentials.ts#L11)
```
--------------------------------
### Get Subaccount
Source: https://github.com/mailgun/mailgun.js/blob/master/README.md
Retrieves a specific subaccount by its ID.
```APIDOC
## GET /v5/accounts/subaccounts/{subaccount_id}
### Description
Retrieves a specific subaccount by its ID.
### Method
GET
### Endpoint
/v5/accounts/subaccounts/{subaccount_id}
### Parameters
#### Path Parameters
- **subaccount_id** (string) - Required - The ID of the subaccount to retrieve.
### Response
#### Success Response (200)
- **subaccount** (object) - The requested Subaccount object.
### Response Example
```json
{ "id": "123", "name": "test.subaccount1", "status": "open" }
```
```
--------------------------------
### Publish to npm
Source: https://github.com/mailgun/mailgun.js/blob/master/README.md
After running the release script and navigating to the dist directory, log in to npm and publish the package. This step is part of the final release process.
```sh
cd ./dist
npm login
npm publish
```