mailgun.js 8.0.6 → 8.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -53,7 +53,7 @@ const mg = mailgun.client({username: 'api', key: process.env.MAILGUN_API_KEY ||
53
53
  ## Methods
54
54
 
55
55
  The following service methods are available to instantiated clients. The examples assume you have already created a mailgun client as `mg` with valid credentials.
56
- - [Mailgun.js ![Build Status](https://travis-ci.org/mailgun/mailgun-js)](#mailgunjs-img-srchttpstravis-ciorgmailgunmailgun-jssvg-altbuild-status)
56
+
57
57
  - [Documentation](#documentation)
58
58
  - [Install](#install)
59
59
  - [Setup Client](#setup-client)
@@ -78,32 +78,33 @@ The following service methods are available to instantiated clients. The example
78
78
  - [list](#list-1)
79
79
  - [get](#get-2)
80
80
  - [create](#create-2)
81
+ - [destroy](#destroy-1)
81
82
  - [webhooks](#webhooks)
82
83
  - [list](#list-2)
83
84
  - [get](#get-3)
84
85
  - [create](#create-3)
85
86
  - [update](#update)
86
- - [destroy](#destroy-1)
87
+ - [destroy](#destroy-2)
87
88
  - [routes](#routes)
88
89
  - [list](#list-3)
89
90
  - [get](#get-4)
90
91
  - [create](#create-4)
91
92
  - [update](#update-1)
92
- - [destroy](#destroy-2)
93
+ - [destroy](#destroy-3)
93
94
  - [validate](#validate)
94
95
  - [get](#get-5)
95
- - [Multiple Validation](#multiple-validation)
96
+ - [multiple validation](#multiple-validation)
96
97
  - [create](#create-5)
97
98
  - [list](#list-4)
98
99
  - [get](#get-5)
99
- - [destroy](#destroy-3)
100
- - [lists](#lists)
100
+ - [destroy](#destroy-4)
101
+ - [mailing lists](#mailing-lists)
101
102
  - [list](#list-5)
102
103
  - [get](#get-6)
103
104
  - [create](#create-6)
104
105
  - [update](#update-2)
105
- - [destroy](#destroy-3)
106
- - [mailListMembers](#maillistmembers)
106
+ - [destroy](#destroy-5)
107
+ - [mailing list members](#mailing-list-members)
107
108
  - [listMembers](#listmember)
108
109
  - [getMember](#getmember)
109
110
  - [createMember](#createmember)
@@ -126,182 +127,182 @@ Method naming conventions:
126
127
  - `update` or `update{{Item}}` - expected response is an object with a status message
127
128
  - `destroy` or `destroy{{Item}}` - expected response is an object with a status message
128
129
 
129
- ### messages
130
+ ### Messages
130
131
 
131
- #### create
132
+ - #### create
132
133
 
133
- `mg.messages.create(domain, data)` - [api docs](https://documentation.mailgun.com/en/latest/api-sending.html)
134
+ `mg.messages.create(domain, data)` - [api docs](https://documentation.mailgun.com/en/latest/api-sending.html)
134
135
 
135
- Options:
136
+ Options:
136
137
 
137
- Parameter | Description
138
- :---------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
139
- to | Email address of the recipient(s). Example: "Bob <bob@host.com>". You can use commas to separate multiple recipients (e.g.: "test@example.com,test@example.com" or ["test@example.com", "test@example.com"]).
140
- cc | Same as `To` but for `carbon copy`
141
- bcc | Same as `To` but for `blind carbon copy`
142
- subject | Subject of the message.
143
- html | HTML version of the message.
144
- text | Text version of the message.
145
- message | MIME string of the message. Make sure to use multipart/form-data to send this as a file upload.
146
- attachment | File attachment. You can post multiple attachment values. Important: You must use multipart/form-data encoding when sending attachments. Also you can use `{data: file, filename: filename}` to define custom filename.
147
- o:tag | Tag string. See Tagging for more information.
148
- o:campaign | Id of the campaign the message belongs to. See um-campaign-analytics for details.
149
- o:deliverytime | Desired time of delivery. See Date Format. Note: Messages can be scheduled for a maximum of 3 days in the future.
150
- o:dkim | Enables/disabled DKIM signatures on per-message basis. Pass yes or no
151
- o:testmode | Enables sending in test mode. Pass yes if needed. See Sending in Test Mode
152
- o:tracking | Toggles tracking on a per-message basis, see Tracking Messages for details. Pass yes or no.
153
- o:tracking-clicks | Toggles clicks tracking on a per-message basis. Has higher priority than domain-level setting. Pass yes, no or htmlonly.
154
- o:tracking-opens | Toggles opens tracking on a per-message basis. Has higher priority than domain-level setting. Pass yes or no.
155
- h:X-My-Header | h: prefix followed by an arbitrary value allows to append a custom MIME header to the message (X-My-Header in this case). For example, h:Reply-To to specify Reply-To address.
156
- v:my-var | v: prefix followed by an arbitrary name allows to attach a custom JSON data to the message. See Attaching Data to Messages for more information.
157
-
158
-
159
- - HTML/TEXT Example:
160
-
161
- ```js
162
- mg.messages.create('sandbox-123.mailgun.org', {
163
- from: "Excited User <mailgun@sandbox-123.mailgun.org>",
164
- to: ["test@example.com"],
165
- subject: "Hello",
166
- text: "Testing some Mailgun awesomness!",
167
- html: "<h1>Testing some Mailgun awesomness!</h1>"
168
- })
169
- .then(msg => console.log(msg)) // logs response data
170
- .catch(err => console.error(err)); // logs any error
171
- ```
138
+ Parameter | Description
139
+ :---------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
140
+ to | Email address of the recipient(s). Example: "Bob <bob@host.com>". You can use commas to separate multiple recipients (e.g.: "test@example.com,test@example.com" or ["test@example.com", "test@example.com"]).
141
+ cc | Same as `To` but for `carbon copy`
142
+ bcc | Same as `To` but for `blind carbon copy`
143
+ subject | Subject of the message.
144
+ html | HTML version of the message.
145
+ text | Text version of the message.
146
+ message | MIME string of the message. Make sure to use multipart/form-data to send this as a file upload.
147
+ attachment | File attachment. You can post multiple attachment values. Important: You must use multipart/form-data encoding when sending attachments. Also you can use `{data: file, filename: filename}` to define custom filename.
148
+ o:tag | Tag string. See Tagging for more information.
149
+ o:campaign | Id of the campaign the message belongs to. See um-campaign-analytics for details.
150
+ o:deliverytime | Desired time of delivery. See Date Format. Note: Messages can be scheduled for a maximum of 3 days in the future.
151
+ o:dkim | Enables/disabled DKIM signatures on per-message basis. Pass yes or no
152
+ o:testmode | Enables sending in test mode. Pass yes if needed. See Sending in Test Mode
153
+ o:tracking | Toggles tracking on a per-message basis, see Tracking Messages for details. Pass yes or no.
154
+ o:tracking-clicks | Toggles clicks tracking on a per-message basis. Has higher priority than domain-level setting. Pass yes, no or htmlonly.
155
+ o:tracking-opens | Toggles opens tracking on a per-message basis. Has higher priority than domain-level setting. Pass yes or no.
156
+ h:X-My-Header | h: prefix followed by an arbitrary value allows to append a custom MIME header to the message (X-My-Header in this case). For example, h:Reply-To to specify Reply-To address.
157
+ v:my-var | v: prefix followed by an arbitrary name allows to attach a custom JSON data to the message. See Attaching Data to Messages for more information.
172
158
 
173
- - MIME Example:
174
159
 
175
- ```js
176
- mg.messages.create('sandbox-123.mailgun.org', {
177
- from: "Excited User <mailgun@sandbox-123.mailgun.org>",
178
- to: ["test@example.com"],
179
- subject: "Hello",
180
- message: "<mime encoded string here>"
181
- })
182
- .then(msg => console.log(msg)) // logs response data
183
- .catch(err => console.error(err)); // logs any error
184
- ```
160
+ - HTML/TEXT Example:
185
161
 
186
- Messages with attachments:
162
+ ```JS
163
+ mg.messages.create('sandbox-123.mailgun.org', {
164
+ from: "Excited User <mailgun@sandbox-123.mailgun.org>",
165
+ to: ["test@example.com"],
166
+ subject: "Hello",
167
+ text: "Testing some Mailgun awesomness!",
168
+ html: "<h1>Testing some Mailgun awesomness!</h1>"
169
+ })
170
+ .then(msg => console.log(msg)) // logs response data
171
+ .catch(err => console.error(err)); // logs any error
172
+ ```
187
173
 
188
- - Node.js example of send file as an attachment
174
+ - MIME Example:
189
175
 
190
- ```js
191
- const fsPromises = require('fs').promises;
192
- const path = require('path');
193
- const filepath = path.resolve(__dirname, '../test.pdf');
194
- let messageParams = {
176
+ ```js
177
+ mg.messages.create('sandbox-123.mailgun.org', {
195
178
  from: "Excited User <mailgun@sandbox-123.mailgun.org>",
196
179
  to: ["test@example.com"],
197
- subject: "Test subject",
198
- text: "Hello here is a file in the attachment"
199
- }
180
+ subject: "Hello",
181
+ message: "<mime encoded string here>"
182
+ })
183
+ .then(msg => console.log(msg)) // logs response data
184
+ .catch(err => console.error(err)); // logs any error
185
+ ```
200
186
 
201
- fsPromises.readFile(filepath)
202
- .then(data => {
203
- const file = {
204
- filename: 'test-rename.pdf',
205
- data
206
- }
207
- messageParams.attachment = file;
208
- return mg.messages.create('sandbox-123.mailgun.org', messageParams);
209
- })
210
- .then(response => {
211
- console.log(response);
212
- })
213
- ```
214
- - Node.js example of send multiple files as an attachment
215
- ```js
216
- const fsPromises = require('fs').promises;
217
- const path = require('path');
218
- const filepath = path.resolve(__dirname, '../test.pdf');
219
- const filepath1 = path.resolve(__dirname, '../test.jpg');
220
-
221
- let messageParams = {
222
- from: "Excited User <mailgun@sandbox-123.mailgun.org>",
223
- to: ["test@example.com"],
224
- subject: "Test subject",
225
- text: "Test message"
226
- }
187
+ - Messages with attachments:
227
188
 
228
- (async () =>{
229
- try {
230
- const firstFile = {
231
- filename: 'test.pdf',
232
- data: await fsPromises.readFile(filepath)
233
- }
189
+ - Node.js example of send file as an attachment
234
190
 
235
- const secondFile = {
236
- filename: 'test.jpg',
237
- data: await fsPromises.readFile(filepath1)
238
- }
191
+ ```js
192
+ const fsPromises = require('fs').promises;
193
+ const path = require('path');
194
+ const filepath = path.resolve(__dirname, '../test.pdf');
195
+ let messageParams = {
196
+ from: "Excited User <mailgun@sandbox-123.mailgun.org>",
197
+ to: ["test@example.com"],
198
+ subject: "Test subject",
199
+ text: "Hello here is a file in the attachment"
200
+ }
239
201
 
240
- messageParams.attachment = [firstFile, secondFile];
241
- const result = await mg.messages.create('sandbox-123.mailgun.org', messageParams);
242
- console.log(result);
243
- } catch (error) {
244
- console.error(error);
202
+ fsPromises.readFile(filepath)
203
+ .then(data => {
204
+ const file = {
205
+ filename: 'test-rename.pdf',
206
+ data
245
207
  }
246
- })()
247
- ```
248
- - Node.js example of send file as inline image
249
- ```js
250
- const fsPromises = require('fs').promises;
251
- const path = require('path');
252
- const filepath = path.resolve(__dirname, '../test.jpg');
253
- let messageParams = {
254
- from: "Excited User <mailgun@sandbox-123.mailgun.org>",
255
- to: ["test@example.com"],
256
- subject: "Test subject",
257
- html: '<div><img alt="image" id="1" src="cid:test.jpg"/></div> Some extra text'
258
- }
259
-
260
- fsPromises.readFile(filepath)
261
- .then(data => {
262
- const file = {
263
- filename: 'test.jpg',
264
- data
208
+ messageParams.attachment = file;
209
+ return mg.messages.create('sandbox-123.mailgun.org', messageParams);
210
+ })
211
+ .then(response => {
212
+ console.log(response);
213
+ })
214
+ ```
215
+ - Node.js example of send multiple files as an attachment
216
+ ```js
217
+ const fsPromises = require('fs').promises;
218
+ const path = require('path');
219
+ const filepath = path.resolve(__dirname, '../test.pdf');
220
+ const filepath1 = path.resolve(__dirname, '../test.jpg');
221
+
222
+ let messageParams = {
223
+ from: "Excited User <mailgun@sandbox-123.mailgun.org>",
224
+ to: ["test@example.com"],
225
+ subject: "Test subject",
226
+ text: "Test message"
265
227
  }
266
228
 
267
- messageParams.inline = file;
268
- return mg.messages.create('sandbox-123.mailgun.org', messageParams);
269
- })
270
- .then(response => {
271
- console.log(response);
272
- })
273
- ```
274
-
275
- - Browser example of send file
229
+ (async () =>{
230
+ try {
231
+ const firstFile = {
232
+ filename: 'test.pdf',
233
+ data: await fsPromises.readFile(filepath)
234
+ }
235
+
236
+ const secondFile = {
237
+ filename: 'test.jpg',
238
+ data: await fsPromises.readFile(filepath1)
239
+ }
240
+
241
+ messageParams.attachment = [firstFile, secondFile];
242
+ const result = await mg.messages.create('sandbox-123.mailgun.org', messageParams);
243
+ console.log(result);
244
+ } catch (error) {
245
+ console.error(error);
246
+ }
247
+ })()
248
+ ```
249
+ - Node.js example of send file as inline image
250
+ ```js
251
+ const fsPromises = require('fs').promises;
252
+ const path = require('path');
253
+ const filepath = path.resolve(__dirname, '../test.jpg');
254
+ let messageParams = {
255
+ from: "Excited User <mailgun@sandbox-123.mailgun.org>",
256
+ to: ["test@example.com"],
257
+ subject: "Test subject",
258
+ html: '<div><img alt="image" id="1" src="cid:test.jpg"/></div> Some extra text'
259
+ }
276
260
 
277
- Before sending the file you need to somehow get the Blob of the file.
278
- Usually can get it from the onChange event of input tag with type file.
279
- ```js
280
- const handleFileSelected = async (event) => {
281
- const files = Array.from(event.target.files)
282
- const fileBuffer = await files[0];
283
- }
284
- <input type="file" onChange={handleFileSelected} name="file-uploader"/>
285
- ```
261
+ fsPromises.readFile(filepath)
262
+ .then(data => {
263
+ const file = {
264
+ filename: 'test.jpg',
265
+ data
266
+ }
286
267
 
287
- Then you can use the same approach as shown above for node.js apps.
288
- ```js
289
- const file = {
290
- filename: 'test.pdf',
291
- data: fileBuffer
292
- };
268
+ messageParams.inline = file;
269
+ return mg.messages.create('sandbox-123.mailgun.org', messageParams);
270
+ })
271
+ .then(response => {
272
+ console.log(response);
273
+ })
274
+ ```
275
+
276
+ - Browser example of send file
277
+
278
+ Before sending the file you need to somehow get the Blob of the file.
279
+ Usually can get it from the onChange event of input tag with type file.
280
+ ```js
281
+ const handleFileSelected = async (event) => {
282
+ const files = Array.from(event.target.files)
283
+ const fileBuffer = await files[0];
284
+ }
285
+ <input type="file" onChange={handleFileSelected} name="file-uploader"/>
286
+ ```
287
+
288
+ Then you can use the same approach as shown above for node.js apps.
289
+ ```js
290
+ const file = {
291
+ filename: 'test.pdf',
292
+ data: fileBuffer
293
+ };
293
294
 
294
- let messageParams = {
295
- from: "Excited User <mailgun@sandbox-123.mailgun.org>",
296
- to: ["test@example.com"],
297
- subject: "Test subject",
298
- text: "Hello here is a file in the attachment",
299
- attachment: file
300
- };
295
+ let messageParams = {
296
+ from: "Excited User <mailgun@sandbox-123.mailgun.org>",
297
+ to: ["test@example.com"],
298
+ subject: "Test subject",
299
+ text: "Hello here is a file in the attachment",
300
+ attachment: file
301
+ };
301
302
 
302
- const res = await mg.messages.create(DOMAIN, messageParams);
303
- ```
304
- Promise Returns:
303
+ const res = await mg.messages.create(DOMAIN, messageParams);
304
+ ```
305
+ Promise returns:
305
306
 
306
307
  ```js
307
308
  {
@@ -309,901 +310,979 @@ Messages with attachments:
309
310
  message: 'Queued. Thank you.'
310
311
  }
311
312
  ```
312
- #### Templates
313
313
 
314
- Mailgun’s templates uses a fork of the very popular template engine [handlebars](https://handlebarsjs.com/).
314
+ ### Templates
315
315
 
316
- To provide values for a substitution you need to use 'h:X-Mailgun-Variables' property in the message description.
316
+ Mailgun’s templates uses a fork of the very popular template engine [handlebars](https://handlebarsjs.com/).
317
317
 
318
- Make sure that this property is a JSON string like {"title":"A title", "body":"The body"}.
318
+ To provide values for a substitution you need to use 'h:X-Mailgun-Variables' property in the message description.
319
319
 
320
- You can find few examples of how to use templates below.
321
- - Providing values for **title** and **slug** variables to render in template
322
- ```js
323
- ...
324
- const {
325
- title,
326
- slug,
327
- } = someDataSource;
320
+ Make sure that this property is a JSON string like {"title":"A title", "body":"The body"}.
328
321
 
329
- const mailgunData = {
330
- from: 'mailer@example.com>',
331
- to: 'recipient@example.com',
332
- subject: `Email ${title}`,
333
- template: 'name-of-the-template-you-made-in-mailgun-web-portal',
334
- 'h:X-Mailgun-Variables': JSON.stringify({ // be sure to stringify your payload
322
+ You can find few examples of how to use templates below.
323
+ - Providing values for **title** and **slug** variables to render in template
324
+ ```js
325
+ ...
326
+ const {
335
327
  title,
336
328
  slug,
337
- }),
338
- 'h:Reply-To': 'reply-to@example.com',
339
- };
329
+ } = someDataSource;
330
+
331
+ const mailgunData = {
332
+ from: 'mailer@example.com>',
333
+ to: 'recipient@example.com',
334
+ subject: `Email ${title}`,
335
+ template: 'name-of-the-template-you-made-in-mailgun-web-portal',
336
+ 'h:X-Mailgun-Variables': JSON.stringify({ // be sure to stringify your payload
337
+ title,
338
+ slug,
339
+ }),
340
+ 'h:Reply-To': 'reply-to@example.com',
341
+ };
340
342
 
341
- try {
342
- const response = await mailgun.messages.create(DOMAIN_NAME, mailgunData);
343
- ...
344
- ```
343
+ try {
344
+ const response = await mailgun.messages.create(DOMAIN_NAME, mailgunData);
345
+ ...
346
+ ```
345
347
 
346
348
  - Providing an array of objects to render them in the template
347
- ```JS
349
+ ```JS
350
+ ...
351
+ const mailgunData = {
352
+ from: 'mailer@example.com>',
353
+ to: 'recipient@example.com',
354
+ subject: `Email ${title}`,
355
+ template: 'name-of-the-another-template-you-made-in-mailgun-web-portal',
356
+ 'h:X-Mailgun-Variables': JSON.stringify({
357
+ "arrayItems": [
358
+ {
359
+ "question": "test_question",
360
+ "answer": "test_answer"
361
+ },
362
+ {
363
+ "question": "test_question",
364
+ "answer": "test_answer"
365
+ }
366
+ ]})
367
+ };
368
+ try {
369
+ const response = await mailgun.messages.create(DOMAIN_NAME, mailgunData);
370
+ ...
371
+ ```
372
+
373
+ ### Recipient Variables
374
+
375
+ [Docs](https://documentation.mailgun.com/en/latest/user_manual.html#batch-sending)
376
+
377
+ Recipient Variables are custom variables that you define, which you can then reference in the message body. They give you the ability to send a custom message to each recipient while still using a single API Call.
378
+
379
+ ```JS
348
380
  ...
349
381
  const mailgunData = {
350
- from: 'mailer@example.com>',
351
- to: 'recipient@example.com',
352
- subject: `Email ${title}`,
353
- template: 'name-of-the-another-template-you-made-in-mailgun-web-portal',
354
- 'h:X-Mailgun-Variables': JSON.stringify({
355
- "arrayItems": [
356
- {
357
- "question": "test_question",
358
- "answer": "test_answer"
382
+ from: 'Example.com Mailer <mailer@mailer.example.com>',
383
+ to: ['me@example.com', 'you@example.com'],
384
+ subject: 'Recipient - %recipient.title%',
385
+ html: 'Here\'s %recipient.title% and <a href="%recipient.link%">link</a>',
386
+ 'recipient-variables': JSON.stringify({
387
+ 'me@example.com': {
388
+ title: 'Me',
389
+ link: 'href-var',
359
390
  },
360
- {
361
- "question": "test_question",
362
- "answer": "test_answer"
363
- }
364
- ]})
365
- };
366
- try {
367
- const response = await mailgun.messages.create(DOMAIN_NAME, mailgunData);
391
+ 'you@example.com': {
392
+ title: 'You',
393
+ link: 'slug-recipient-var-c',
394
+ },
395
+ }),
396
+ };
397
+
398
+ try {
399
+ const response = await mailgun.messages.create(DOMAIN_NAME, mailgunData);
368
400
  ...
369
- ```
401
+ ```
370
402
 
371
- #### Recipient Variables
372
- [Docs](https://documentation.mailgun.com/en/latest/user_manual.html#batch-sending)
373
-
374
- Recipient Variables are custom variables that you define, which you can then reference in the message body. They give you the ability to send a custom message to each recipient while still using a single API Call.
375
-
376
- ```Js
377
- ...
378
- const mailgunData = {
379
- from: 'Example.com Mailer <mailer@mailer.example.com>',
380
- to: ['me@example.com', 'you@example.com'],
381
- subject: 'Recipient - %recipient.title%',
382
- html: 'Here\'s %recipient.title% and <a href="%recipient.link%">link</a>',
383
- 'recipient-variables': JSON.stringify({
384
- 'me@example.com': {
385
- title: 'Me',
386
- link: 'href-var',
387
- },
388
- 'you@example.com': {
389
- title: 'You',
390
- link: 'slug-recipient-var-c',
391
- },
392
- }),
393
- };
403
+ ### Domains
394
404
 
395
- try {
396
- const response = await mailgun.messages.create(DOMAIN_NAME, mailgunData);
397
- ...
398
- ```
405
+ - #### list
399
406
 
400
- ### domains
407
+ `mg.domains.list(query)` - [api docs](https://documentation.mailgun.com/en/latest/api-domains.html)
401
408
 
402
- #### list
409
+ Example:
403
410
 
404
- `mg.domains.list(query)` - [api docs](https://documentation.mailgun.com/en/latest/api-domains.html)
411
+ ```js
412
+ mg.domains.list()
413
+ .then(domains => console.log(domains)) // logs array of domains
414
+ .catch(err => console.error(err)); // logs any error
415
+ ```
405
416
 
406
- Example:
417
+ Promise returns: array of Domain instances
418
+
419
+ ```JS
420
+ [{
421
+ created_at: 'Sun, 19 Oct 2014 18:49:36 GMT',
422
+ name: 'testing.example.com',
423
+ receiving_dns_records: null,
424
+ require_tls: true,
425
+ sending_dns_records: null,
426
+ skip_verification: true,
427
+ smtp_login: 'postmaster@testing.example.com',
428
+ smtp_password: 'password',
429
+ spam_action: 'disabled',
430
+ state: 'unverified',
431
+ type: 'custom',
432
+ wildcard: true
433
+ }]
434
+ ```
407
435
 
408
- ```js
409
- mg.domains.list()
410
- .then(domains => console.log(domains)) // logs array of domains
411
- .catch(err => console.error(err)); // logs any error
412
- ```
436
+ Query data may have next properties:
413
437
 
414
- Promise Returns: array of Domain instances
438
+ | Property | Description |
439
+ |:----------|:------------------------------------------------------|
440
+ | limit | Maximum number of records to return. (100 by default) |
441
+ | skip | Number of records to skip. (0 by default) |
415
442
 
416
- ```
417
- [{
418
- created_at: 'Sun, 19 Oct 2014 18:49:36 GMT',
419
- name: 'testing.example.com',
420
- receiving_dns_records: null,
421
- require_tls: true,
422
- sending_dns_records: null,
423
- skip_verification: true,
424
- smtp_login: 'postmaster@testing.example.com',
425
- smtp_password: 'password',
426
- spam_action: 'disabled',
427
- state: 'unverified',
428
- type: 'custom',
429
- wildcard: true
430
- }]
431
- ```
443
+ - #### get
432
444
 
433
- Options
445
+ `mg.domains.get()`
434
446
 
435
- | Parameter | Description |
436
- |:----------|:------------------------------------------------------|
437
- | limit | Maximum number of records to return. (100 by default) |
438
- | skip | Number of records to skip. (0 by default) |
447
+ Example:
439
448
 
440
- #### get
449
+ ```JS
450
+ mg.domains.get()
451
+ .then(domains => console.log(domains)) // logs array of domains
452
+ .catch(err => console.error(err)); // logs any error
453
+ ```
441
454
 
442
- `mg.domains.get()`
455
+ Promise returns: Domain instance
443
456
 
444
- Example:
457
+ ```JS
458
+ {
459
+ created_at: 'Sun, 19 Oct 2014 18:49:36 GMT',
460
+ name: 'testing.example.com',
461
+ receiving_dns_records: [{
462
+ "name": "testing.example.com",
463
+ "record_type": "TXT",
464
+ "valid": "unknown",
465
+ "value": "v=spf1 include:mailgun.org ~all"
466
+ },
467
+ {
468
+ "name": "k1._domainkey.testing.example.com",
469
+ "record_type": "TXT",
470
+ "valid": "unknown",
471
+ "value": "k=rsa; 123456"
472
+ },
473
+ {
474
+ "name": "email.testing.example.com",
475
+ "record_type": "CNAME",
476
+ "valid": "unknown",
477
+ "value": "mailgun.org"
478
+ }],
479
+ require_tls: true,
480
+ sending_dns_records: [{
481
+ "priority": "10",
482
+ "record_type": "MX",
483
+ "valid": "unknown",
484
+ "value": "mxa.mailgun.org"
485
+ },
486
+ {
487
+ "priority": "10",
488
+ "record_type": "MX",
489
+ "valid": "unknown",
490
+ "value": "mxb.mailgun.org"
491
+ }],
492
+ skip_verification: true,
493
+ smtp_login: 'postmaster@testing.example.com',
494
+ smtp_password: 'password',
495
+ spam_action: 'disabled',
496
+ state: 'unverified',
497
+ type: 'custom',
498
+ wildcard: true
499
+ }
500
+ ```
445
501
 
446
- ```js
447
- mg.domains.get()
448
- .then(domains => console.log(domains)) // logs array of domains
449
- .catch(err => console.error(err)); // logs any error
450
- ```
502
+ - #### create
451
503
 
452
- Promise Returns: Domain instance
504
+ `mg.domains.create(data)`
453
505
 
454
- ```
455
- {
456
- created_at: 'Sun, 19 Oct 2014 18:49:36 GMT',
457
- name: 'testing.example.com',
458
- receiving_dns_records: [{
459
- "name": "testing.example.com",
460
- "record_type": "TXT",
461
- "valid": "unknown",
462
- "value": "v=spf1 include:mailgun.org ~all"
463
- },
464
- {
465
- "name": "k1._domainkey.testing.example.com",
466
- "record_type": "TXT",
467
- "valid": "unknown",
468
- "value": "k=rsa; 123456"
469
- },
470
- {
471
- "name": "email.testing.example.com",
472
- "record_type": "CNAME",
473
- "valid": "unknown",
474
- "value": "mailgun.org"
475
- }],
476
- require_tls: true,
477
- sending_dns_records: [{
478
- "priority": "10",
479
- "record_type": "MX",
480
- "valid": "unknown",
481
- "value": "mxa.mailgun.org"
482
- },
483
- {
484
- "priority": "10",
485
- "record_type": "MX",
486
- "valid": "unknown",
487
- "value": "mxb.mailgun.org"
488
- }],
489
- skip_verification: true,
490
- smtp_login: 'postmaster@testing.example.com',
491
- smtp_password: 'password',
492
- spam_action: 'disabled',
493
- state: 'unverified',
494
- type: 'custom',
495
- wildcard: true
496
- }
497
- ```
506
+ Example:
498
507
 
499
- #### create
508
+ ```js
509
+ mg.domains.create({name: 'foobar.example.com'})
510
+ .then(msg => console.log(msg)) // logs response data
511
+ .catch(err => console.error(err)); // logs any error
512
+ ```
500
513
 
501
- `mg.domains.create(data)`
514
+ Create method accepts data object with next properties:
502
515
 
503
- Example:
516
+ | Property | Description |
517
+ |:--------------|:----------------------------------------------------------------------------------------------------------------------------------------------|
518
+ | name | Name of the domain (ex. domain.com) |
519
+ | smtp_password | Password for SMTP authentication |
520
+ | spam_action | disabled or tag Disable, no spam filtering will occur for inbound messages. Tag, messages will be tagged wtih a spam header. See Spam Filter. |
521
+ | wildcard | true or false Determines whether the domain will accept email for sub-domains. |
504
522
 
505
- ```js
506
- mg.domains.create({name: 'foobar.example.com'})
507
- .then(msg => console.log(msg)) // logs response data
508
- .catch(err => console.error(err)); // logs any error
509
- ```
523
+ Promise returns:
510
524
 
511
- Options:
525
+ ```JS
526
+ {
527
+ created_at: 'Sun, 19 Oct 2014 18:49:36 GMT',
528
+ name: 'foobar.example.com',
529
+ receiving_dns_records: [{
530
+ "name": "foobar.example.com",
531
+ "record_type": "TXT",
532
+ "valid": "unknown",
533
+ "value": "v=spf1 include:mailgun.org ~all"
534
+ },
535
+ {
536
+ "name": "k1._domainkey.foobar.example.com",
537
+ "record_type": "TXT",
538
+ "valid": "unknown",
539
+ "value": "k=rsa; 123456"
540
+ },
541
+ {
542
+ "name": "email.foobar.example.com",
543
+ "record_type": "CNAME",
544
+ "valid": "unknown",
545
+ "value": "mailgun.org"
546
+ }],
547
+ require_tls: true,
548
+ sending_dns_records: [{
549
+ "priority": "10",
550
+ "record_type": "MX",
551
+ "valid": "unknown",
552
+ "value": "mxa.mailgun.org"
553
+ },
554
+ {
555
+ "priority": "10",
556
+ "record_type": "MX",
557
+ "valid": "unknown",
558
+ "value": "mxb.mailgun.org"
559
+ }],
560
+ skip_verification: true,
561
+ smtp_login: 'postmaster@foobar.example.com',
562
+ smtp_password: 'password',
563
+ spam_action: 'disabled',
564
+ state: 'unverified',
565
+ type: 'custom',
566
+ wildcard: false
567
+ }
568
+ ```
569
+ - #### destroy
512
570
 
513
- | Parameter | Description |
514
- |:--------------|:----------------------------------------------------------------------------------------------------------------------------------------------|
515
- | name | Name of the domain (ex. domain.com) |
516
- | smtp_password | Password for SMTP authentication |
517
- | spam_action | disabled or tag Disable, no spam filtering will occur for inbound messages. Tag, messages will be tagged wtih a spam header. See Spam Filter. |
518
- | wildcard | true or false Determines whether the domain will accept email for sub-domains. |
571
+ `mg.domains.destroy(domainAddress)`
519
572
 
520
- Promise Returns: Domain instance
573
+ Example:
521
574
 
522
- ```
523
- {
524
- created_at: 'Sun, 19 Oct 2014 18:49:36 GMT',
525
- name: 'foobar.example.com',
526
- receiving_dns_records: [{
527
- "name": "foobar.example.com",
528
- "record_type": "TXT",
529
- "valid": "unknown",
530
- "value": "v=spf1 include:mailgun.org ~all"
531
- },
532
- {
533
- "name": "k1._domainkey.foobar.example.com",
534
- "record_type": "TXT",
535
- "valid": "unknown",
536
- "value": "k=rsa; 123456"
537
- },
538
- {
539
- "name": "email.foobar.example.com",
540
- "record_type": "CNAME",
541
- "valid": "unknown",
542
- "value": "mailgun.org"
543
- }],
544
- require_tls: true,
545
- sending_dns_records: [{
546
- "priority": "10",
547
- "record_type": "MX",
548
- "valid": "unknown",
549
- "value": "mxa.mailgun.org"
550
- },
551
- {
552
- "priority": "10",
553
- "record_type": "MX",
554
- "valid": "unknown",
555
- "value": "mxb.mailgun.org"
556
- }],
557
- skip_verification: true,
558
- smtp_login: 'postmaster@foobar.example.com',
559
- smtp_password: 'password',
560
- spam_action: 'disabled',
561
- state: 'unverified',
562
- type: 'custom',
563
- wildcard: false
564
- }
565
- ```
566
- #### destroy
575
+ ```JS
576
+ mg.domains.destroy('foobar.example.com')
577
+ .then(msg => console.log(msg)) // logs response data
578
+ .catch(err => console.error(err)); // logs any error
579
+ ```
567
580
 
568
- `mg.domains.destroy(domain)`
581
+ Promise returns:
569
582
 
570
- Example:
583
+ ```JS
584
+ {
585
+ message: "Domain has been deleted"
586
+ }
587
+ ```
571
588
 
572
- ```js
573
- mg.domains.destroy('foobar.example.com')
574
- .then(msg => console.log(msg)) // logs response data
575
- .catch(err => console.error(err)); // logs any error
576
- ```
589
+ - #### getTracking
577
590
 
578
- Promise Returns:
591
+ `mg.domains.getTracking(domainAddress)`
579
592
 
580
- ```
581
- {
582
- message: "Domain has been deleted"
583
- }
584
- ```
593
+ Example:
585
594
 
586
- #### getTracking
595
+ ```JS
596
+ mg.domains.getTracking('foobar.example.com')
597
+ .then(msg => console.log(msg)) // logs response data
598
+ .catch(err => console.error(err)); // logs any error
599
+ ```
587
600
 
588
- `mg.domains.getTracking(domain)`
601
+ Promise returns:
589
602
 
590
- Example:
603
+ ```JS
604
+ {
605
+ "click": {
606
+ "active": false
607
+ },
608
+ "open": {
609
+ "active": false
610
+ },
611
+ "unsubscribe": {
612
+ "active": false,
613
+ "html_footer": "\n<br>\n<p><a href=\"%unsubscribe_url%\">unsubscribe</a></p>\n",
614
+ "text_footer": "\n\nTo unsubscribe click: <%unsubscribe_url%>\n\n"
615
+ }
616
+ }
617
+ ```
591
618
 
592
- ```js
593
- mg.domains.getTracking('foobar.example.com')
594
- .then(msg => console.log(msg)) // logs response data
595
- .catch(err => console.error(err)); // logs any error
596
- ```
619
+ - #### updateTracking
597
620
 
598
- Promise Returns:
621
+ `mg.domains.updateTracking(domain, trackingType, data)`
599
622
 
600
- ```
601
- {
602
- "click": {
603
- "active": false
604
- },
605
- "open": {
606
- "active": false
607
- },
608
- "unsubscribe": {
609
- "active": false,
610
- "html_footer": "\n<br>\n<p><a href=\"%unsubscribe_url%\">unsubscribe</a></p>\n",
611
- "text_footer": "\n\nTo unsubscribe click: <%unsubscribe_url%>\n\n"
612
- }
613
- }
614
- ```
623
+ - Open Tracking Example:
615
624
 
616
- #### updateTracking
625
+ ```js
626
+ mg.domains.updateTracking('foobar.example.com', 'open', {active: true})
627
+ .then(msg => console.log(msg)) // logs response data
628
+ .catch(err => console.error(err)); // logs any error
629
+ ```
617
630
 
618
- `mg.domains.updateTracking(domain, trackingType, data)`
631
+ Open tracking data object properties:
619
632
 
620
- Open Tracking Example:
633
+ | Property | Description |
634
+ |:----------|:-------------------------------------------|
635
+ | active | Boolean, enables or disables open tracking |
621
636
 
622
- ```js
623
- mg.domains.updateTracking('foobar.example.com', 'open', {active: true})
624
- .then(msg => console.log(msg)) // logs response data
625
- .catch(err => console.error(err)); // logs any error
626
- ```
637
+ Promise returns:
627
638
 
628
- Open Tracking Options
639
+ ```JS
640
+ {
641
+ message: 'Tracking settings have been updated',
642
+ open: {
643
+ active: true
644
+ }
645
+ }
646
+ ```
629
647
 
630
- | Parameter | Description |
631
- |:----------|:-------------------------------------------|
632
- | active | Boolean, enables or disables open tracking |
648
+ - Click Tracking Example:
633
649
 
634
- Promise Returns:
650
+ ```JS
651
+ mg.domains.updateTracking('foobar.example.com', 'click', {active: true})
652
+ .then(msg => console.log(msg)) // logs response data
653
+ .catch(err => console.error(err)); // logs any error
654
+ ```
635
655
 
636
- ```
637
- {
638
- message: 'Tracking settings have been updated',
639
- open: {
640
- active: true
641
- }
642
- }
643
- ```
656
+ Click tracking data object properties:
644
657
 
645
- Click Tracking Example:
658
+ | Property | Description |
659
+ |:----------|:--------------------------------------------|
660
+ | active | Boolean, enables or disables click tracking |
646
661
 
647
- ```js
648
- mg.domains.updateTracking('foobar.example.com', 'click', {active: true})
649
- .then(msg => console.log(msg)) // logs response data
650
- .catch(err => console.error(err)); // logs any error
651
- ```
662
+ Promise returns:
652
663
 
653
- Click Tracking Options
664
+ ```JS
665
+ {
666
+ message: 'Tracking settings have been updated',
667
+ click: {
668
+ active: true
669
+ }
670
+ }
671
+ ```
654
672
 
655
- | Parameter | Description |
656
- |:----------|:--------------------------------------------|
657
- | active | Boolean, enables or disables click tracking |
673
+ - Unsubscribe Tracking Example:
658
674
 
659
- Promise Returns:
675
+ ```js
676
+ mg.domains.updateTracking('foobar.example.com', 'unsubscribe', {
677
+ active: true,
678
+ html_footer: "\n<br>\n<p><a href=\"%unsubscribe_url%\">unsubscribe</a></p>\n",
679
+ text_footer: "\n\nTo unsubscribe click: <%unsubscribe_url%>\n\n"
680
+ })
681
+ .then(msg => console.log(msg)) // logs response data
682
+ .catch(err => console.error(err)); // logs any error
683
+ ```
660
684
 
661
- ```
662
- {
663
- message: 'Tracking settings have been updated',
664
- click: {
665
- active: true
666
- }
667
- }
668
- ```
685
+ Unsubscribe Tracking data object properties:
669
686
 
670
- Unsubscribe Tracking Example:
687
+ | Property | Description |
688
+ |:------------|:--------------------------------------------------------------|
689
+ | active | Boolean, enables or disables unsubscribe tracking |
690
+ | html_footer | string appended to html emails for managing unsubscribe links |
691
+ | text_footer | string appended to html emails for managing unsubscribe links |
671
692
 
672
- ```js
673
- mg.domains.updateTracking('foobar.example.com', 'unsubscribe', {
674
- active: true,
675
- html_footer: "\n<br>\n<p><a href=\"%unsubscribe_url%\">unsubscribe</a></p>\n",
676
- text_footer: "\n\nTo unsubscribe click: <%unsubscribe_url%>\n\n"
677
- })
678
- .then(msg => console.log(msg)) // logs response data
679
- .catch(err => console.error(err)); // logs any error
680
- ```
693
+ Promise returns:
681
694
 
682
- Unsubscribe Tracking Options
695
+ ```JS
696
+ {
697
+ message: 'Tracking settings have been updated',
698
+ "unsubscribe": {
699
+ "active": true,
700
+ "html_footer": "\n<br>\n<p><a href=\"%unsubscribe_url%\">unsubscribe</a></p>\n",
701
+ "text_footer": "\n\nTo unsubscribe click: <%unsubscribe_url%>\n\n"
702
+ }
703
+ }
704
+ ```
683
705
 
684
- | Parameter | Description |
685
- |:------------|:--------------------------------------------------------------|
686
- | active | Boolean, enables or disables unsubscribe tracking |
687
- | html_footer | string appended to html emails for managing unsubscribe links |
688
- | text_footer | string appended to html emails for managing unsubscribe links |
706
+ - #### getIps
707
+ `mg.domains.getIps(domain)`
689
708
 
690
- Promise Returns:
709
+ Example:
691
710
 
692
- ```
693
- {
694
- message: 'Tracking settings have been updated',
695
- "unsubscribe": {
696
- "active": true,
697
- "html_footer": "\n<br>\n<p><a href=\"%unsubscribe_url%\">unsubscribe</a></p>\n",
698
- "text_footer": "\n\nTo unsubscribe click: <%unsubscribe_url%>\n\n"
699
- }
700
- }
701
- ```
711
+ ```js
712
+ mg.domains.getIps('foobar.example.com')
713
+ .then(msg => console.log(msg)) // logs response data
714
+ .catch(err => console.error(err)); // logs any error
715
+ ```
702
716
 
703
- #### getIps
704
- `mg.domains.getIps(domain)`
717
+ Promise returns:
705
718
 
706
- Example:
719
+ ```JS
720
+ ["192.168.0.1", "192.168.0.2"]
721
+ ```
707
722
 
708
- ```js
709
- mg.domains.getIps('foobar.example.com')
710
- .then(msg => console.log(msg)) // logs response data
711
- .catch(err => console.error(err)); // logs any error
712
- ```
723
+ - #### assignIp
724
+ `mg.domains.assignIp(domain, ip)`
713
725
 
714
- Promise Returns:
726
+ Example:
715
727
 
716
- ```
717
- ["192.168.0.1", "192.168.0.2"]
718
- ```
728
+ ```JS
729
+ mg.domains.assignIp('foobar.example.com', "192.168.0.3")
730
+ .then(msg => console.log(msg)) // logs response data
731
+ .catch(err => console.error(err)); // logs any error
732
+ ```
719
733
 
720
- #### assignIp
721
734
 
722
- `mg.domains.assignIp(domain, ip)`
735
+ ```JS
736
+ {
737
+ message: 'success',
738
+ status: 200,
739
+ }
740
+ ```
723
741
 
724
- Example:
742
+ - #### deleteIp
743
+ `mg.domains.deleteIp(domain, ip)`
725
744
 
726
- ```js
727
- mg.domains.assignIp('foobar.example.com', "192.168.0.3")
728
- .then(msg => console.log(msg)) // logs response data
729
- .catch(err => console.error(err)); // logs any error
730
- ```
745
+ Example:
731
746
 
747
+ ```JS
748
+ mg.domains.deleteIp('foobar.example.com', "192.168.0.3")
749
+ .then(msg => console.log(msg)) // logs response data
750
+ .catch(err => console.error(err)); // logs any error
751
+ ```
732
752
 
733
- ```
734
- {
735
- message: 'success'
736
- }
737
- ```
753
+ ```JS
754
+ {
755
+ message: 'success'
756
+ }
757
+ ```
738
758
 
739
- #### deleteIp
759
+ ### Events
740
760
 
741
- `mg.domains.deleteIp(domain, ip)`
761
+ - #### get
742
762
 
743
- Example:
763
+ `mg.events.get(domain, query)`
744
764
 
745
- ```js
746
- mg.domains.deleteIp('foobar.example.com', "192.168.0.3")
747
- .then(msg => console.log(msg)) // logs response data
748
- .catch(err => console.error(err)); // logs any error
749
- ```
765
+ Example:
750
766
 
767
+ ```js
768
+ mg.events.get('foobar.example.com', { page: 'mypageid' })
769
+ .then(data => console.log(data.items)) // logs array of event objects
770
+ .catch(err => console.error(err)); // logs any error
771
+ ```
751
772
 
752
- ```
753
- {
754
- message: 'success'
755
- }
756
- ```
773
+ Options:
757
774
 
758
775
 
759
- ### events
776
+ | Parameter | Description |
777
+ |:----------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
778
+ | page | Fetches the specified page of log records, assuming that the URL was returned by the previous request |
779
+ | begin | The beginning of the search time range. It can be specified as a string (see Date Format) or linux epoch seconds. Refer to Time Range for details. |
780
+ | end | The end of the search time range. It can be specified as a string (see Date Format) or linux epoch seconds. Refer to Time Range for details. |
781
+ | ascending | Defines the direction of the search time range if the range end time is not specified. Can be either yes or no. Refer to Time Range for details. |
782
+ | limit | Number of entries to return. (300 max) |
783
+ | <field> | <field> is the name of the Filter Field. The value of the parameter should be a valid Filter Expression. Several field filters can be specified in one request. If the same field is mentioned, more then once, then all its filter expressions are combined with AND operator. |
760
784
 
761
- #### get
785
+ Promise returns: items (array of event objects), pages (paging keys grouped by id)
762
786
 
763
- `mg.events.get(domain, query)`
787
+ ```JS
788
+ {
789
+ items: [{
790
+ type: 'accepted',
791
+ summary: 'got it',
792
+ content: { more: 'data' },
793
+ timestamp: Wed Nov 19 2014 10:32:57 GMT-0800 (PST) },
794
+ }],
795
+ pages: {
796
+ first: { id: 'first', number: 'W3siYSI6IGZhbHNlLC', url: 'apiurl' },
797
+ last: { id: 'last', number: 'W3siYSI6IGZhbHNlLC', url: 'apiurl' },
798
+ next: { id: 'next', number: W3siYSI6IGZhbHNlLC'', url: 'apiurl' },
799
+ previous: { id: 'previous', number: 'W3siYSI6IGZhbHNlLC', url: 'apiurl' }
800
+ }
801
+ }
802
+ ```
764
803
 
765
- Example:
804
+ ### Stats
805
+ - Stats Options
766
806
 
767
- ```js
768
- mg.events.get('foobar.example.com', { page: 'mypageid' })
769
- .then(data => console.log(data.items)) // logs array of event objects
770
- .catch(err => console.error(err)); // logs any error
771
- ```
807
+ | Parameter | Description |
808
+ |:-----------|:---------------------------------------------------------------------------------------------------------------------------|
809
+ | event | The type of the event. For a complete list of all events written to the log see the `Event Types` table below. (Required) |
810
+ | start | The starting time. Should be in :rfc:`2822#page-14` or unix epoch format. Default: 7 days from the current time. |
811
+ | end | The ending date. Should be in :rfc:`2822#page-14` or unix epoch format. Default: current time. |
812
+ | resolution | Can be either ``hour``, ``day`` or ``month``. Default: ``day`` |
813
+ | duration | Period of time with resolution encoded. If provided, overwrites the start date. See list below. |
772
814
 
773
- Options:
815
+ Duration is a string that represents a period of time with some resolution. It has a format `[0-9]+[m,d,h]` where
774
816
 
817
+ - `h` - an hour
818
+ - `d` - a day
819
+ - `m` - a month
775
820
 
776
- | Parameter | Description |
777
- |:----------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
778
- | page | Fetches the specified page of log records, assuming that the URL was returned by the previous request |
779
- | begin | The beginning of the search time range. It can be specified as a string (see Date Format) or linux epoch seconds. Refer to Time Range for details. |
780
- | end | The end of the search time range. It can be specified as a string (see Date Format) or linux epoch seconds. Refer to Time Range for details. |
781
- | ascending | Defines the direction of the search time range if the range end time is not specified. Can be either yes or no. Refer to Time Range for details. |
782
- | limit | Number of entries to return. (300 max) |
783
- | <field> | <field> is the name of the Filter Field. The value of the parameter should be a valid Filter Expression. Several field filters can be specified in one request. If the same field is mentioned, more then once, then all its filter expressions are combined with AND operator. |
821
+ Examples:
784
822
 
785
- Promise Returns: items (array of event objects), pages (paging keys grouped by id)
823
+ - `24h` - a period of 24 hours (a day) with hourly resolution
824
+ - `1d` - a period of 1 day with daily resolution
825
+ - `2m` - a period of 2 months with monthly resolution
786
826
 
787
- ```
788
- {
789
- items: [{
790
- type: 'accepted',
791
- summary: 'got it',
792
- content: { more: 'data' },
793
- timestamp: Wed Nov 19 2014 10:32:57 GMT-0800 (PST) },
794
- }],
795
- pages: {
796
- first: { id: 'first', number: 'W3siYSI6IGZhbHNlLC', url: 'apiurl' },
797
- last: { id: 'last', number: 'W3siYSI6IGZhbHNlLC', url: 'apiurl' },
798
- next: { id: 'next', number: W3siYSI6IGZhbHNlLC'', url: 'apiurl' },
799
- previous: { id: 'previous', number: 'W3siYSI6IGZhbHNlLC', url: 'apiurl' }
800
- }
801
- }
802
- ```
827
+ Event Types
803
828
 
804
- ### stats
829
+ | Event Type | Description |
830
+ |:-------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
831
+ | accepted | Mailgun accepted the request to send/forward the email and the message has been placed in queue. |
832
+ | delivered | Mailgun sent the email and it was accepted by the recipient email server. |
833
+ | failed | Mailgun could not deliver the email to the recipient email server. |
834
+ | opened | The email recipient opened the email and enabled image viewing. Open tracking must be enabled in the Mailgun control panel, and the CNAME record must be pointing to mailgun.org. |
835
+ | clicked | The email recipient clicked on a link in the email. Click tracking must be enabled in the Mailgun control panel, and the CNAME record must be pointing to mailgun.org. |
836
+ | unsubscribed | The email recipient clicked on the unsubscribe link. Unsubscribe tracking must be enabled in the Mailgun control panel. |
837
+ | complained | The email recipient clicked on the spam complaint button within their email client. Feedback loops enable the notification to be received by Mailgun. |
838
+ | stored | Mailgun has stored an incoming message
805
839
 
806
- Stats Options
840
+ - #### getDomain
807
841
 
808
- | Parameter | Description |
809
- |:-----------|:---------------------------------------------------------------------------------------------------------------------------|
810
- | event | The type of the event. For a complete list of all events written to the log see the `Event Types` table below. (Required) |
811
- | start | The starting time. Should be in :rfc:`2822#page-14` or unix epoch format. Default: 7 days from the current time. |
812
- | end | The ending date. Should be in :rfc:`2822#page-14` or unix epoch format. Default: current time. |
813
- | resolution | Can be either ``hour``, ``day`` or ``month``. Default: ``day`` |
814
- | duration | Period of time with resolution encoded. If provided, overwrites the start date. See list below. |
842
+ `mg.stats.getDomain(domain, query)`
815
843
 
816
- Duration is a string that represents a period of time with some resolution. It has a format `[0-9]+[m,d,h]` where
844
+ Example:
817
845
 
818
- - `h` - an hour
819
- - `d` - a day
820
- - `m` - a month
846
+ ```js
847
+ mg.stats.getDomain('foobar.example.com', {event: ['delivered', 'accepted', 'failed', 'complained']})
848
+ .then(msg => console.log(msg)) // logs response data
849
+ .catch(err => console.error(err)); // logs any error
850
+ ```
821
851
 
822
- Examples:
852
+ Promise returns:
823
853
 
824
- - `24h` - a period of 24 hours (a day) with hourly resolution
825
- - `1d` - a period of 1 day with daily resolution
826
- - `2m` - a period of 2 months with monthly resolution
854
+ ```JS
855
+ {
856
+ start: Sun Mar 15 2015 17:00:00 GMT-0700 (PDT),
857
+ end: Sun Mar 22 2015 17:00:00 GMT-0700 (PDT),
858
+ resolution: 'day',
859
+ stats: [{
860
+ time: Sun Mar 15 2015 17:00:00 GMT-0700 (PDT),
861
+ delivered: { smtp: 2, http: 1, total: 3 }
862
+ }]
863
+ }
864
+ ```
827
865
 
828
- Event Types
866
+ - #### getAccount
829
867
 
830
- | Event Type | Description |
831
- |:-------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
832
- | accepted | Mailgun accepted the request to send/forward the email and the message has been placed in queue. |
833
- | delivered | Mailgun sent the email and it was accepted by the recipient email server. |
834
- | failed | Mailgun could not deliver the email to the recipient email server. |
835
- | opened | The email recipient opened the email and enabled image viewing. Open tracking must be enabled in the Mailgun control panel, and the CNAME record must be pointing to mailgun.org. |
836
- | clicked | The email recipient clicked on a link in the email. Click tracking must be enabled in the Mailgun control panel, and the CNAME record must be pointing to mailgun.org. |
837
- | unsubscribed | The email recipient clicked on the unsubscribe link. Unsubscribe tracking must be enabled in the Mailgun control panel. |
838
- | complained | The email recipient clicked on the spam complaint button within their email client. Feedback loops enable the notification to be received by Mailgun. |
839
- | stored | Mailgun has stored an incoming message
868
+ `mg.stats.getDomain(domain, query)`
840
869
 
841
- #### getDomain
870
+ Example:
842
871
 
843
- `mg.stats.getDomain(domain, query)`
872
+ ```js
873
+ mg.stats.getDomain('foobar.example.com', {event: ['delivered', 'accepted', 'failed', 'complained']})
874
+ .then(msg => console.log(msg)) // logs response data
875
+ .catch(err => console.error(err)); // logs any error
876
+ ```
844
877
 
845
- Example:
878
+ Promise returns:
846
879
 
847
- ```js
848
- mg.stats.getDomain('foobar.example.com', {event: ['delivered', 'accepted', 'failed', 'complained']})
849
- .then(msg => console.log(msg)) // logs response data
850
- .catch(err => console.error(err)); // logs any error
851
- ```
880
+ ```JS
881
+ {
882
+ start: Sun Mar 15 2015 17:00:00 GMT-0700 (PDT),
883
+ end: Sun Mar 22 2015 17:00:00 GMT-0700 (PDT),
884
+ resolution: 'day',
885
+ stats: [{
886
+ time: Sun Mar 15 2015 17:00:00 GMT-0700 (PDT),
887
+ delivered: { smtp: 2, http: 1, total: 3 }
888
+ }]
889
+ }
890
+ ```
852
891
 
853
- Promise Returns:
892
+ ### Suppressions
854
893
 
855
- ```
856
- {
857
- start: Sun Mar 15 2015 17:00:00 GMT-0700 (PDT),
858
- end: Sun Mar 22 2015 17:00:00 GMT-0700 (PDT),
859
- resolution: 'day',
860
- stats: [{
861
- time: Sun Mar 15 2015 17:00:00 GMT-0700 (PDT),
862
- delivered: { smtp: 2, http: 1, total: 3 }
863
- }]
864
- }
865
- ```
894
+ - #### list
866
895
 
867
- #### getAccount
896
+ `mg.suppressions.list(domain, suppressionType, query?)`
868
897
 
869
- `mg.stats.getDomain(domain, query)`
898
+ - Bounces Example:
870
899
 
871
- Example:
900
+ ```js
901
+ mg.suppressions.list('foobar.example.com', 'bounces')
902
+ .then(msg => console.log(msg)) // logs response data
903
+ .catch(err => console.error(err)); // logs any error
904
+ ```
872
905
 
873
- ```js
874
- mg.stats.getDomain('foobar.example.com', {event: ['delivered', 'accepted', 'failed', 'complained']})
875
- .then(msg => console.log(msg)) // logs response data
876
- .catch(err => console.error(err)); // logs any error
877
- ```
906
+ - Unsubscribes Example:
878
907
 
879
- Promise Returns:
908
+ ```js
909
+ mg.suppressions.list('foobar.example.com', 'unsubscribes')
910
+ .then(msg => console.log(msg)) // logs response data
911
+ .catch(err => console.error(err)); // logs any error
912
+ ```
880
913
 
881
- ```
882
- {
883
- start: Sun Mar 15 2015 17:00:00 GMT-0700 (PDT),
884
- end: Sun Mar 22 2015 17:00:00 GMT-0700 (PDT),
885
- resolution: 'day',
886
- stats: [{
887
- time: Sun Mar 15 2015 17:00:00 GMT-0700 (PDT),
888
- delivered: { smtp: 2, http: 1, total: 3 }
889
- }]
890
- }
891
- ```
914
+ - Complaints Example:
892
915
 
893
- ### suppressions
916
+ ```js
917
+ mg.suppressions.list('foobar.example.com', 'complaints')
918
+ .then(msg => console.log(msg)) // logs response data
919
+ .catch(err => console.error(err)); // logs any error
920
+ ```
894
921
 
895
- #### list
922
+ Promise returns:
896
923
 
897
- `mg.suppressions.list(domain, suppressionType, query)`
924
+ ```JS
925
+ {
926
+ items: [
927
+ {
928
+ type: "bounces",
929
+ address: "unknown@unknown.com",
930
+ code: 550,
931
+ error: "No such mailbox",
932
+ created_at: Fri Oct 21 2011 04:02:55 GMT-0700 (PDT)
933
+ }],
934
+ pages: {
935
+ first: { id: "first", page: "", address: "", url: "apiurl" },
936
+ last: { id: "last", page: "", address: "", url: "apiurl" },
937
+ next: { id: "next", page: "", address: "", url: "apiurl" },
938
+ previous: { id: "prev", page: "", address: "", url: "apiurl" }
939
+ }
940
+ }
941
+ ```
898
942
 
899
- Bounces Example:
943
+ - #### get
900
944
 
901
- ```js
902
- mg.suppressions.list('foobar.example.com', 'bounces')
903
- .then(msg => console.log(msg)) // logs response data
904
- .catch(err => console.error(err)); // logs any error
905
- ```
945
+ `mg.suppressions.get(domain, suppressionType, address)`
906
946
 
907
- Unsubscribes Example:
947
+ - Bounces Example:
908
948
 
909
- ```js
910
- mg.suppressions.list('foobar.example.com', 'unsubscribes')
911
- .then(msg => console.log(msg)) // logs response data
912
- .catch(err => console.error(err)); // logs any error
913
- ```
949
+ ```js
950
+ mg.suppressions.get('foobar.example.com', 'bounces', 'address@example.com')
951
+ .then(msg => console.log(msg)) // logs response data
952
+ .catch(err => console.error(err)); // logs any error
953
+ ```
914
954
 
915
- Complaints Example:
955
+ - Unsubscribes Example:
916
956
 
917
- ```js
918
- mg.suppressions.list('foobar.example.com', 'complaints')
919
- .then(msg => console.log(msg)) // logs response data
920
- .catch(err => console.error(err)); // logs any error
921
- ```
957
+ ```js
958
+ mg.suppressions.get('foobar.example.com', 'unsubscribes', 'address@example.com')
959
+ .then(msg => console.log(msg)) // logs response data
960
+ .catch(err => console.error(err)); // logs any error
961
+ ```
922
962
 
923
- Promise Returns:
963
+ - Complaints Example:
924
964
 
925
- ```
926
- {
927
- items: [
928
- {
929
- type: 'bounces',
930
- address: 'unknown@unknown.com',
931
- code: 550,
932
- error: 'No such mailbox',
933
- created_at: Fri Oct 21 2011 04:02:55 GMT-0700 (PDT)
934
- }
935
- ],
936
- pages: {
937
- first: { id: 'first', page: '', address: '', url: 'apiurl' },
938
- last: { id: 'last', page: '', address: '', url: 'apiurl' },
939
- next: { id: 'next', page: '', address: '', url: 'apiurl' },
940
- previous: { id: 'prev', page: '', address: '', url: 'apiurl' }
965
+ ```js
966
+ mg.suppressions.get('foobar.example.com', 'complaints', 'address@example.com')
967
+ .then(msg => console.log(msg)) // logs response data
968
+ .catch(err => console.error(err)); // logs any error
969
+ ```
970
+
971
+ Response example:
972
+
973
+ ```JS
974
+ {
975
+ type: "bounces",
976
+ address: "address?@unknown.com",
977
+ tags: [ "*" ],
978
+ created_at: Fri Oct 21 2011 05:02:55 GMT-0700 (PDT)
941
979
  }
942
- }
943
- ```
980
+ ```
944
981
 
945
- #### get
982
+ - #### create
983
+ `mg.suppressions.create(domain, suppressionType, data || data[])`
946
984
 
947
- `mg.suppressions.get(domain, suppressionType, address)`
985
+ - Bounces Example:
986
+ ```JS
987
+ mg.suppressions.create('foobar.example.com', 'bounces', [{address: 'bob@example.com'}])
988
+ .then(msg => console.log(msg)) // logs response data
989
+ .catch(err => console.error(err)); // logs any error
990
+ ```
948
991
 
949
- Bounces Example:
992
+ Bounces Options: Contains an array with the following object properties
950
993
 
951
- ```js
952
- mg.suppressions.get('foobar.example.com', 'bounces', 'address@example.com')
953
- .then(msg => console.log(msg)) // logs response data
954
- .catch(err => console.error(err)); // logs any error
955
- ```
994
+ | Parameter | Description |
995
+ |:-----------|:--------------------------------------------------------------------------------|
996
+ | address | Valid email address |
997
+ | code | Error code (optional, default: 550) |
998
+ | error | Error description (optional, default: empty string) |
999
+ | created_at | Timestamp of a bounce event in RFC2822 format (optional, default: current time) |
956
1000
 
957
- Unsubscribes Example:
1001
+ Promise returns:
958
1002
 
959
- ```js
960
- mg.suppressions.get('foobar.example.com', 'unsubscribes', 'address@example.com')
961
- .then(msg => console.log(msg)) // logs response data
962
- .catch(err => console.error(err)); // logs any error
963
- ```
1003
+ ```JSON
1004
+ {
1005
+ message: "1 address has been added to the bounces table"
1006
+ }
1007
+ ```
964
1008
 
965
- Complaints Example:
1009
+ - Unsubscribes Example:
966
1010
 
967
- ```js
968
- mg.suppressions.get('foobar.example.com', 'complaints', 'address@example.com')
969
- .then(msg => console.log(msg)) // logs response data
970
- .catch(err => console.error(err)); // logs any error
971
- ```
1011
+ ```js
1012
+ mg.suppressions.create('foobar.example.com', 'unsubscribes', [{address: 'bob@example.com'}])
1013
+ .then(msg => console.log(msg)) // logs response data
1014
+ .catch(err => console.error(err)); // logs any error
1015
+ ```
972
1016
 
973
- Options:
1017
+ Unsubscribes Options: Contains an array with the following object properties
974
1018
 
975
- Promise Returns:
1019
+ | Parameter | Description |
1020
+ |:-----------|:-----------------------------------------------------------------------------------------------------------------|
1021
+ | address | Valid email address |
1022
+ | tag | Tag to unsubscribe from, use * to unsubscribe an address from all domain’s correspondence (optional, default: *) |
1023
+ | created_at | Timestamp of a bounce event in RFC2822 format (optional, default: current time) |
976
1024
 
977
- ```
978
- {
979
- type: 'bounces',
980
- address: 'address?@unknown.com',
981
- tags: [ '*' ],
982
- created_at: Fri Oct 21 2011 05:02:55 GMT-0700 (PDT)
983
- }
984
- ```
1025
+ Promise returns:
985
1026
 
986
- #### create
1027
+ ```JS
1028
+ {
1029
+ message: "1 address has been added to the unsubscribes table"
1030
+ }
1031
+ ```
987
1032
 
988
- `mg.suppressions.create(domain, suppressionType, array)`
1033
+ - Complaints Example:
989
1034
 
990
- Bounces Example:
1035
+ ```js
1036
+ mg.suppressions.create('foobar.example.com', 'complaints', [{address: 'bob@example.com'}])
1037
+ .then(msg => console.log(msg)) // logs response data
1038
+ .catch(err => console.error(err)); // logs any error
1039
+ ```
991
1040
 
992
- ```js
993
- mg.suppressions.create('foobar.example.com', 'bounces', [{address: 'bob@example.com'}])
994
- .then(msg => console.log(msg)) // logs response data
995
- .catch(err => console.error(err)); // logs any error
996
- ```
1041
+ Complaints Options: Contains an array with the following object properties
997
1042
 
998
- Bounces Options: Contains an array with the following object properties
1043
+ | Parameter | Description |
1044
+ |:-----------|:-----------------------------------------------------------------------------------------------------------------|
1045
+ | address | Valid email address |
1046
+ | created_at | Timestamp of a bounce event in RFC2822 format (optional, default: current time) |
999
1047
 
1000
- | Parameter | Description |
1001
- |:-----------|:--------------------------------------------------------------------------------|
1002
- | address | Valid email address |
1003
- | code | Error code (optional, default: 550) |
1004
- | error | Error description (optional, default: empty string) |
1005
- | created_at | Timestamp of a bounce event in RFC2822 format (optional, default: current time) |
1048
+ Promise returns:
1006
1049
 
1007
- Promise Returns:
1050
+ ```JS
1051
+ {
1052
+ message: "1 address has been added to the complaints table"
1053
+ }
1054
+ ```
1008
1055
 
1009
- ```
1010
- {
1011
- message: "1 address has been added to the bounces table"
1012
- }
1013
- ```
1056
+ - #### destroy
1057
+ `mg.suppressions.destroy(domain, suppressionType, address)`
1014
1058
 
1015
- Unsubscribes Example:
1059
+ - Bounces Example:
1016
1060
 
1017
- ```js
1018
- mg.suppressions.create('foobar.example.com', 'unsubscribes', [{address: 'bob@example.com'}])
1019
- .then(msg => console.log(msg)) // logs response data
1020
- .catch(err => console.error(err)); // logs any error
1021
- ```
1061
+ ```JS
1062
+ mg.suppressions.destroy('foobar.example.com', 'bounces', 'bob@example.com')
1063
+ .then(msg => console.log(msg)) // logs response data
1064
+ .catch(err => console.error(err)); // logs any error
1065
+ ```
1066
+
1067
+ Promise returns:
1022
1068
 
1023
- Unsubscribes Options: Contains an array with the following object properties
1069
+ ```JS
1070
+ {
1071
+ message: "Bounced address has been removed",
1072
+ value: "",
1073
+ address: "bob@example.com",
1074
+ status: 200
1075
+ }
1076
+ ```
1024
1077
 
1025
- | Parameter | Description |
1026
- |:-----------|:-----------------------------------------------------------------------------------------------------------------|
1027
- | address | Valid email address |
1028
- | tag | Tag to unsubscribe from, use * to unsubscribe an address from all domain’s correspondence (optional, default: *) |
1029
- | created_at | Timestamp of a bounce event in RFC2822 format (optional, default: current time) |
1078
+ - Unsubscribes Example:
1030
1079
 
1031
- Promise Returns:
1080
+ ```js
1081
+ mg.suppressions.destroy('foobar.example.com', 'unsubscribes', 'bob@example.com')
1082
+ .then(msg => console.log(msg)) // logs response data
1083
+ .catch(err => console.error(err)); // logs any error
1084
+ ```
1032
1085
 
1033
- ```
1034
- {
1035
- message: "1 address has been added to the unsubscribes table"
1036
- }
1037
- ```
1086
+ Promise returns:
1038
1087
 
1039
- Complaints Example:
1088
+ ```JS
1089
+ {
1090
+ message: 'Unsubscribe event has been removed',
1091
+ value: '',
1092
+ address: 'bob@example.com',
1093
+ status: 200
1094
+ }
1095
+ ```
1040
1096
 
1041
- ```js
1042
- mg.suppressions.create('foobar.example.com', 'complaints', [{address: 'bob@example.com'}])
1043
- .then(msg => console.log(msg)) // logs response data
1044
- .catch(err => console.error(err)); // logs any error
1045
- ```
1097
+ - Complaints Example:
1046
1098
 
1047
- Complaints Options: Contains an array with the following object properties
1099
+ ```js
1100
+ mg.suppressions.destroy('foobar.example.com', 'complaints', 'bob@example.com')
1101
+ .then(msg => console.log(msg)) // logs response data
1102
+ .catch(err => console.error(err)); // logs any error
1103
+ ```
1048
1104
 
1049
- | Parameter | Description |
1050
- |:-----------|:-----------------------------------------------------------------------------------------------------------------|
1051
- | address | Valid email address |
1052
- | created_at | Timestamp of a bounce event in RFC2822 format (optional, default: current time) |
1105
+ Promise returns:
1053
1106
 
1054
- Promise Returns:
1107
+ ```JS
1108
+ message: 'Spam complaint has been removed',
1109
+ value: '',
1110
+ address: 'bob@example.com',
1111
+ status: 200
1112
+ ```
1055
1113
 
1056
- ```
1057
- {
1058
- message: "1 address has been added to the complaints table"
1059
- }
1060
- ```
1061
1114
 
1062
- ### webhooks
1115
+ ### Webhooks
1063
1116
 
1064
- #### list
1117
+ - #### list
1065
1118
 
1066
- `mg.webhooks.list(domain, query)`
1119
+ `mg.webhooks.list(domain, query)`
1067
1120
 
1068
- Example:
1121
+ Example:
1069
1122
 
1070
- ```js
1071
- mg.webhooks.list('foobar.example.com')
1072
- .then(msg => console.log(msg)) // logs response data
1073
- .catch(err => console.error(err)); // logs any error
1074
- ```
1123
+ ```js
1124
+ mg.webhooks.list('foobar.example.com')
1125
+ .then(msg => console.log(msg)) // logs response data
1126
+ .catch(err => console.error(err)); // logs any error
1127
+ ```
1075
1128
 
1076
- Promise Returns:
1129
+ Promise returns:
1077
1130
 
1078
- ```
1079
- {
1080
- open: { 'url': 'http://requestb.in' },
1081
- click: { 'url': 'http://requestb.in' },
1082
- bounce: { 'url': 'http://requestb.in' },
1083
- deliver: { 'url': 'http://requestb.in' },
1084
- drop: { 'url': 'http://requestb.in' },
1085
- spam: { 'url': 'http://requestb.in' },
1086
- unsubscribe: { 'url': 'http://requestb.in' },
1087
- click: { 'url': 'http://requestb.in' },
1088
- open: { 'url': 'http://requestb.in' },
1089
- }
1090
- ```
1131
+ ```JS
1132
+ {
1133
+ open: { 'url': 'http://requestb.in' },
1134
+ click: { 'url': 'http://requestb.in' },
1135
+ bounce: { 'url': 'http://requestb.in' },
1136
+ deliver: { 'url': 'http://requestb.in' },
1137
+ drop: { 'url': 'http://requestb.in' },
1138
+ spam: { 'url': 'http://requestb.in' },
1139
+ unsubscribe: { 'url': 'http://requestb.in' },
1140
+ click: { 'url': 'http://requestb.in' },
1141
+ open: { 'url': 'http://requestb.in' },
1142
+ }
1143
+ ```
1091
1144
 
1092
- #### get
1145
+ - #### get
1093
1146
 
1094
- `mg.webhooks.get(domain, id)`
1147
+ `mg.webhooks.get(domain, id)`
1095
1148
 
1096
- Example:
1149
+ Example:
1097
1150
 
1098
- ```js
1099
- mg.webhooks.get('foobar.example.com', 'open') // bounce, deliver, drop, spam, unsubscribe, click, open
1100
- .then(msg => console.log(msg)) // logs response data
1101
- .catch(err => console.error(err)); // logs any error
1102
- ```
1151
+ ```js
1152
+ mg.webhooks.get('foobar.example.com', 'open') // bounce, deliver, drop, spam, unsubscribe, click, open
1153
+ .then(msg => console.log(msg)) // logs response data
1154
+ .catch(err => console.error(err)); // logs any error
1155
+ ```
1103
1156
 
1104
- Promise Returns:
1157
+ Promise returns:
1105
1158
 
1106
- ```
1107
- {
1108
- 'open': { 'url': 'http://requestb.in' }
1109
- }
1110
- ```
1159
+ ```JS
1160
+ {
1161
+ 'open': { 'url': 'http://requestb.in' }
1162
+ }
1163
+ ```
1111
1164
 
1112
- #### create
1165
+ - #### create
1113
1166
 
1114
- `mg.webhooks.create(domain, id, data, test)`
1167
+ `mg.webhooks.create(domain, id, data, test)`
1115
1168
 
1116
- Example:
1169
+ Example:
1117
1170
 
1118
- ```js
1119
- mg.webhooks.create('foobar.example.com', 'open', 'http://requestb.in') // bounce, deliver, drop, spam, unsubscribe, click, open
1120
- .then(msg => console.log(msg)) // logs response data
1121
- .catch(err => console.error(err)); // logs any error
1122
- ```
1171
+ ```js
1172
+ mg.webhooks.create('foobar.example.com', 'open', 'http://requestb.in') // bounce, deliver, drop, spam, unsubscribe, click, open
1173
+ .then(msg => console.log(msg)) // logs response data
1174
+ .catch(err => console.error(err)); // logs any error
1175
+ ```
1123
1176
 
1124
- Promise Returns:
1177
+ Promise returns:
1125
1178
 
1126
- ```
1127
- {
1128
- 'open': { 'url': 'http://requestb.in' }
1129
- }
1130
- ```
1179
+ ```JS
1180
+ {
1181
+ 'open': { 'url': 'http://requestb.in' }
1182
+ }
1183
+ ```
1131
1184
 
1132
- Test Webhook Example:
1185
+ Test Webhook Example:
1133
1186
 
1134
- ```js
1135
- mg.webhooks.get('foobar.example.com', 'open', 'http://requestb.in', true) // bounce, deliver, drop, spam, unsubscribe, click, open
1136
- .then(msg => console.log(msg)) // logs response data
1137
- .catch(err => console.error(err)); // logs any error
1138
- ```
1187
+ ```JS
1188
+ mg.webhooks.get('foobar.example.com', 'open', 'http://requestb.in', true) // bounce, deliver, drop, spam, unsubscribe, click, open
1189
+ .then(msg => console.log(msg)) // logs response data
1190
+ .catch(err => console.error(err)); // logs any error
1191
+ ```
1139
1192
 
1140
- Promise Returns:
1193
+ Promise returns:
1141
1194
 
1142
- ```
1143
- {
1144
- 'code': '500',
1145
- 'message': 'Hi!'
1146
- }
1147
- ```
1195
+ ```JS
1196
+ {
1197
+ 'code': '500',
1198
+ 'message': 'Hi!'
1199
+ }
1200
+ ```
1148
1201
 
1149
- #### update
1202
+ - #### update
1150
1203
 
1151
- `mg.webhooks.update(domain, id, url, test)`
1204
+ `mg.webhooks.update(domain, id, url, test)`
1152
1205
 
1153
- Example:
1206
+ Example:
1154
1207
 
1155
- ```js
1156
- mg.webhooks.update('foobar.example.com', 'open', 'http://requestb.in') // bounce, deliver, drop, spam, unsubscribe, click, open
1157
- .then(msg => console.log(msg)) // logs response data
1158
- .catch(err => console.error(err)); // logs any error
1159
- ```
1208
+ ```js
1209
+ mg.webhooks.update('foobar.example.com', 'open', 'http://requestb.in') // bounce, deliver, drop, spam, unsubscribe, click, open
1210
+ .then(msg => console.log(msg)) // logs response data
1211
+ .catch(err => console.error(err)); // logs any error
1212
+ ```
1160
1213
 
1161
- Promise Returns:
1214
+ Promise returns:
1162
1215
 
1163
- ```
1164
- {
1165
- 'open': { 'url': 'http://requestb.in' }
1166
- }
1167
- ```
1216
+ ```JS
1217
+ {
1218
+ 'open': { 'url': 'http://requestb.in' }
1219
+ }
1220
+ ```
1168
1221
 
1169
- #### destroy
1222
+ - #### destroy
1170
1223
 
1171
- `mg.webhooks.destroy(domain, id)`
1224
+ `mg.webhooks.destroy(domain, id)`
1172
1225
 
1173
- Example:
1226
+ Example:
1174
1227
 
1175
- ```js
1176
- mg.webhooks.update('foobar.example.com', 'open') // bounce, deliver, drop, spam, unsubscribe, click, open
1177
- .then(msg => console.log(msg)) // logs response data
1178
- .catch(err => console.error(err)); // logs any error
1179
- ```
1228
+ ```JS
1229
+ mg.webhooks.update('foobar.example.com', 'open') // bounce, deliver, drop, spam, unsubscribe, click, open
1230
+ .then(msg => console.log(msg)) // logs response data
1231
+ .catch(err => console.error(err)); // logs any error
1232
+ ```
1180
1233
 
1181
- Promise Returns:
1234
+ Promise returns:
1182
1235
 
1183
- ```
1184
- {
1185
- 'open': { 'url': 'http://requestb.in' }
1186
- }
1187
- ```
1236
+ ```JS
1237
+ {
1238
+ 'open': { 'url': 'http://requestb.in' }
1239
+ }
1240
+ ```
1188
1241
 
1189
- ### routes
1242
+ ### Routes
1190
1243
 
1191
- #### list
1244
+ - #### list
1192
1245
 
1193
- `mg.routes.list(query)`
1246
+ `mg.routes.list(query)`
1194
1247
 
1195
- Example:
1248
+ Example:
1196
1249
 
1197
- ```js
1198
- mg.routes.list()
1199
- .then(data => console.log(data)) // logs response body
1200
- .catch(err => console.error(err)); // logs any error
1201
- ```
1250
+ ```JS
1251
+ mg.routes.list()
1252
+ .then(data => console.log(data)) // logs response body
1253
+ .catch(err => console.error(err)); // logs any error
1254
+ ```
1202
1255
 
1203
- Promise Returns: response body
1256
+ Promise returns:
1204
1257
 
1205
- ```
1206
- [
1258
+ ```JS
1259
+ [
1260
+ {
1261
+ actions: [ 'forward("http://myhost.com/messages/")', 'stop()' ],
1262
+ created_at: 'Mon, 26 Oct 2015 03:56:51 GMT',
1263
+ description: 'sample',
1264
+ expression: 'match_recipient(".*@example.com")',
1265
+ id: '562da483125730608a7d1719',
1266
+ priority: 0
1267
+ }
1268
+ ]
1269
+ ```
1270
+
1271
+ - #### get
1272
+
1273
+ `mg.routes.get(id)`
1274
+
1275
+ Example:
1276
+
1277
+ ```js
1278
+ mg.routes.get('562da483125730608a7d1719')
1279
+ .then(data => console.log(data)) // logs response body
1280
+ .catch(err => console.error(err)); // logs any error
1281
+ ```
1282
+
1283
+ Promise returns: response body
1284
+
1285
+ ```JS
1207
1286
  {
1208
1287
  actions: [ 'forward("http://myhost.com/messages/")', 'stop()' ],
1209
1288
  created_at: 'Mon, 26 Oct 2015 03:56:51 GMT',
@@ -1212,594 +1291,568 @@ Promise Returns: response body
1212
1291
  id: '562da483125730608a7d1719',
1213
1292
  priority: 0
1214
1293
  }
1215
- ]
1216
- ```
1217
-
1218
- #### get
1294
+ ```
1219
1295
 
1220
- `mg.routes.get(id)`
1296
+ - #### create
1221
1297
 
1222
- Example:
1298
+ `mg.routes.create(options)`
1223
1299
 
1224
- ```js
1225
- mg.routes.get('562da483125730608a7d1719')
1226
- .then(data => console.log(data)) // logs response body
1227
- .catch(err => console.error(err)); // logs any error
1228
- ```
1300
+ Example:
1229
1301
 
1230
- Promise Returns: response body
1231
-
1232
- ```
1233
- {
1234
- actions: [ 'forward("http://myhost.com/messages/")', 'stop()' ],
1235
- created_at: 'Mon, 26 Oct 2015 03:56:51 GMT',
1236
- description: 'sample',
1237
- expression: 'match_recipient(".*@example.com")',
1238
- id: '562da483125730608a7d1719',
1239
- priority: 0
1240
- }
1241
- ```
1242
-
1243
- #### create
1244
-
1245
- `mg.routes.create(options)`
1302
+ ```JS
1303
+ mg.routes.create({
1304
+ priority: 0,
1305
+ description: 'sample',
1306
+ expression: 'match_recipient(".*@example.org")',
1307
+ action: ['forward("http://myhost.com/messages/")', 'stop()']
1308
+ })
1309
+ .then(data => console.log(data)) // logs response body
1310
+ .catch(err => console.error(err)); // logs any error
1311
+ ```
1246
1312
 
1247
- Example:
1313
+ Promise returns: response body
1248
1314
 
1249
- ```js
1250
- mg.routes.create({
1251
- priority: 0,
1315
+ ```JS
1316
+ {
1317
+ actions: [ 'forward("http://myhost.com/messages/")', 'stop()' ],
1318
+ created_at: 'Mon, 26 Oct 2015 03:56:51 GMT',
1252
1319
  description: 'sample',
1253
- expression: 'match_recipient(".*@example.org")',
1254
- action: ['forward("http://myhost.com/messages/")', 'stop()']
1255
- })
1256
- .then(data => console.log(data)) // logs response body
1257
- .catch(err => console.error(err)); // logs any error
1258
- ```
1320
+ expression: 'match_recipient(".*@example.com")',
1321
+ id: '562da483125730608a7d1719',
1322
+ priority: 0
1323
+ }
1324
+ ```
1259
1325
 
1260
- Promise Returns: response body
1326
+ - #### update
1261
1327
 
1262
- ```
1263
- {
1264
- actions: [ 'forward("http://myhost.com/messages/")', 'stop()' ],
1265
- created_at: 'Mon, 26 Oct 2015 03:56:51 GMT',
1266
- description: 'sample',
1267
- expression: 'match_recipient(".*@example.com")',
1268
- id: '562da483125730608a7d1719',
1269
- priority: 0
1270
- }
1271
- ```
1328
+ `mg.routes.update(id, options)`
1272
1329
 
1273
- #### update
1330
+ Example:
1274
1331
 
1275
- `mg.routes.update(id, options)`
1332
+ ```JS
1333
+ mg.routes.update('562da483125730608a7d1719', {
1334
+ priority: 0,
1335
+ description: 'sample',
1336
+ expression: 'match_recipient(".*@example.org")',
1337
+ action: ['forward("http://myhost.com/messages/")', 'stop()']
1338
+ })
1339
+ .then(data => console.log(data)) // logs response body
1340
+ .catch(err => console.error(err)); // logs any error
1341
+ ```
1276
1342
 
1277
- Example:
1343
+ Promise returns: response body
1278
1344
 
1279
- ```js
1280
- mg.routes.update('562da483125730608a7d1719', {
1281
- priority: 0,
1345
+ ```JS
1346
+ {
1347
+ actions: [ 'forward("http://myhost.com/messages/")', 'stop()' ],
1348
+ created_at: 'Mon, 26 Oct 2015 03:56:51 GMT',
1282
1349
  description: 'sample',
1283
- expression: 'match_recipient(".*@example.org")',
1284
- action: ['forward("http://myhost.com/messages/")', 'stop()']
1285
- })
1286
- .then(data => console.log(data)) // logs response body
1287
- .catch(err => console.error(err)); // logs any error
1288
- ```
1289
-
1290
- Promise Returns: response body
1291
-
1292
- ```
1293
- {
1294
- actions: [ 'forward("http://myhost.com/messages/")', 'stop()' ],
1295
- created_at: 'Mon, 26 Oct 2015 03:56:51 GMT',
1296
- description: 'sample',
1297
- expression: 'match_recipient(".*@example.com")',
1298
- id: '562da483125730608a7d1719',
1299
- message: 'Route has been updated',
1300
- priority: 0
1301
- }
1302
- ```
1350
+ expression: 'match_recipient(".*@example.com")',
1351
+ id: '562da483125730608a7d1719',
1352
+ message: 'Route has been updated',
1353
+ priority: 0
1354
+ }
1355
+ ```
1303
1356
 
1304
- #### destroy
1357
+ - #### destroy
1305
1358
 
1306
- `mg.routes.destroy(id)`
1359
+ `mg.routes.destroy(id)`
1307
1360
 
1308
- Example:
1361
+ Example:
1309
1362
 
1310
- ```js
1311
- mg.routes.destroy('562da483125730608a7d1719')
1312
- .then(data => console.log(data)) // logs response body
1313
- .catch(err => console.error(err)); // logs any error
1314
- ```
1363
+ ```js
1364
+ mg.routes.destroy('562da483125730608a7d1719')
1365
+ .then(data => console.log(data)) // logs response body
1366
+ .catch(err => console.error(err)); // logs any error
1367
+ ```
1315
1368
 
1316
- Promise Returns: response body
1369
+ Promise returns: response body
1317
1370
 
1318
- ```
1319
- {
1320
- id: '562da483125730608a7d1719',
1321
- message: 'Route has been deleted'
1322
- }
1323
- ```
1371
+ ```JS
1372
+ {
1373
+ id: '562da483125730608a7d1719',
1374
+ message: 'Route has been deleted'
1375
+ }
1376
+ ```
1324
1377
 
1325
- ### validate
1378
+ ### Validation
1326
1379
 
1327
- #### get
1380
+ - #### get
1328
1381
 
1329
- `mg.validate.get(address)`
1382
+ `mg.validate.get(address)`
1330
1383
 
1331
- Example:
1384
+ Example:
1332
1385
 
1333
- ```js
1334
- mg.validate.get('foo@mailgun.net')
1335
- .then(data => console.log(data)) // logs response body
1336
- .catch(err => console.error(err)); // logs any error
1337
- ```
1386
+ ```JS
1387
+ mg.validate.get('foo@mailgun.net')
1388
+ .then(data => console.log(data)) // logs response body
1389
+ .catch(err => console.error(err)); // logs any error
1390
+ ```
1338
1391
 
1339
- Promise Returns: response body
1392
+ Promise returns: response body
1340
1393
 
1341
- ```
1342
- {
1343
- address: 'alice@example.com',
1344
- did_you_mean: null,
1345
- is_valid: false,
1346
- parts: { display_name: null, domain: null, local_part: null }
1347
- }
1348
- ```
1394
+ ```JS
1395
+ {
1396
+ address: 'alice@example.com',
1397
+ did_you_mean: null,
1398
+ is_valid: false,
1399
+ parts: {
1400
+ display_name: null,
1401
+ domain: null,
1402
+ local_part: null
1403
+ }
1404
+ }
1405
+ ```
1349
1406
 
1350
- ### Multiple Validation
1407
+ ### Multiple validation
1351
1408
  https://documentation.mailgun.com/en/latest/api-email-validation.html#email-validation
1352
- #### create
1353
- `mg.validate.multipleValidation.create('name_of_the_list', { file })`
1409
+ - #### create
1410
+ `mg.validate.multipleValidation.create('name_of_the_list', { file })`
1354
1411
 
1355
- ```js
1356
- const fsPromises = require('fs').promises;
1357
- const filepath = path.resolve(__dirname, '../path_to_your_file_with_emails_list.csv');
1412
+ ```js
1413
+ const fsPromises = require('fs').promises;
1414
+ const filepath = path.resolve(__dirname, '../path_to_your_file_with_emails_list.csv');
1358
1415
 
1359
- ...
1416
+ ...
1360
1417
 
1361
- (async () => {
1362
- try {
1363
- const file = {
1364
- filename: 'test.csv',
1365
- data: await fsPromises.readFile(filepath)
1366
- };
1418
+ (async () => {
1419
+ try {
1420
+ const file = {
1421
+ filename: 'test.csv',
1422
+ data: await fsPromises.readFile(filepath)
1423
+ };
1424
+
1425
+ const validateBulkResult = await mg.validate.multipleValidation.create('name_of_the_list', { file });
1426
+ console.log('validateBulkResult', validateBulkResult);
1427
+ } catch (error) {
1428
+ console.error(error);
1429
+ }
1430
+ })();
1431
+ ```
1367
1432
 
1368
- const validateBulkResult = await mg.validate.multipleValidation.create('name_of_the_list', { file });
1369
- console.log('validateBulkResult', validateBulkResult);
1370
- } catch (error) {
1371
- console.error(error);
1433
+ Response shape:
1434
+ ```JSON
1435
+ {
1436
+ "id": "name_of_the_list",
1437
+ "message": "The validation job was submitted."
1372
1438
  }
1373
- })();
1374
- ```
1375
-
1376
- Response shape:
1377
- ```JSON
1378
- {
1379
- "id": "name_of_the_list",
1380
- "message": "The validation job was submitted."
1381
- }
1382
- ```
1439
+ ```
1383
1440
 
1384
- #### list
1441
+ - #### list
1385
1442
 
1386
- `mg.validate.multipleValidation.list()`
1443
+ `mg.validate.multipleValidation.list()`
1387
1444
 
1388
- ```js
1389
- mg.validate.multipleValidation.list()
1390
- .then(data => console.log(data)) // logs response body
1391
- .catch(err => console.error(err)); // logs any error
1392
- ```
1445
+ ```js
1446
+ mg.validate.multipleValidation.list()
1447
+ .then(data => console.log(data)) // logs response body
1448
+ .catch(err => console.error(err)); // logs any error
1449
+ ```
1393
1450
 
1394
- Response shape:
1395
- ```JSON
1396
- {
1397
- "jobs": [
1398
- {
1399
- "created_at": 1643965937,
1400
- "download_url": {
1401
- "csv": "csv-url",
1402
- "json": "json-url"
1403
- },
1404
- "id": "name_of_the_list",
1405
- "quantity": 40,
1406
- "records_processed": 40,
1407
- "status": "uploaded",
1408
- "summary": {
1409
- "result": {
1410
- "catch_all": 0,
1411
- "deliverable": 0,
1412
- "do_not_send": 0,
1413
- "undeliverable": 0,
1414
- "unknown": 40
1451
+ Response shape:
1452
+ ```JSON
1453
+ {
1454
+ "jobs": [
1455
+ {
1456
+ "created_at": 1643965937,
1457
+ "download_url": {
1458
+ "csv": "csv-url",
1459
+ "json": "json-url"
1415
1460
  },
1416
- "risk": { "high": 0, "low": 0, "medium": 0, "unknown": 40 }
1461
+ "id": "name_of_the_list",
1462
+ "quantity": 40,
1463
+ "records_processed": 40,
1464
+ "status": "uploaded",
1465
+ "summary": {
1466
+ "result": {
1467
+ "catch_all": 0,
1468
+ "deliverable": 0,
1469
+ "do_not_send": 0,
1470
+ "undeliverable": 0,
1471
+ "unknown": 40
1472
+ },
1473
+ "risk": { "high": 0, "low": 0, "medium": 0, "unknown": 40 }
1474
+ }
1417
1475
  }
1418
- }
1419
- ],
1420
- "paging": {
1421
- "first": "https://api.mailgun.net/v4/address/validate/bulk?limit=100&page=first&pivot=",
1422
- "last": "https://api.mailgun.net/v4/address/validate/bulk?limit=100&page=last&pivot=",
1423
- "next": "https://api.mailgun.net/v4/address/validate/bulk?limit=100&page=next&pivot=b4808b5b-1111-2222-3333-6cd0b63f41ea",
1424
- "prev": "https://api.mailgun.net/v4/address/validate/bulk?limit=100&page=prev&pivot="
1425
- },
1426
- "total": 1
1427
- }
1428
- ```
1476
+ ],
1477
+ "paging": {
1478
+ "first": "https://api.mailgun.net/v4/address/validate/bulk?limit=100&page=first&pivot=",
1479
+ "last": "https://api.mailgun.net/v4/address/validate/bulk?limit=100&page=last&pivot=",
1480
+ "next": "https://api.mailgun.net/v4/address/validate/bulk?limit=100&page=next&pivot=b4808b5b-1111-2222-3333-6cd0b63f41ea",
1481
+ "prev": "https://api.mailgun.net/v4/address/validate/bulk?limit=100&page=prev&pivot="
1482
+ },
1483
+ "total": 1
1484
+ }
1485
+ ```
1429
1486
 
1430
- #### get
1487
+ - #### get
1431
1488
 
1432
- `mg.validate.multipleValidation.get('name_of_the_list')`
1489
+ `mg.validate.multipleValidation.get('name_of_the_list')`
1433
1490
 
1434
- ```js
1435
- mg.validate.multipleValidation.get('name_of_the_list')
1436
- .then(data => console.log(data)) // logs response body
1437
- .catch(err => console.error(err)); // logs any error
1438
- ```
1491
+ ```js
1492
+ mg.validate.multipleValidation.get('name_of_the_list')
1493
+ .then(data => console.log(data)) // logs response body
1494
+ .catch(err => console.error(err)); // logs any error
1495
+ ```
1439
1496
 
1440
- Response shape:
1441
- ```JSON
1442
- {
1443
- "created_at": 1643965937,
1444
- "download_url": {
1445
- "csv": "csv-url",
1446
- "json": "json-url"
1447
- },
1448
- "id": "name_of_the_list",
1449
- "quantity": 40,
1450
- "records_processed": 40,
1451
- "responseStatusCode": 200,
1452
- "status": "uploaded",
1453
- "summary": {
1454
- "result": {
1455
- "catch_all": 0,
1456
- "deliverable": 0,
1457
- "do_not_send": 0,
1458
- "undeliverable": 0,
1459
- "unknown": 40
1497
+ Response shape:
1498
+ ```JSON
1499
+ {
1500
+ "created_at": 1643965937,
1501
+ "download_url": {
1502
+ "csv": "csv-url",
1503
+ "json": "json-url"
1460
1504
  },
1461
- "risk": { "high": 0, "low": 0, "medium": 0, "unknown": 40 }
1505
+ "id": "name_of_the_list",
1506
+ "quantity": 40,
1507
+ "records_processed": 40,
1508
+ "responseStatusCode": 200,
1509
+ "status": "uploaded",
1510
+ "summary": {
1511
+ "result": {
1512
+ "catch_all": 0,
1513
+ "deliverable": 0,
1514
+ "do_not_send": 0,
1515
+ "undeliverable": 0,
1516
+ "unknown": 40
1517
+ },
1518
+ "risk": { "high": 0, "low": 0, "medium": 0, "unknown": 40 }
1519
+ }
1462
1520
  }
1463
- }
1464
- ```
1521
+ ```
1465
1522
 
1466
- #### destroy
1523
+ - #### destroy
1467
1524
 
1468
- `mg.validate.multipleValidation.destroy('name_of_the_list');`
1525
+ `mg.validate.multipleValidation.destroy('name_of_the_list');`
1469
1526
 
1470
- cancels bulk validation job
1471
- ```js
1472
- mg.validate.multipleValidation.destroy('name_of_the_list');
1473
- .then(data => console.log(data)) // logs response body
1474
- .catch(err => console.error(err)); // logs any error
1475
- ```
1527
+ cancels bulk validation job
1528
+ ```JS
1529
+ mg.validate.multipleValidation.destroy('name_of_the_list');
1530
+ .then(data => console.log(data)) // logs response body
1531
+ .catch(err => console.error(err)); // logs any error
1532
+ ```
1476
1533
 
1477
- Response shape:
1478
- ```JSON
1479
- {
1480
- "body": "Validation job canceled.",
1481
- "status": 200
1482
- }
1483
- ```
1534
+ Response shape:
1535
+ ```JS
1536
+ {
1537
+ body: "Validation job canceled.",
1538
+ status: 200
1539
+ }
1540
+ ```
1484
1541
 
1485
- ### lists
1542
+ ### Mailing lists
1486
1543
 
1487
- A client to manage mailing lists.
1544
+ A client to manage mailing lists.
1488
1545
 
1489
- #### list
1546
+ - #### list
1490
1547
 
1491
- `mg.lists.list()`
1548
+ `mg.lists.list()`
1492
1549
 
1493
- Example:
1550
+ Example:
1494
1551
 
1495
- ```js
1496
- mg.lists.list()
1497
- .then(data => console.log(data)) // logs response body
1498
- .catch(err => console.error(err)); // logs any error
1499
- ```
1552
+ ```js
1553
+ mg.lists.list()
1554
+ .then(data => console.log(data)) // logs response body
1555
+ .catch(err => console.error(err)); // logs any error
1556
+ ```
1500
1557
 
1501
- Promise Returns: response body
1558
+ Promise returns: response body
1502
1559
 
1503
- ```
1504
- [
1560
+ ```JS
1561
+ [
1562
+ {
1563
+ access_level: 'readonly',
1564
+ address: 'noreply@sample.com',
1565
+ created_at: 'Wed, 27 Oct 2021 21:59:21 -0000',
1566
+ description: '',
1567
+ members_count: 0,
1568
+ name: '',
1569
+ reply_preference: 'list'
1570
+ }
1571
+ ]
1572
+ ```
1573
+
1574
+ - #### get
1575
+
1576
+ `mg.lists.get(mailListAddress)`
1577
+
1578
+ Example:
1579
+
1580
+ ```JS
1581
+ mg.lists.get('noreply@sample.com')
1582
+ .then(data => console.log(data)) // logs response body
1583
+ .catch(err => console.error(err)); // logs any error
1584
+ ```
1585
+
1586
+ Promise returns:
1587
+
1588
+ ```JS
1505
1589
  {
1506
1590
  access_level: 'readonly',
1507
1591
  address: 'noreply@sample.com',
1508
- created_at: 'Wed, 27 Oct 2021 21:59:21 -0000',
1592
+ created_at: 'Thu, 28 Oct 2021 00:16:56 -0000',
1509
1593
  description: '',
1510
1594
  members_count: 0,
1511
1595
  name: '',
1512
1596
  reply_preference: 'list'
1513
1597
  }
1514
- ]
1515
- ```
1516
-
1517
- #### get
1518
-
1519
- `mg.lists.get(mailListAddress)`
1520
-
1521
- Example:
1598
+ ```
1522
1599
 
1523
- ```js
1524
- mg.lists.get('noreply@sample.com')
1525
- .then(data => console.log(data)) // logs response body
1526
- .catch(err => console.error(err)); // logs any error
1527
- ```
1600
+ - #### create
1528
1601
 
1529
- Promise Returns: response body
1602
+ `mg.lists.create(data)`
1530
1603
 
1531
- ```
1532
- {
1533
- access_level: 'readonly',
1534
- address: 'noreply@sample.com',
1535
- created_at: 'Thu, 28 Oct 2021 00:16:56 -0000',
1536
- description: '',
1537
- members_count: 0,
1538
- name: '',
1539
- reply_preference: 'list'
1540
- }
1541
- ```
1542
-
1543
- #### create
1604
+ Example:
1544
1605
 
1545
- `mg.lists.create(data)`
1606
+ ```js
1607
+ mg.lists.create({
1608
+ address: 'reply@sample.com',
1609
+ name: 'Reply Address', // optional, modifiable on website
1610
+ description: 'Mailing lists for repliable address', // optional, modifiable on website
1611
+ access_level: 'readonly', // optional, modifiable on website
1612
+ reply_preference: 'list', // optional, modifiable on website
1613
+ })
1614
+ .then(data => console.log(data)) // logs response body
1615
+ .catch(err => console.error(err)); // logs any error
1616
+ ```
1546
1617
 
1547
- Example:
1618
+ Promise returns:
1548
1619
 
1549
- ```js
1550
- mg.lists.create({
1620
+ ```JS
1621
+ {
1622
+ access_level: 'readonly',
1551
1623
  address: 'reply@sample.com',
1552
- name: 'Reply Address', // optional, modifiable on website
1553
- description: 'Mailing lists for repliable address', // optional, modifiable on website
1554
- access_level: 'readonly', // optional, modifiable on website
1555
- reply_preference: 'list', // optional, modifiable on website
1556
- })
1557
- .then(data => console.log(data)) // logs response body
1558
- .catch(err => console.error(err)); // logs any error
1559
- ```
1624
+ created_at: 'Thu, 28 Oct 2021 03:12:17 -0000',
1625
+ description: 'Mailing lists for repliable address',
1626
+ members_count: 0,
1627
+ name: 'Reply Address',
1628
+ reply_preference: 'list'
1629
+ }
1630
+ ```
1560
1631
 
1561
- Promise Returns: response body
1632
+ - #### update
1562
1633
 
1563
- ```
1564
- {
1565
- access_level: 'readonly',
1566
- address: 'reply@sample.com',
1567
- created_at: 'Thu, 28 Oct 2021 03:12:17 -0000',
1568
- description: 'Mailing lists for repliable address',
1569
- members_count: 0,
1570
- name: 'Reply Address',
1571
- reply_preference: 'list'
1572
- }
1573
- ```
1634
+ `mg.lists.update(mailListAddress)`
1574
1635
 
1575
- #### update
1636
+ Example:
1576
1637
 
1577
- `mg.lists.update(mailListAddress)`
1638
+ ```js
1639
+ mg.lists.update('reply@sample.com', {
1640
+ address: 'foo@sample.com',
1641
+ name: 'Foo', // optional, modifiable on website
1642
+ description: 'Foo bar bat', // optional, modifiable on website
1643
+ access_level: 'members', // optional, modifiable on website
1644
+ reply_preference: 'sender', // optional, modifiable on website
1645
+ })
1646
+ .then(data => console.log(data)) // logs response body
1647
+ .catch(err => console.error(err)); // logs any error
1648
+ ```
1578
1649
 
1579
- Example:
1650
+ Promise returns:
1580
1651
 
1581
- ```js
1582
- mg.lists.update('reply@sample.com', {
1652
+ ```JS
1653
+ {
1654
+ access_level: 'members',
1583
1655
  address: 'foo@sample.com',
1584
- name: 'Foo', // optional, modifiable on website
1585
- description: 'Foo bar bat', // optional, modifiable on website
1586
- access_level: 'members', // optional, modifiable on website
1587
- reply_preference: 'sender', // optional, modifiable on website
1588
- })
1589
- .then(data => console.log(data)) // logs response body
1590
- .catch(err => console.error(err)); // logs any error
1591
- ```
1656
+ created_at: 'Thu, 28 Oct 2021 03:21:15 -0000',
1657
+ description: 'Foo bar bat',
1658
+ members_count: 0,
1659
+ name: 'Foo',
1660
+ reply_preference: 'sender'
1661
+ }
1662
+ ```
1592
1663
 
1593
- Promise Returns: response body
1664
+ - #### destroy
1594
1665
 
1595
- ```
1596
- {
1597
- access_level: 'members',
1598
- address: 'foo@sample.com',
1599
- created_at: 'Thu, 28 Oct 2021 03:21:15 -0000',
1600
- description: 'Foo bar bat',
1601
- members_count: 0,
1602
- name: 'Foo',
1603
- reply_preference: 'sender'
1604
- }
1605
- ```
1666
+ `mg.lists.destroy(mailListAddress)`
1606
1667
 
1607
- #### destroy
1668
+ Example:
1608
1669
 
1609
- `mg.lists.destroy(mailListAddress)`
1670
+ ```js
1671
+ mg.lists.destroy('foo@sample.com')
1672
+ .then(data => console.log(data)) // logs response body
1673
+ .catch(err => console.error(err)); // logs any error
1674
+ ```
1610
1675
 
1611
- Example:
1676
+ Promise returns: response body
1612
1677
 
1613
- ```js
1614
- mg.lists.destroy('foo@sample.com')
1615
- .then(data => console.log(data)) // logs response body
1616
- .catch(err => console.error(err)); // logs any error
1617
- ```
1678
+ ```JS
1679
+ {
1680
+ address: 'foo@sample.com',
1681
+ message: 'Mailing list has been removed'
1682
+ }
1683
+ ```
1618
1684
 
1619
- Promise Returns: response body
1685
+ ### Mailing list members
1686
+ A client to manage members within a specific mailing list.
1620
1687
 
1621
- ```
1622
- {
1623
- address: 'foo@sample.com',
1624
- message: 'Mailing list has been removed'
1625
- }
1626
- ```
1688
+ - #### listMembers
1627
1689
 
1628
- ### mailListMembers
1690
+ `mg.lists.members.listMembers(mailListAddress)`
1629
1691
 
1630
- A client to manage members within a specific mailing list.
1692
+ Example:
1631
1693
 
1632
- #### listMembers
1694
+ ```js
1695
+ mg.lists.members.listMembers('reply@sample.com')
1696
+ .then(data => console.log(data)) // logs response body
1697
+ .catch(err => console.error(err)); // logs any error
1698
+ ```
1699
+
1700
+ Promise returns:
1701
+
1702
+ ```JS
1703
+ [
1704
+ {
1705
+ address: 'foo@bar.com',
1706
+ name: 'Jane Doe',
1707
+ subscribed: true,
1708
+ vars: { age: 50 }
1709
+ }
1710
+ ]
1711
+ ```
1633
1712
 
1634
- `mg.lists.members.listMembers(mailListAddress)`
1713
+ - #### getMember
1714
+ `mg.lists.members.getMember(mailListAddress, mailListMemberAddress)`
1635
1715
 
1636
- Example:
1716
+ Example:
1637
1717
 
1638
- ```js
1639
- mg.lists.members.listMembers('reply@sample.com')
1640
- .then(data => console.log(data)) // logs response body
1641
- .catch(err => console.error(err)); // logs any error
1642
- ```
1718
+ ```JS
1719
+ mg.lists.members.getMember('reply@sample.com', 'foo@bar.com')
1720
+ .then(data => console.log(data)) // logs response body
1721
+ .catch(err => console.error(err)); // logs any error
1722
+ ```
1643
1723
 
1644
- Promise Returns: response body
1724
+ Promise returns:
1645
1725
 
1646
- ```
1647
- [
1726
+ ```JS
1648
1727
  {
1649
1728
  address: 'foo@bar.com',
1650
1729
  name: 'Jane Doe',
1651
1730
  subscribed: true,
1652
1731
  vars: { age: 50 }
1653
1732
  }
1654
- ]
1655
- ```
1656
-
1657
- #### getMember
1658
-
1659
- `mg.lists.members.getMember(mailListAddress, mailListMemberAddress)`
1660
-
1661
- Example:
1662
-
1663
- ```js
1664
- mg.lists.members.getMember('reply@sample.com', 'foo@bar.com')
1665
- .then(data => console.log(data)) // logs response body
1666
- .catch(err => console.error(err)); // logs any error
1667
- ```
1733
+ ```
1668
1734
 
1669
- Promise Returns: response body
1735
+ - #### createMember
1736
+ `mg.lists.members.createMember(mailListAddress, data)`
1670
1737
 
1671
- ```
1672
- {
1673
- address: 'foo@bar.com',
1674
- name: 'Jane Doe',
1675
- subscribed: true,
1676
- vars: { age: 50 }
1677
- }
1678
- ```
1738
+ Example:
1679
1739
 
1680
- #### createMember
1681
-
1682
- `mg.lists.members.createMember(mailListAddress, data)`
1740
+ ```JS
1741
+ mg.lists.members.createMember('reply@sample.com', {
1742
+ address: 'bat@bar.com',
1743
+ name: 'John Smith', // optional, modifiable on website
1744
+ vars: {hobby: "chess"}, // optional, modifiable on website
1745
+ subscribed: 'no', // optional, modifiable on website
1746
+ upsert: 'yes', // optional, choose yes to insert if not exist, or update it exist
1747
+ })
1748
+ .then(data => console.log(data)) // logs response body
1749
+ .catch(err => console.error(err)); // logs any error
1750
+ ```
1683
1751
 
1684
- Example:
1752
+ Promise returns: response body
1685
1753
 
1686
- ```js
1687
- mg.lists.members.createMember('reply@sample.com', {
1754
+ ```JS
1755
+ {
1688
1756
  address: 'bat@bar.com',
1689
- name: 'John Smith', // optional, modifiable on website
1690
- vars: {hobby: "chess"}, // optional, modifiable on website
1691
- subscribed: 'no', // optional, modifiable on website
1692
- upsert: 'yes', // optional, choose yes to insert if not exist, or update it exist
1693
- })
1694
- .then(data => console.log(data)) // logs response body
1695
- .catch(err => console.error(err)); // logs any error
1696
- ```
1697
-
1698
- Promise Returns: response body
1757
+ name: 'John Smith',
1758
+ subscribed: false,
1759
+ vars: { hobby: 'chess' }
1760
+ }
1761
+ ```
1699
1762
 
1700
- ```
1701
- {
1702
- address: 'bat@bar.com',
1703
- name: 'John Smith',
1704
- subscribed: false,
1705
- vars: { hobby: 'chess' }
1706
- }
1707
- ```
1763
+ - #### createMembers
1764
+ `mg.lists.members.createMembers(mailListAddress, data)`
1708
1765
 
1709
- #### createMembers
1766
+ Example:
1710
1767
 
1711
- `mg.lists.members.createMembers(mailListAddress, data)`
1768
+ ```JS
1769
+ mg.lists.members.createMembers('reply@sample.com', {
1770
+ members: [
1771
+ {
1772
+ address: "bot1@foobar.com",
1773
+ name: "Bot1 Superbot",
1774
+ vars: {location: "loc1"},
1775
+ subscribed: true,
1776
+ },
1777
+ {
1778
+ address: "bot2@foobar.com",
1779
+ name: "Bot2 Superbot",
1780
+ vars: {location: "loc2"},
1781
+ subscribed: false,
1782
+ },
1783
+ ],
1784
+ upsert: "yes",
1785
+ })
1786
+ .then(data => console.log(data)) // logs response body
1787
+ .catch(err => console.error(err)); // logs any error
1788
+ ```
1712
1789
 
1713
- Example:
1790
+ Promise returns:
1714
1791
 
1715
- ```js
1716
- mg.lists.members.createMembers('reply@sample.com', {
1717
- members: [
1718
- {
1719
- address: "bot1@foobar.com",
1720
- name: "Bot1 Superbot",
1721
- vars: {location: "loc1"},
1722
- subscribed: true,
1723
- },
1724
- {
1725
- address: "bot2@foobar.com",
1726
- name: "Bot2 Superbot",
1727
- vars: {location: "loc2"},
1728
- subscribed: false,
1729
- },
1730
- ],
1731
- upsert: "yes",
1732
- })
1733
- .then(data => console.log(data)) // logs response body
1734
- .catch(err => console.error(err)); // logs any error
1735
- ```
1792
+ ```JS
1793
+ {
1794
+ list: {
1795
+ access_level: 'readonly',
1796
+ address: 'reply@sample.com',
1797
+ created_at: 'Thu, 28 Oct 2021 03:21:15 -0000',
1798
+ description: 'For reply purpose',
1799
+ members_count: 2,
1800
+ name: 'Reply',
1801
+ reply_preference: 'list'
1802
+ },
1803
+ message: 'Mailing list has been updated',
1804
+ 'task-id': '575b943c37a211ec8a520242ac11000a'
1805
+ }
1806
+ ```
1736
1807
 
1737
- Promise Returns: response body
1808
+ - #### updateMember
1738
1809
 
1739
- ```
1740
- {
1741
- list: {
1742
- access_level: 'readonly',
1743
- address: 'reply@sample.com',
1744
- created_at: 'Thu, 28 Oct 2021 03:21:15 -0000',
1745
- description: 'For reply purpose',
1746
- members_count: 2,
1747
- name: 'Reply',
1748
- reply_preference: 'list'
1749
- },
1750
- message: 'Mailing list has been updated',
1751
- 'task-id': '575b943c37a211ec8a520242ac11000a'
1752
- }
1753
- ```
1810
+ `mg.lists.members.updateMember(mailListAddress, mailListMemberAddress, data)`
1754
1811
 
1755
- #### updateMember
1812
+ Example:
1756
1813
 
1757
- `mg.lists.members.updateMember(mailListAddress, mailListMemberAddress, data)`
1814
+ ```JS
1815
+ mg.lists.members.updateMember('reply@sample.com', 'bot1@foobar.com', {
1816
+ address: 'bot0@barfoo.com',
1817
+ name: 'Bot0 Normalbot', // optional, modifiable on website
1818
+ vars: {location: "space"},
1819
+ subscribed: false,
1820
+ })
1821
+ .then(data => console.log(data)) // logs response body
1822
+ .catch(err => console.error(err)); // logs any error
1823
+ ```
1758
1824
 
1759
- Example:
1825
+ Promise returns: response body
1760
1826
 
1761
- ```js
1762
- mg.lists.members.updateMember('reply@sample.com', 'bot1@foobar.com', {
1827
+ ```JS
1828
+ {
1763
1829
  address: 'bot0@barfoo.com',
1764
- name: 'Bot0 Normalbot', // optional, modifiable on website
1765
- vars: {location: "space"},
1830
+ name: 'Bot0 Normalbot',
1766
1831
  subscribed: false,
1767
- })
1768
- .then(data => console.log(data)) // logs response body
1769
- .catch(err => console.error(err)); // logs any error
1770
- ```
1771
-
1772
- Promise Returns: response body
1773
-
1774
- ```
1775
- {
1776
- address: 'bot0@barfoo.com',
1777
- name: 'Bot0 Normalbot',
1778
- subscribed: false,
1779
- vars: { location: 'space' }
1780
- }
1781
- ```
1832
+ vars: { location: 'space' }
1833
+ }
1834
+ ```
1782
1835
 
1783
- #### destroyMember
1836
+ - #### destroyMember
1784
1837
 
1785
- `mg.lists.members.destroyMember(mailListAddress, mailListMemberAddress)`
1838
+ `mg.lists.members.destroyMember(mailListAddress, mailListMemberAddress)`
1786
1839
 
1787
- Example:
1840
+ Example:
1788
1841
 
1789
- ```js
1790
- mg.lists.members.destroyMember('reply@sample.com', 'bot2@foobar.com')
1791
- .then(data => console.log(data)) // logs response body
1792
- .catch(err => console.error(err)); // logs any error
1793
- ```
1842
+ ```JS
1843
+ mg.lists.members.destroyMember('reply@sample.com', 'bot2@foobar.com')
1844
+ .then(data => console.log(data)) // logs response body
1845
+ .catch(err => console.error(err)); // logs any error
1846
+ ```
1794
1847
 
1795
- Promise Returns: response body
1848
+ Promise returns: response body
1796
1849
 
1797
- ```js
1798
- {
1799
- member: { address: 'bot2@foobar.com' },
1800
- message: 'Mailing list member has been deleted'
1801
- }
1802
- ```
1850
+ ```JS
1851
+ {
1852
+ member: { address: 'bot2@foobar.com' },
1853
+ message: 'Mailing list member has been deleted'
1854
+ }
1855
+ ```
1803
1856
 
1804
1857
  ## Navigation thru lists
1805
1858
  Most of the methods that return items in a list support pagination.