mailgun.js 10.3.0 → 11.0.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
@@ -127,61 +127,82 @@ The following service methods are available to instantiated clients. The example
127
127
  - [get](#get)
128
128
  - [create](#create-1)
129
129
  - [update](#update)
130
+ - [verify](#verify)
130
131
  - [destroy](#destroy)
131
132
  - [getTracking](#gettracking)
132
133
  - [updateTracking](#updatetracking)
134
+ - [getConnection](#getconnection)
135
+ - [updateConnection](#updateconnection)
136
+ - [updateDKIMAuthority](#updatedkimauthority)
137
+ - [updateDKIMSelector](#updatedkimselector)
133
138
  - [getIps](#getips)
134
139
  - [assignIp](#assignip)
135
- - [events](#events)
140
+ - [domain templates](#domain-templates)
141
+ - [list](#list-1)
136
142
  - [get](#get-1)
143
+ - [create](#create-2)
144
+ - [update](#update-1)
145
+ - [destroy](#destroy-1)
146
+ - [destroyAll](#destroyall)
147
+ - [listVersions](#listversions)
148
+ - [getVersion](#getversion)
149
+ - [createVersion](#createversion)
150
+ - [updateVersion](#updateversion)
151
+ - [destroyVersion](#destroyversion)
152
+ - [events](#events)
153
+ - [get](#get-2)
137
154
  - [Example with Date and *Filter field*](#example-with-date-and-filter-field)
138
155
  - [stats](#stats)
156
+ - [Stats Options](#stats-options)
139
157
  - [getDomain](#getdomain)
140
158
  - [getAccount](#getaccount)
159
+ - [metrics](#metrics)
160
+ - [getAccount](#getaccount-1)
161
+ - [getAccountUsage](#getaccountusage)
141
162
  - [suppressions](#suppressions)
142
- - [list](#list-1)
163
+ - [list](#list-2)
143
164
  - [Bounces Example](#bounces-example)
144
165
  - [Unsubscribes Example](#unsubscribes-example)
145
166
  - [Complaints Example](#complaints-example)
146
- - [get](#get-2)
167
+ - [get](#get-3)
147
168
  - [Bounces Example](#bounces-example-1)
148
169
  - [Unsubscribes Example](#unsubscribes-example-1)
149
170
  - [Complaints Example](#complaints-example-1)
150
- - [create](#create-2)
171
+ - [create](#create-3)
151
172
  - [Bounces Example](#bounces-example-2)
152
173
  - [Unsubscribes Example](#unsubscribes-example-2)
153
174
  - [Unsubscribe from one tag](#unsubscribe-from-one-tag)
154
175
  - [Unsubscribe from particular tags](#unsubscribe-from-particular-tags)
155
176
  - [Complaints Example](#complaints-example-2)
156
- - [destroy](#destroy-1)
177
+ - [destroy](#destroy-2)
157
178
  - [Bounces Example](#bounces-example-3)
158
179
  - [Unsubscribes Example](#unsubscribes-example-3)
159
180
  - [Complaints Example](#complaints-example-3)
160
181
  - [webhooks](#webhooks)
161
- - [list](#list-2)
162
- - [get](#get-3)
163
- - [create](#create-3)
164
- - [update](#update-1)
165
- - [destroy](#destroy-2)
166
- - [routes](#routes)
167
182
  - [list](#list-3)
168
183
  - [get](#get-4)
169
184
  - [create](#create-4)
170
185
  - [update](#update-2)
171
186
  - [destroy](#destroy-3)
172
- - [validate](#validate)
173
- - [get](#get-5)
174
- - [multiple validation](#multiple-validation)
175
- - [create](#create-5)
187
+ - [routes](#routes)
176
188
  - [list](#list-4)
177
189
  - [get](#get-5)
190
+ - [create](#create-5)
191
+ - [update](#update-3)
178
192
  - [destroy](#destroy-4)
179
- - [mailing lists](#mailing-lists)
180
- - [list](#list-5)
193
+ - [validate](#validate)
181
194
  - [get](#get-6)
195
+ - [multiple validation](#multiple-validation)
182
196
  - [create](#create-6)
183
- - [update](#update-3)
197
+ - [list](#list-5)
198
+ - [get](#get-7)
184
199
  - [destroy](#destroy-5)
200
+ - [mailing lists](#mailing-lists)
201
+ - [list](#list-6)
202
+ - [get](#get-8)
203
+ - [create](#create-7)
204
+ - [update](#update-4)
205
+ - [destroy](#destroy-6)
185
206
  - [mailing list members](#mailing-list-members)
186
207
  - [listMembers](#listmember)
187
208
  - [getMember](#getmember)
@@ -190,38 +211,38 @@ The following service methods are available to instantiated clients. The example
190
211
  - [updateMember](#updatemember)
191
212
  - [destroyMember](#destroymember)
192
213
  - [subaccounts](#subaccounts)
193
- - [list](#list-6)
194
- - [get](#get-8)
195
- - [create](#create-7)
214
+ - [list](#list-7)
215
+ - [get](#get-9)
216
+ - [create](#create-8)
196
217
  - [enable](#enable)
197
218
  - [disable](#disable)
198
- - [Inbox Placements](#inbox-placements)
219
+ - [inbox placements](#inbox-placements)
199
220
  - [SeedsLists](#seedslists)
200
- - [list](#list-7)
201
- - [get](#get-9)
202
- - [create](#create-8)
203
- - [update](#update-4)
204
- - [destroy](#destroy-6)
221
+ - [list](#list-8)
222
+ - [get](#get-10)
223
+ - [create](#create-9)
224
+ - [update](#update-5)
225
+ - [destroy](#destroy-7)
205
226
  - [SeedsLists Attributes](#attributes)
206
- - [list](#list-8)
207
- - [get](#get-10)
208
- - [SeedsLists Filters](#filters)
209
227
  - [list](#list-9)
228
+ - [get](#get-11)
229
+ - [SeedsLists Filters](#filters)
230
+ - [list](#list-10)
210
231
  - [Providers](#providers)
211
- - [list](#list-10)
212
- - [Results](#results)
213
232
  - [list](#list-11)
214
- - [get](#get-11)
215
- - [destroy](#destroy-7)
233
+ - [Results](#results)
234
+ - [list](#list-12)
235
+ - [get](#get-12)
236
+ - [destroy](#destroy-8)
216
237
  - [getResultByShareId](#getresultbyshareid)
217
238
  - [Results Attributes](#attributes-1)
218
- - [list](#list-12)
219
- - [get](#get-12)
220
- - [Results Filters](#filters-1)
221
239
  - [list](#list-13)
222
- - [Sharing](#sharing)
223
240
  - [get](#get-13)
224
- - [update](#update-5)
241
+ - [Results Filters](#filters-1)
242
+ - [list](#list-14)
243
+ - [Sharing](#sharing)
244
+ - [get](#get-14)
245
+ - [update](#update-6)
225
246
  - [Run Test](#run-test)
226
247
  - [Navigation thru lists](#navigation-thru-lists)
227
248
  - [Browser Demo](#browser-demo)
@@ -517,10 +538,11 @@ The following service methods are available to instantiated clients. The example
517
538
  ```
518
539
 
519
540
  ### Domains
541
+ Domains API manages domains, domain keys and DNS verification.
520
542
 
521
543
  - #### list
522
-
523
- `mg.domains.list(query)` - [api docs](https://documentation.mailgun.com/en/latest/api-domains.html)
544
+ Get the list of domains. Can be filtered by state or authority. Sorting is optional. The list is paginated and limited to 1000 items per page.
545
+ `mg.domains.list(query)` - [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Domains/#tag/Domains/operation/GET-v4-domains)
524
546
 
525
547
  Example:
526
548
 
@@ -534,18 +556,23 @@ The following service methods are available to instantiated clients. The example
534
556
 
535
557
  ```JS
536
558
  [{
537
- created_at: 'Sun, 19 Oct 2014 18:49:36 GMT',
538
559
  name: 'testing.example.com',
539
- receiving_dns_records: null,
540
560
  require_tls: true,
541
- sending_dns_records: null,
542
561
  skip_verification: true,
543
- smtp_login: 'postmaster@testing.example.com',
544
- smtp_password: 'password',
545
- spam_action: 'disabled',
546
562
  state: 'unverified',
547
- type: 'custom',
548
563
  wildcard: true
564
+ spam_action: 'disabled',
565
+ created_at: 'Sun, 19 Oct 2014 18:49:36 GMT',
566
+ smtp_password: undefined,
567
+ smtp_login: 'postmaster@testing.example.com',
568
+ type: 'custom',
569
+ receiving_dns_records: null,
570
+ sending_dns_records: null,
571
+ id: '697d01d38712cf0322bb24d1',
572
+ is_disabled: false,
573
+ web_prefix: 'test',
574
+ web_scheme: 'https',
575
+ use_automatic_sender_security: true
549
576
  }]
550
577
  ```
551
578
 
@@ -555,159 +582,248 @@ The following service methods are available to instantiated clients. The example
555
582
  |:----------|:------------------------------------------------------|
556
583
  | limit | Maximum number of records to return. (100 by default) |
557
584
  | skip | Number of records to skip. (0 by default) |
585
+ | state | To only get domains with a specific state. Can be either active, unverified or disabled. |
586
+ | sort | Valid sort options are **name** which defaults to asc order, **name:asc**, or **name:desc**. If sorting is not specified domains are returned in reverse creation date order. |
587
+ | authority | To only get domains with a specific authority. If state is specified then only state filtering will be proceed |
588
+ | search | Search domains by the given partial or complete name. Does not support wildcards|
558
589
 
559
590
  - #### get
591
+ Fetches representation of a domain that includes details about the domain's state and settings.
560
592
 
561
- `mg.domains.get(domain)`
593
+ `mg.domains.get(domain, query)` - [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Domains/#tag/Domains/operation/GET-v4-domains--name-)
562
594
 
563
595
  Example:
564
596
 
565
597
  ```JS
566
- mg.domains.get('testing.example.com')
567
- .then(domains => console.log(domains)) // logs domain object
598
+ mg.domains.get('testing.example.com', {
599
+ extended: true
600
+ })
601
+ .then(domain => console.log(domain)) // logs domain object
568
602
  .catch(err => console.error(err)); // logs any error
569
603
  ```
570
604
 
605
+ Query object may have next properties:
606
+
607
+ | Property | Description |
608
+ |:----------|:------------------------------------------------------|
609
+ | extended | Default to false. If set to true, domain payload will include dkim_host, mailfrom_host and pod |
610
+ | with_dns | Default to true, domain payload will include sending and receiving dns records payload|
611
+
571
612
  Promise returns: Domain instance
572
613
 
573
614
  ```JS
574
615
  {
575
- created_at: 'Sun, 19 Oct 2014 18:49:36 GMT',
576
616
  name: 'testing.example.com',
577
- receiving_dns_records: [{
578
- "name": "testing.example.com",
579
- "record_type": "TXT",
580
- "valid": "unknown",
581
- "value": "v=spf1 include:mailgun.org ~all"
582
- },
583
- {
584
- "name": "k1._domainkey.testing.example.com",
585
- "record_type": "TXT",
586
- "valid": "unknown",
587
- "value": "k=rsa; 123456"
588
- },
589
- {
590
- "name": "email.testing.example.com",
591
- "record_type": "CNAME",
592
- "valid": "unknown",
593
- "value": "mailgun.org"
594
- }],
595
617
  require_tls: true,
596
- sending_dns_records: [{
597
- "priority": "10",
598
- "record_type": "MX",
599
- "valid": "unknown",
600
- "value": "mxa.mailgun.org"
601
- },
602
- {
603
- "priority": "10",
604
- "record_type": "MX",
605
- "valid": "unknown",
606
- "value": "mxb.mailgun.org"
607
- }],
608
618
  skip_verification: true,
609
- smtp_login: 'postmaster@testing.example.com',
610
- smtp_password: 'password',
611
- spam_action: 'disabled',
612
619
  state: 'unverified',
613
- type: 'custom',
614
620
  wildcard: true,
615
- id: '64a4291ebbe4ec7e1d78bc80',
621
+ spam_action: 'disabled',
622
+ created_at: new Date('Sun, 19 Oct 2014 18:49:36 GMT'),
623
+ smtp_password: undefined,
624
+ smtp_login: 'postmaster@testing.example.com',
625
+ type: 'custom',
626
+ receiving_dns_records: [ // may be null if with_dns is set to false.
627
+ {
628
+ is_active: true,
629
+ cached: [],
630
+ priority: '10',
631
+ record_type: 'TXT',
632
+ valid: "unknown",
633
+ value: "dns_record_value"
634
+ },
635
+ ...
636
+ ],
637
+ sending_dns_records: [ // may be null if with_dns is set to false.
638
+ {
639
+ is_active: true,
640
+ cached: [],
641
+ name: 'dns_record_name',
642
+ record_type: 'CNAME',
643
+ valid: 'unknown',
644
+ value: 'dns_record_value'
645
+ },
646
+ ...
647
+ ],
648
+ id: '697d01d38712cf0322bb24d1',
616
649
  is_disabled: false,
617
650
  web_prefix: 'email',
618
- web_scheme: 'http'
651
+ web_scheme: 'http',
652
+ use_automatic_sender_security: true,
653
+ dkim_host: 'dkim_host_value', // absent if 'extended' was not set to true.
654
+ mailfrom_host: 'mailfrom_host_value', // absent if 'extended' was not set to true.
619
655
  }
620
656
  ```
621
657
 
622
658
  - #### create
659
+ Creates a domain for sending emails
623
660
 
624
- `mg.domains.create(data)`
661
+ `mg.domains.create(data)` [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Domains/#tag/Domains/operation/POST-v4-domains)
625
662
 
626
663
  Example:
627
664
 
628
665
  ```js
629
- mg.domains.create({name: 'foobar.example.com'})
630
- .then(msg => console.log(msg)) // logs response data
666
+ mg.domains.create({
667
+ name: 'foobar.example.com',
668
+ dkim_key_size: 1024,
669
+ dkim_selector: 's1',
670
+ encrypt_incoming_message: true,
671
+ force_dkim_authority: false,
672
+ force_root_dkim_host: false,
673
+ wildcard: true,
674
+ pool_id: 'pool_id',
675
+ ips: '',
676
+ spam_action: 'tag',
677
+ smtp_password: 'smtp_password_value',
678
+ use_automatic_sender_security: true,
679
+ web_prefix: 'test',
680
+ web_scheme: 'https',
681
+ })
682
+ .then(data => console.log(data)) // logs response data
631
683
  .catch(err => console.error(err)); // logs any error
632
684
  ```
633
685
 
634
686
  Create method accepts data object with next properties:
635
687
 
636
- | Parameter | Description |
637
- |--- |--- |
638
- | name | Name of the domain (ex. domain.com) |
639
- | smtp_password | Password for SMTP authentication |
640
- | spam_action | `disabled`, `block`, or `tag`<br>If `disabled`, no spam filtering will occur for inbound messages.<br>If `block`, inbound spam messages will not be delivered.<br>If `tag`, inbound messages will be tagged with a spam header. [Spam Filter](https://documentation.mailgun.com/en/latest/user_manual.html#um-spam-filter)<br>The default is `disabled`. |
641
- | wildcard | Can be string `'true'` or `'false'` or `boolean`<br>Determines whether the domain will accept email for sub-domains when sending messages.<br>The default is `false`. |
642
- | force_dkim_authority | Can be string `'true'` or `'false'` or `boolean`<br>If set to `true`, the domain will be the DKIM authority for itself even if the root domain is registered on the same mailgun account<br>If set to `false`, the domain will have the same DKIM authority as the root domain registered on the same mailgun account<br>The default is `false`. |
643
- | dkim_key_size | **1024** or **2048**<br>Set the length of your domain’s generated DKIM key<br>The default is **1024** |
644
- | ips | An optional, comma-separated list of IP addresses to be assigned to this domain. If not specified, all dedicated IP addresses on the account will be assigned. If the request cannot be fulfilled (e.g. a requested IP is not assigned to the account, etc), a 400 will be returned. |
645
- | pool_id | The id of the IP Pool that you wish to assign to the domain. The pool must contain at least 1 IP. (Note: IP Pools are only available on certain plans; see http://mailgun.com/pricing) |
646
- | web_scheme | String with `http` or `https`<br>Set your **open**, **click** and **unsubscribe** URLs to use `http` or `https`<br>The default is `http` |
688
+ | Parameter | Description |
689
+ |--- |--- |
690
+ | name (required) | Name of the domain (ex. domain.com) |
691
+ | dkim_host_name | Set the DKIM host name for the domain that is being created. Note, the value must be a valid domain name, and can be the domain name being created, a subdomain of the domain being created, or the root domain. This parameter cannot be used in conjunction with `force_dkim_authority` or `force_root_dkim_host`. |
692
+ | dkim_key_size | **1024** or **2048**<br>Set the length of your domain’s generated DKIM key<br>The default is **1024** |
693
+ | dkim_selector | Explicitly set the value of the DKIM selector for the domain being created. If the domain key does not already exist, one will be created. The selector must be a valid atom per RFC2822. e.g valid value foobar, invalid value foo.bar https://datatracker.ietf.org/doc/html/rfc2822#section-3.2.4|
694
+ | encrypt_incoming_message | Enable encrypting incoming messages for the given domain. This cannot be altered via API after being set for security purposes. Reach out to Support to disable if necessary. Default to false|
695
+ | force_dkim_authority| If set to true, the domain will be the DKIM authority for itself even if the root domain is registered on the same mailgun account. If set to false, the domain will have the same DKIM authority as the root domain registered on the same mailgun account. Default to false. |
696
+ | force_root_dkim_host | If set to true, the root domain will be the DKIM Host for the domain being created even if the root domain itself is not registered with Mailgun. The domain being created will still need to pass domain verification with valid spf records for the domain and valid DKIM record for the root domain. This does not effect the smtp mail-from host for the domain being created. The mail-from host will remain the domain name being created, not the root domain.|
697
+ | wildcard | Determines whether the domain will accept email for sub-domains when sending messages. Default to false. |
698
+ | pool_id | Requested IP Pool to be assigned to the domain at creation. |
699
+ | ips | An optional, comma-separated list of IP addresses to be assigned to this domain. If not specified, all dedicated IP addresses on the account will be assigned. If the request cannot be fulfilled (e.g. a requested IP is not assigned to the account, etc), a 400 will be returned. |
700
+ | spam_action | `disabled`, `block`, or `tag`<br>If `disabled`, no spam filtering will occur for inbound messages.<br>If `block`, inbound spam messages will not be delivered.<br>If `tag`, inbound messages will be tagged with a spam header. [Spam Filter](https://documentation.mailgun.com/en/latest/user_manual.html#um-spam-filter)<br>The default is `disabled`. |
701
+ | smtp_password | Password for SMTP authentication |
702
+ | use_automatic_sender_security | Enable Automatic Sender Security. This requires setting DNS CNAME entries for DKIM keys instead of a TXT record. Defaults to false. |
703
+ | web_prefix | Sets your open, click and unsubscribe URLs domain name prefix. Links rewritten or added by Mailgun in your emails will look like ://./... Default to email |
704
+ | web_scheme |Sets your open, click and unsubscribe URLs to use http or https. Value either `http` or `https`. Defaults to http. In order for https to work, you must have a valid cert created for your domain. See Domain Tracking for TLS cert generation. |
647
705
 
648
706
  Promise returns:
649
707
 
650
708
  ```JS
651
- name: 'foobar.example.com',
652
- require_tls: false,
653
- skip_verification: false,
654
- state: 'unverified',
655
- wildcard: false,
656
- spam_action: 'disabled',
657
- created_at: 'Tue, 04 Jul 2023 14:09:18 GMT',
658
- smtp_password: undefined,
659
- smtp_login: 'postmaster@foobar.example.com',
660
- type: 'custom',
661
- receiving_dns_records: [{
662
- "name": "foobar.example.com",
663
- "record_type": "TXT",
664
- "valid": "unknown",
665
- "value": "v=spf1 include:mailgun.org ~all"
666
- },
667
- {
668
- "name": "k1._domainkey.foobar.example.com",
669
- "record_type": "TXT",
670
- "valid": "unknown",
671
- "value": "k=rsa; 123456"
672
- },
673
- {
674
- "name": "email.foobar.example.com",
675
- "record_type": "CNAME",
676
- "valid": "unknown",
677
- "value": "mailgun.org"
678
- }
679
- ],
680
- sending_dns_records: [{
681
- "priority": "10",
682
- "record_type": "MX",
683
- "valid": "unknown",
684
- "value": "mxa.mailgun.org"
685
- },
686
- {
687
- "priority": "10",
688
- "record_type": "MX",
689
- "valid": "unknown",
690
- "value": "mxb.mailgun.org"
691
- }],
692
- id: '64a4291ebbe4ec7e1d78bc80',
693
- is_disabled: false,
694
- web_prefix: 'email',
695
- web_scheme: 'http'
709
+ {
710
+ name: 'foobar.example.com',
711
+ require_tls: false,
712
+ skip_verification: false,
713
+ state: 'unverified',
714
+ wildcard: true,
715
+ spam_action: 'tag',
716
+ created_at: 2025-01-08T12:52:29.000Z,
717
+ smtp_password: undefined,
718
+ smtp_login: new Date('postmaster@foobar.example.com'),
719
+ type: 'custom',
720
+ receiving_dns_records: [
721
+ {
722
+ is_active: true,
723
+ cached: [],
724
+ priority: '10',
725
+ record_type: 'MX',
726
+ valid: 'unknown',
727
+ value: 'dns_record_value'
728
+ },
729
+ ...
730
+ ],
731
+ sending_dns_records: [
732
+ {
733
+ is_active: false,
734
+ cached: [],
735
+ name: 'sending_dns_record_name',
736
+ record_type: 'CNAME',
737
+ valid: 'unknown',
738
+ value: 'sending_dns_record_value'
739
+ },
740
+ ...
741
+ ],
742
+ id: '64a4291ebbe4ec7e1d78bc80',
743
+ is_disabled: false,
744
+ web_prefix: 'test',
745
+ web_scheme: 'https',
746
+ use_automatic_sender_security: true
747
+ }
748
+ ```
749
+
750
+ - #### verify
751
+ Verify the domains DNS records (includes A, CNAME, SPF, DKIM and MX records) to ensure the domain is ready and able to send
752
+
753
+ `mg.domains.verify(domainAddress)` [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Domains/#tag/Domains/operation/PUT-v4-domains--name--verify)
754
+
755
+ Example:
756
+
757
+ ```JS
758
+ mg.domains.destroy('foobar.example.com')
759
+ .then(data => console.log(data)) // logs response data
760
+ .catch(err => console.error(err)); // logs any error
761
+ ```
762
+
763
+ Promise returns:
764
+
765
+ ```JS
766
+ {
767
+ name: 'foobar.example.com',
768
+ require_tls: false,
769
+ skip_verification: false,
770
+ state: 'active',
771
+ wildcard: false,
772
+ spam_action: 'tag',
773
+ created_at: new Date('2017-10-05T14:55:20.000Z'),
774
+ smtp_password: undefined,
775
+ smtp_login: 'postmaster@foobar.example.com',
776
+ type: 'custom',
777
+ receiving_dns_records: [
778
+ {
779
+ is_active: true,
780
+ cached: [Array],
781
+ priority: '10',
782
+ record_type: 'MX',
783
+ valid: 'valid',
784
+ value: 'receiving_dns_record_value'
785
+ },
786
+ ...
787
+ ],
788
+ sending_dns_records: [
789
+ {
790
+ is_active: true,
791
+ cached: [],
792
+ name: 'foobar.example.com',
793
+ record_type: 'CNAME',
794
+ valid: 'unknown',
795
+ value: 'sending_dns_record_value'
796
+ },
797
+ ...
798
+ ],
799
+ id: '64a5880eere4eg7e1d85bc69',
800
+ is_disabled: false,
801
+ web_prefix: 'email',
802
+ web_scheme: 'https',
803
+ use_automatic_sender_security: true
804
+ }
696
805
  ```
697
806
 
807
+
698
808
  - #### update
809
+ Update domains configuration like smtp credentials, enable/disable automatic sender security, spam actions, wildcard, or tracking web scheme.
699
810
 
700
- `mg.domains.update(domain, options)`
811
+ `mg.domains.update(domain, options)` [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Domains/#tag/Domains/operation/PUT-v4-domains--name-)
701
812
 
702
813
  Example:
703
814
 
704
815
  ```js
705
816
  mg.domains.update('foobar.example.com',{
706
- wildcard: 'true',
817
+ mailfrom_host: 'mailfrom_host_value',
818
+ message_ttl: 20,
819
+ smtp_password: 'smtp_password_value'
820
+ spam_action: 'tag',
821
+ use_automatic_sender_security: true
707
822
  web_scheme: 'http',
708
- spam_action: 'disabled',
823
+ web_prefix: 'web_prefix_value'
824
+ wildcard: 'true',
709
825
  })
710
- .then(msg => console.log(msg)) // logs response data
826
+ .then(data => console.log(data)) // logs response data
711
827
  .catch(err => console.error(err)); // logs any error
712
828
  ```
713
829
 
@@ -715,8 +831,13 @@ The following service methods are available to instantiated clients. The example
715
831
 
716
832
  | Property | Description |
717
833
  |:--------------|:----------------------------------------------------------------------------------------------------------------------------------------------|
834
+ | mailfrom_host | The hostname to update to. Must be in lower case |
835
+ | message_ttl | Duration of the message retrieval TTL in seconds |
836
+ | smtp_password | Updates the domain's SMTP credentials with the given string |
718
837
  | spam_action | Can be string with value `disabled`, `block`, or `tag`. If *disabled*, no spam filtering will occur for inbound messages. If `block`, inbound spam messages will not be delivered. If `tag`, inbound messages will be tagged with a spam header. See [Spam Filter](https://documentation.mailgun.com/en/latest/user_manual.html#um-spam-filter).|
838
+ | use_automatic_sender_security | enable or disable Automatic Sender Security. If enabled, requires setting DNS CNAME entries for DKIM keys instead of a TXT record. Domain must be reverified after changing this field. Defaults to `false`|
719
839
  | web_scheme | Can be string with value `http` or `https`. Set your **open**, **click** and **unsubscribe** URLs to use `http` or `https`. The default is `http`|
840
+ | web_prefix | Web prefix to be used for tracking. Must be a valid atom. Nothing will be updated if omitted |
720
841
  | wildcard | Can be string `'true'` or `'false'` or `boolean`. Determines whether the domain will accept email for sub-domains. The default is `false`.|
721
842
 
722
843
  Promise returns:
@@ -729,7 +850,7 @@ The following service methods are available to instantiated clients. The example
729
850
  state: 'unverified',
730
851
  wildcard: true,
731
852
  spam_action: 'disabled',
732
- created_at: 'Tue, 04 Jul 2023 14:09:18 GMT',
853
+ created_at: new Date('2025-01-08T12:52:29.000Z'),
733
854
  smtp_password: undefined,
734
855
  smtp_login: 'postmaster@foobar.example.com',
735
856
  type: 'custom',
@@ -740,16 +861,9 @@ The following service methods are available to instantiated clients. The example
740
861
  priority: '10',
741
862
  record_type: 'MX',
742
863
  valid: 'unknown',
743
- value: 'mxa.mailgun.org'
864
+ value: 'receiving_dns_record_value'
744
865
  },
745
- {
746
- is_active: true,
747
- cached: [],
748
- priority: '10',
749
- record_type: 'MX',
750
- valid: 'unknown',
751
- value: 'mxb.mailgun.org'
752
- }
866
+ ...
753
867
  ],
754
868
  sending_dns_records: [
755
869
  {
@@ -758,214 +872,778 @@ The following service methods are available to instantiated clients. The example
758
872
  name: 'foobar.example.com',
759
873
  record_type: 'TXT',
760
874
  valid: 'unknown',
761
- value: 'v=spf1 include:mailgun.org ~all'
875
+ value: 'sending_dns_record_value'
762
876
  },
763
- {
764
- is_active: true,
765
- cached: [],
766
- name: 'email.foobar.example.com',
767
- record_type: 'CNAME',
768
- valid: 'unknown',
769
- value: 'mailgun.org'
770
- }
877
+ ...
771
878
  ],
772
879
  id: '64a5880eere4eg7e1d85bc69',
773
880
  is_disabled: false,
774
- web_prefix: 'email',
775
- web_scheme: 'http'
881
+ web_prefix: 'test',
882
+ web_scheme: 'https',
883
+ use_automatic_sender_security: true
776
884
  }
777
885
  ```
778
886
 
887
+
888
+
779
889
  - #### destroy
890
+ The domain must not be disabled or used as an authority for an other domain. Sandbox domain can't be deleted.
891
+ `mg.domains.destroy(domainAddress)` [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Domains/#tag/Domains/operation/DELETE-v3-domains--name-)
892
+
893
+ Example:
894
+
895
+ ```JS
896
+ mg.domains.destroy('foobar.example.com')
897
+ .then(data => console.log(data)) // logs response data
898
+ .catch(err => console.error(err)); // logs any error
899
+ ```
900
+
901
+ Promise returns message:
902
+
903
+ ```JS
904
+ {
905
+ message: "Domain will be deleted in the background"
906
+ }
907
+ ```
908
+
909
+
910
+ - #### getTracking
911
+ Mailgun offers tracking for clicks, unsubscribes, and opens, with optional HTTPS protocol support on tracking URLs. To enable HTTPS, Mailgun uses Let’s Encrypt with HTTP-01 challenges through your existing tracking CNAME record to issue a TLS certificate. This setup also includes support for HTTP Strict Transport Security (HSTS) for enhanced security.
912
+
913
+ `mg.domains.getTracking(domainAddress)` [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Domain-Tracking/#tag/Domain-Tracking)
914
+
915
+ Example:
916
+
917
+ ```JS
918
+ mg.domains.getTracking('foobar.example.com')
919
+ .then(msg => console.log(msg)) // logs response data
920
+ .catch(err => console.error(err)); // logs any error
921
+ ```
922
+
923
+ Promise returns:
924
+
925
+ ```JS
926
+ {
927
+ "click": {
928
+ "active": false
929
+ },
930
+ "open": {
931
+ "active": false
932
+ },
933
+ "unsubscribe": {
934
+ "active": false,
935
+ "html_footer": "\n<br>\n<p><a href=\"%unsubscribe_url%\">unsubscribe</a></p>\n",
936
+ "text_footer": "\n\nTo unsubscribe click: <%unsubscribe_url%>\n\n"
937
+ }
938
+ }
939
+ ```
940
+
941
+ - #### updateTracking
942
+ A common method to turn on/off the click, open, and unsubscribe tracking at the domain level.
943
+
944
+ `mg.domains.updateTracking(domain, trackingType, data)`
945
+
946
+ - Open Tracking Example:
947
+
948
+ [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Domain-Tracking/#tag/Domain-Tracking/operation/PUT-v3-domains--name--tracking-open)
949
+ ```js
950
+ mg.domains.updateTracking('foobar.example.com', 'open', {
951
+ active: true,
952
+ place_at_the_top: true,
953
+ })
954
+ .then(msg => console.log(msg)) // logs response data
955
+ .catch(err => console.error(err)); // logs any error
956
+ ```
957
+
958
+ Open tracking data object properties:
959
+
960
+ | Property | Description |
961
+ |:----------|:-------------------------------------------|
962
+ | active | Boolean, enables or disables open tracking |
963
+ | place_at_the_top| Setting this param to true will place the open tracking pixel at the top of the HTML body when inserted into the email mime. Omit this param to keep current setting. |
964
+
965
+ Promise returns:
966
+
967
+ ```JS
968
+ {
969
+ message: 'Tracking settings have been updated',
970
+ open: {
971
+ active: true,
972
+ place_at_the_top: true,
973
+ }
974
+ }
975
+ ```
976
+
977
+ - Click Tracking Example:
978
+
979
+ [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Domain-Tracking/#tag/Domain-Tracking/operation/PUT-v3-domains--name--tracking-click)
980
+ ```JS
981
+ mg.domains.updateTracking('foobar.example.com', 'click', {active: true})
982
+ .then(msg => console.log(msg)) // logs response data
983
+ .catch(err => console.error(err)); // logs any error
984
+ ```
985
+
986
+ Click tracking data object properties:
987
+
988
+ | Property | Description |
989
+ |:----------|:--------------------------------------------|
990
+ | active | Boolean, enables or disables click tracking |
991
+
992
+ Promise returns:
993
+
994
+ ```JS
995
+ {
996
+ message: 'Tracking settings have been updated',
997
+ click: {
998
+ active: true
999
+ }
1000
+ }
1001
+ ```
1002
+
1003
+ - Unsubscribe Tracking Example
1004
+
1005
+ [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Domain-Tracking/#tag/Domain-Tracking/operation/PUT-v3-domains--name--tracking-unsubscribe)
1006
+ ```js
1007
+ mg.domains.updateTracking('foobar.example.com', 'unsubscribe', {
1008
+ active: true,
1009
+ html_footer: "\n<br>\n<p><a href=\"%unsubscribe_url%\">unsubscribe</a></p>\n",
1010
+ text_footer: "\n\nTo unsubscribe click: <%unsubscribe_url%>\n\n"
1011
+ })
1012
+ .then(msg => console.log(msg)) // logs response data
1013
+ .catch(err => console.error(err)); // logs any error
1014
+ ```
1015
+
1016
+ Unsubscribe Tracking data object properties:
1017
+
1018
+ | Property | Description |
1019
+ |:------------|:--------------------------------------------------------------|
1020
+ | active | Boolean, enables or disables unsubscribe tracking |
1021
+ | html_footer | string appended to html emails for managing unsubscribe links |
1022
+ | text_footer | string appended to html emails for managing unsubscribe links |
1023
+
1024
+ Promise returns:
1025
+
1026
+ ```JS
1027
+ {
1028
+ message: 'Tracking settings have been updated',
1029
+ unsubscribe: {
1030
+ active: true,
1031
+ html_footer: '\n<br>\n<p><a href=\'%unsubscribe_url%\">unsubscribe</a></p>\n',
1032
+ text_footer: '\n\nTo unsubscribe click: <%unsubscribe_url%>\n\n'
1033
+ }
1034
+ }
1035
+ ```
1036
+
1037
+ - #### getConnection
1038
+ Returns domain's delivery connection settings.
1039
+
1040
+ `mg.domains.getConnection(domainAddress)` [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Domain-Connection/#tag/Domain-Connection/operation/GET-v3-domains--name--connection)
1041
+
1042
+ Example:
1043
+
1044
+ ```JS
1045
+ mg.domains.getConnection(domainAddress)
1046
+ .then(data => console.log(data)) // logs response data
1047
+ .catch(err => console.error(err)); // logs any error
1048
+ ```
1049
+
1050
+ Promise returns:
1051
+
1052
+ ```JS
1053
+ {
1054
+ require_tls: false,
1055
+ skip_verification: false
1056
+ }
1057
+ ```
1058
+
1059
+ - #### updateConnection
1060
+ Update a domain's TLS connection settings.
1061
+
1062
+ `mg.domains.updateConnection(domainAddress, data)` [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Domain-Connection/#tag/Domain-Connection/operation/PUT-v3-domains--name--connection)
1063
+
1064
+ Example:
1065
+
1066
+ ```JS
1067
+ mg.domains.updateConnection(domainAddress, {
1068
+ require_tls: true;
1069
+ skip_verification: false;
1070
+ })
1071
+ .then(data => console.log(data)) // logs response data
1072
+ .catch(err => console.error(err)); // logs any error
1073
+ ```
1074
+
1075
+ Promise returns:
1076
+
1077
+ ```JS
1078
+ {
1079
+ message: 'Domain connection settings have been updated, may take 10 minutes to fully propagate',
1080
+ require_tls: false,
1081
+ skip_verification: false
1082
+ }
1083
+ ```
1084
+
1085
+ - #### updateDKIMAuthority
1086
+ You can delegate the domain authority to an other domain. Domain's authority is set to itself by default.
1087
+
1088
+ `mg.domains.updateDKIMAuthority(domainAddress, data)` [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Domain-Keys/#tag/Domain-Keys/operation/PUT-v3-domains--name--dkim-authority)
1089
+
1090
+ Example:
1091
+
1092
+ ```JS
1093
+ mg.domains.updateDKIMAuthority(domainAddress, {
1094
+ self: true
1095
+ })
1096
+ .then(data => console.log(data)) // logs response data
1097
+ .catch(err => console.error(err)); // logs any error
1098
+ ```
1099
+
1100
+ Data object accepts next properties:
1101
+
1102
+ | Property | Description |
1103
+ |:--------------|:----------------------------------------------------------------------------------------------------------------------------------------------|
1104
+ | self | Change the DKIM authority for a domain. If set to true, the domain will be the DKIM authority for itself even if the root domain is registered on the same mailgun account If set to false, the domain will have the same DKIM authority as the root domain registered on the same mailgun account |
1105
+
1106
+ Promise returns:
1107
+
1108
+ ```JS
1109
+ {
1110
+ message: 'Domain DKIM authority has been changed',
1111
+ sending_dns_records: [
1112
+ {
1113
+ is_active: true,
1114
+ cached: [],
1115
+ name: 'sending_dns_record_name',
1116
+ record_type: 'TXT',
1117
+ valid: 'unknown',
1118
+ value: 'sending_dns_record_value'
1119
+ },
1120
+ ...
1121
+ ],
1122
+ changed: true
1123
+ }
1124
+ ```
1125
+
1126
+ - #### updateDKIMSelector
1127
+ Selector is the unique identifier of your key. It has to be different from other keys selector.
1128
+
1129
+ `mg.domains.updateDKIMSelector(domainAddress, data)` [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Domain-Keys/#tag/Domain-Keys/operation/PUT-v3-domains--name--dkim-selector)
1130
+
1131
+ Example:
1132
+
1133
+ ```JS
1134
+ mg.domains.updateDKIMSelector(domainAddress, {
1135
+ dkimSelector: 'dkimSelector_value'
1136
+ })
1137
+ .then(data => console.log(data)) // logs response data
1138
+ .catch(err => console.error(err)); // logs any error
1139
+ ```
1140
+
1141
+ Data object accepts next properties:
1142
+
1143
+ | Property | Description |
1144
+ |:--------------|:----------------------------------------------------------------------------------------------------------------------------------------------|
1145
+ | dkimSelector | Selector is the unique identifier of your key. It has to be different from other keys selector. |
1146
+
1147
+ Promise returns:
1148
+
1149
+ ```JS
1150
+ {
1151
+ message: 'DKIM selector changed',
1152
+ status: 200
1153
+ }
1154
+ ```
1155
+
1156
+ - #### getIps
1157
+ **Deprecated, and will be removed in the future releases**
1158
+
1159
+ `mg.domains.getIps(domain)`
1160
+
1161
+ Example:
1162
+
1163
+ ```js
1164
+ mg.domains.getIps('foobar.example.com')
1165
+ .then(msg => console.log(msg)) // logs response data
1166
+ .catch(err => console.error(err)); // logs any error
1167
+ ```
1168
+
1169
+ Promise returns:
1170
+
1171
+ ```JS
1172
+ ["192.168.0.1", "192.168.0.2"]
1173
+ ```
1174
+
1175
+ - #### assignIp
1176
+ **Deprecated, and will be removed in the future releases**
1177
+ `mg.domains.assignIp(domain, ip)`
1178
+
1179
+ Example:
1180
+
1181
+ ```JS
1182
+ mg.domains.assignIp('foobar.example.com', "192.168.0.3")
1183
+ .then(msg => console.log(msg)) // logs response data
1184
+ .catch(err => console.error(err)); // logs any error
1185
+ ```
1186
+
1187
+
1188
+ ```JS
1189
+ {
1190
+ message: 'success',
1191
+ status: 200,
1192
+ }
1193
+ ```
1194
+
1195
+ - #### deleteIp
1196
+ **Deprecated, and will be removed in the future releases**
1197
+ `mg.domains.deleteIp(domain, ip)`
1198
+
1199
+ Example:
1200
+
1201
+ ```JS
1202
+ mg.domains.deleteIp('foobar.example.com', "192.168.0.3")
1203
+ .then(msg => console.log(msg)) // logs response data
1204
+ .catch(err => console.error(err)); // logs any error
1205
+ ```
1206
+
1207
+ ```JS
1208
+ {
1209
+ message: 'success'
1210
+ }
1211
+ ```
1212
+
1213
+ ### Domain templates
1214
+
1215
+ - #### list
1216
+ Returns a list of templates for the domain.
1217
+
1218
+ `mg.domains.domainTemplates.list('domainId', query)` - [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Templates/#tag/Templates/operation/httpapi.(*TemplateAPIControler).GetPage-fm-9)
1219
+
1220
+ Example:
1221
+
1222
+ ```js
1223
+ mg.domains.domainTemplates.list('domainId',{
1224
+ limit: 10
1225
+ })
1226
+ .then(domainTemplates => console.log(domainTemplates)) // logs array of domain templates
1227
+ .catch(err => console.error(err)); // logs any error
1228
+ ```
1229
+
1230
+ Query data object may have next properties:
1231
+
1232
+ | Property | Description |
1233
+ |:----------|:------------------------------------------------------|
1234
+ | limit | Maximum number of records to return. (100 by default) |
1235
+ | page | params from previous response's 'paging' object. Value must be stringified as query params. e.g. '?page=first','?page=next&p=name-of-last-item'|
1236
+
1237
+ Promise returns: object with domain's templates
1238
+ ```JS
1239
+ {
1240
+ items: [
1241
+ {
1242
+ name: 'template_name',
1243
+ description: 'template description ',
1244
+ createdAt: new Date('2021-08-24T22:26:55.000Z'),
1245
+ createdBy: '',
1246
+ id: '48d63154-8c8f-4104-ab14-687d01dbf296'
1247
+ },
1248
+ ...
1249
+ ]
1250
+ }
1251
+ ```
1252
+
1253
+ - #### get
1254
+
1255
+ Returns metadata information about the stored template specified in the url. If the active flag is provided, the content of the active version of the template is returned.
1256
+
1257
+ `mg.domains.domainTemplates.get('domainId', 'templateName', query)` [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Templates/#tag/Templates/operation/httpapi.(*TemplateAPIControler).Get-fm-6)
1258
+
1259
+ Example:
1260
+
1261
+ ```js
1262
+ mg.domains.domainTemplates.get('domainId', 'template_name', {
1263
+ active: 'yes'
1264
+ }).then(data => console.log(data)) // logs template
1265
+ .catch(err => console.error(err)); // logs any error
1266
+ ```
1267
+
1268
+ Query data object may have next properties:
1269
+
1270
+ | Property | Description |
1271
+ |:----------|:------------------------------------------------------|
1272
+ | active | If this flag is set to yes the active version of the template is included in the response. |
1273
+
1274
+ Promise returns: object with domain template and active version
1275
+ ```JS
1276
+ {
1277
+ name: 'template_name',
1278
+ description: 'This is the description of the template',
1279
+ createdAt: new Date('2021-08-24T22:26:55.000Z'),
1280
+ createdBy: '',
1281
+ id: '46565d87-68b6-4edb-8b3c-34554af4bb77'
1282
+ version: {
1283
+ tag: 'tag',
1284
+ template: '<html>template content</html>',
1285
+ engine: 'handlebars',
1286
+ mjml: '',
1287
+ createdAt: new Date('2021-08-22T22:26:55.000Z'),
1288
+ comment: 'Version comment',
1289
+ active: true,
1290
+ id: '3efd2b85-0f41-4a1d-9898-05d7e7459c4a',
1291
+ headers: {
1292
+ From: 'from value'
1293
+ }
1294
+ }
1295
+ }
1296
+ ```
1297
+
1298
+ - #### create
1299
+ Store a new template, including its name, description and (optionally) the template content.
1300
+ If the template content is provided, a new version is automatically created and becomes the active version.
780
1301
 
781
- `mg.domains.destroy(domainAddress)`
1302
+ `mg.domains.domainTemplates.create(domainId, templateData)` [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Templates/#tag/Templates/operation/httpapi.(*TemplateAPIControler).Post-fm-4)
782
1303
 
783
1304
  Example:
784
1305
 
785
- ```JS
786
- mg.domains.destroy('foobar.example.com')
787
- .then(msg => console.log(msg)) // logs response data
1306
+ ```js
1307
+ mg.domains.domainTemplates.create('domainId', {
1308
+ name: 'template_name',
1309
+ createdBy: '',
1310
+ tag: 'tag',
1311
+ template: '<html>template content</html>',
1312
+ description: 'template description',
1313
+ comment: 'Version comment',
1314
+ headers: JSON.stringify({
1315
+ From: 'from value'
1316
+ }),
1317
+ engine: 'handlebars'
1318
+ }).then(data => console.log(data)) // logs created template
788
1319
  .catch(err => console.error(err)); // logs any error
789
1320
  ```
790
1321
 
791
- Promise returns:
1322
+ Template data object may have next properties:
1323
+
1324
+ | Property | Description |
1325
+ |:----------|:------------------------------------------------------|
1326
+ | name (required) | Name of the template being stored. Supports utf-8 characters and name will be down cased. |
1327
+ | createdBy | Optional metadata field api user can indicate who created the template. |
1328
+ | tag | Initial tag of the created version. If the template parameter is provided and the tag is missing, the default value **initial** is used. |
1329
+ | template | Content of the template. |
1330
+ | description | Description of the template being stored |
1331
+ | comment | Version comment. This is valid only if a new version is being created. (template parameter is provided.) |
1332
+ | headers | Key Value json dictionary of headers to be stored with the template. Where key is the header name and value is the header value. The header names **From**, **Subject**, and **Reply-To** are the only ones currently supported. These headers will be inserted into the mime at the time we attempt delivery.Headers set at the message level will override headers set on the template. e.g. Setting the From header at the time of sending will override the From header saved on the template. Additionally, headers generated by templates are not reflected on the accepted event as they are not prepended to the message until the message is prepped for delivery. if a From header is not provided either in the message or template, we will default to postmaster@your-sending-domain.tld |
1333
+ | engine | The template engine to be used when rendering the template. Supported value are handlebars and go (golang template). The default if parameter is not provided is handlebars. |
1334
+
1335
+ Promise returns: created domain template and active version
792
1336
 
793
1337
  ```JS
794
1338
  {
795
- message: "Domain has been deleted"
1339
+ name: 'template_name',
1340
+ description: 'template description',
1341
+ createdAt: new Date('2025-01-03T12:33:10.000Z'),
1342
+ createdBy: '',
1343
+ id: '46565d87-68b6-4edb-8b3c-34554af4bb77',
1344
+ version: {
1345
+ tag: 'tag',
1346
+ template: '<html>template content</html>',
1347
+ engine: 'handlebars',
1348
+ mjml: '',
1349
+ createdAt: new Date('2025-01-03T12:33:10.000Z'),
1350
+ comment: 'Version comment',
1351
+ active: true,
1352
+ id: '3efd2b85-0f41-4a1d-9898-05d7e7459c4a',
1353
+ headers: { From: 'from value' }
1354
+ }
796
1355
  }
797
1356
  ```
798
1357
 
799
- - #### getTracking
1358
+ - #### update
1359
+ Update the description of a template.
800
1360
 
801
- `mg.domains.getTracking(domainAddress)`
1361
+ `mg.domains.domainTemplates.update('domainId', 'templateName', data)` [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Templates/#tag/Templates/operation/httpapi.(*TemplateAPIControler).Put-fm-12)
802
1362
 
803
1363
  Example:
804
1364
 
805
- ```JS
806
- mg.domains.getTracking('foobar.example.com')
807
- .then(msg => console.log(msg)) // logs response data
1365
+ ```js
1366
+ mg.domains.domainTemplates.update('domainId', 'templateName', {
1367
+ description: 'new template description',
1368
+ }).then(data => console.log(data)) // logs data
808
1369
  .catch(err => console.error(err)); // logs any error
809
1370
  ```
810
1371
 
811
- Promise returns:
1372
+ Data object may have next properties:
1373
+
1374
+ | Property | Description |
1375
+ |:----------|:------------------------------------------------------|
1376
+ | description | Update description of the template being updated. |
812
1377
 
1378
+ Promise returns:
813
1379
  ```JS
814
1380
  {
815
- "click": {
816
- "active": false
817
- },
818
- "open": {
819
- "active": false
820
- },
821
- "unsubscribe": {
822
- "active": false,
823
- "html_footer": "\n<br>\n<p><a href=\"%unsubscribe_url%\">unsubscribe</a></p>\n",
824
- "text_footer": "\n\nTo unsubscribe click: <%unsubscribe_url%>\n\n"
825
- }
1381
+ status: 200,
1382
+ message: 'template has been updated',
1383
+ templateName: 'template_name'
826
1384
  }
827
1385
  ```
828
1386
 
829
- - #### updateTracking
830
-
831
- `mg.domains.updateTracking(domain, trackingType, data)`
1387
+ - #### destroy
1388
+ Delete the template specified in the url. NOTE: This method deletes all versions of the specified template.
832
1389
 
833
- - Open Tracking Example:
1390
+ `mg.domains.domainTemplates.destroy('domainId', 'templateName')` [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Templates/#tag/Templates/operation/httpapi.(*TemplateAPIControler).Delete-fm-13)
834
1391
 
835
- ```js
836
- mg.domains.updateTracking('foobar.example.com', 'open', {active: true})
837
- .then(msg => console.log(msg)) // logs response data
838
- .catch(err => console.error(err)); // logs any error
839
- ```
1392
+ Example:
840
1393
 
841
- Open tracking data object properties:
1394
+ ```js
1395
+ mg.domains.domainTemplates.destroy('domainId', 'templateName')
1396
+ .then(data => console.log(data)) // logs data
1397
+ .catch(err => console.error(err)); // logs any error
1398
+ ```
842
1399
 
843
- | Property | Description |
844
- |:----------|:-------------------------------------------|
845
- | active | Boolean, enables or disables open tracking |
1400
+ Promise returns:
1401
+ ```JS
1402
+ {
1403
+ status: 200,
1404
+ message: 'template has been deleted',
1405
+ templateName: 'template_name'
1406
+ }
1407
+ ```
846
1408
 
847
- Promise returns:
1409
+ - #### destroyAll
1410
+ Delete all templates and their versions for the domain.
848
1411
 
849
- ```JS
850
- {
851
- message: 'Tracking settings have been updated',
852
- open: {
853
- active: true
854
- }
855
- }
856
- ```
1412
+ `mg.domains.domainTemplates.destroyAll('domainId')` [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Templates/#tag/Templates/operation/httpapi.(*TemplateAPIControler).DeleteAll-fm-15)
857
1413
 
858
- - Click Tracking Example:
1414
+ Example:
859
1415
 
860
- ```JS
861
- mg.domains.updateTracking('foobar.example.com', 'click', {active: true})
862
- .then(msg => console.log(msg)) // logs response data
863
- .catch(err => console.error(err)); // logs any error
864
- ```
1416
+ ```js
1417
+ mg.domains.domainTemplates.destroyAll('domainId')
1418
+ .then(data => console.log(data)) // logs data
1419
+ .catch(err => console.error(err)); // logs any error
1420
+ ```
865
1421
 
866
- Click tracking data object properties:
1422
+ Promise returns:
1423
+ ```JS
1424
+ {
1425
+ status: 200,
1426
+ message: "templates have been deleted"
1427
+ }
1428
+ ```
867
1429
 
868
- | Property | Description |
869
- |:----------|:--------------------------------------------|
870
- | active | Boolean, enables or disables click tracking |
1430
+ - #### listVersions
1431
+ Returns a paginated list of template versions.
871
1432
 
872
- Promise returns:
1433
+ `mg.domains.domainTemplates.listVersions('domainId', 'template_name', queryData)` [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Templates/#tag/Templates/operation/httpapi.(*TemplateAPIControler).GetVersionsPage-fm-8)
873
1434
 
874
- ```JS
875
- {
876
- message: 'Tracking settings have been updated',
877
- click: {
878
- active: true
879
- }
880
- }
881
- ```
1435
+ Example:
882
1436
 
883
- - Unsubscribe Tracking Example:
1437
+ ```js
1438
+ mg.domains.domainTemplates.listVersions('domainId', 'template_name', {
1439
+ limit: 10,
1440
+ })
1441
+ .then(data => console.log(data)) // logs data
1442
+ .catch(err => console.error(err)); // logs any error
1443
+ ```
884
1444
 
885
- ```js
886
- mg.domains.updateTracking('foobar.example.com', 'unsubscribe', {
887
- active: true,
888
- html_footer: "\n<br>\n<p><a href=\"%unsubscribe_url%\">unsubscribe</a></p>\n",
889
- text_footer: "\n\nTo unsubscribe click: <%unsubscribe_url%>\n\n"
890
- })
891
- .then(msg => console.log(msg)) // logs response data
892
- .catch(err => console.error(err)); // logs any error
893
- ```
1445
+ Query data object may have next properties:
894
1446
 
895
- Unsubscribe Tracking data object properties:
1447
+ | Property | Description |
1448
+ |:----------|:------------------------------------------------------|
1449
+ | limit | Maximum number of records to return. (100 by default) |
1450
+ | page | params from previous response's 'paging' object. Value must be stringified as query params. e.g. '?page=first','?page=next&p=name-of-last-item'|
896
1451
 
897
- | Property | Description |
898
- |:------------|:--------------------------------------------------------------|
899
- | active | Boolean, enables or disables unsubscribe tracking |
900
- | html_footer | string appended to html emails for managing unsubscribe links |
901
- | text_footer | string appended to html emails for managing unsubscribe links |
1452
+ Promise returns:
1453
+ ```JS
1454
+ {
1455
+ template: {
1456
+ name: 'template_name',
1457
+ description: 'template description',
1458
+ createdAt: new Date('2025-01-03T12:33:10.000Z'),
1459
+ createdBy: '',
1460
+ id: '46565d87-68b6-4edb-8b3c-34554af4bb77',
1461
+ versions: [
1462
+ {
1463
+ tag: 'tag',
1464
+ engine: 'handlebars',
1465
+ mjml: '',
1466
+ createdAt: new Date('2025-01-03T12:33:10.000Z'),
1467
+ comment: 'Version comment',
1468
+ active: true,
1469
+ id: 'b3f09533-a03f-4e10-9aac-a91115297b6c'
1470
+ }
1471
+ ]
1472
+ }
1473
+ }
1474
+ ```
902
1475
 
903
- Promise returns:
1476
+ - #### getVersion
904
1477
 
905
- ```JS
906
- {
907
- message: 'Tracking settings have been updated',
908
- "unsubscribe": {
909
- "active": true,
910
- "html_footer": "\n<br>\n<p><a href=\"%unsubscribe_url%\">unsubscribe</a></p>\n",
911
- "text_footer": "\n\nTo unsubscribe click: <%unsubscribe_url%>\n\n"
912
- }
913
- }
914
- ```
1478
+ Retrieve the information and content of the specified version of a template.
915
1479
 
916
- - #### getIps
917
- `mg.domains.getIps(domain)`
1480
+ `mg.domains.domainTemplates.getVersion('domainId', 'template_name', 'tag')` [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Templates/#tag/Templates/operation/httpapi.(*TemplateAPIControler).GetVersion-fm-7)
918
1481
 
919
- Example:
1482
+ Example:
920
1483
 
921
- ```js
922
- mg.domains.getIps('foobar.example.com')
923
- .then(msg => console.log(msg)) // logs response data
924
- .catch(err => console.error(err)); // logs any error
925
- ```
1484
+ ```js
1485
+ mg.domains.domainTemplates.getVersion('domainId', 'template_name','tag')
1486
+ .then(data => console.log(data)) // logs data
1487
+ .catch(err => console.error(err)); // logs any error
1488
+ ```
926
1489
 
927
- Promise returns:
1490
+ Promise returns:
1491
+ ```JS
1492
+ {
1493
+ template: {
1494
+ name: 'template_name',
1495
+ description: 'template description',
1496
+ createdAt: new Date('2025-01-03T12:33:10.000Z'),
1497
+ createdBy: '',
1498
+ id: '46565d87-68b6-4edb-8b3c-34554af4bb77',
1499
+ versions: [
1500
+ {
1501
+ tag: 'tag',
1502
+ template: '<html>template content</html>',
1503
+ engine: 'handlebars',
1504
+ mjml: '',
1505
+ createdAt: new Date('2025-01-03T12:33:10.000Z'),
1506
+ comment: 'Version comment',
1507
+ active: true,
1508
+ id: 'b3f09533-a03f-4e10-9aac-a91115297b6c',
1509
+ headers: {
1510
+ From: 'from value'
1511
+ }
1512
+ }
1513
+ ]
1514
+ }
1515
+ }
1516
+ ```
928
1517
 
929
- ```JS
930
- ["192.168.0.1", "192.168.0.2"]
931
- ```
1518
+ - #### createVersion
1519
+ Adds a new template version. If the template doesn’t contain any other versions, the first version becomes active. A template can store up to 40 versions.
932
1520
 
933
- - #### assignIp
934
- `mg.domains.assignIp(domain, ip)`
1521
+ `mg.domains.domainTemplates.createVersion('domainId', 'template_name', versionData)` [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Templates/#tag/Templates/operation/httpapi.(*TemplateAPIControler).PostVersion-fm-5)
935
1522
 
936
1523
  Example:
937
1524
 
938
- ```JS
939
- mg.domains.assignIp('foobar.example.com', "192.168.0.3")
940
- .then(msg => console.log(msg)) // logs response data
1525
+ ```js
1526
+ mg.domains.domainTemplates.createVersion('domainId', 'template_name',{
1527
+ {
1528
+ template: `<html>template content</html>`,
1529
+ tag: 'v1',
1530
+ engine: 'handlebars',
1531
+ comment: 'comment',
1532
+ active: 'yes',
1533
+ headers: JSON.stringify({
1534
+ From: 'from value'
1535
+ })
1536
+ }
1537
+ })
1538
+ .then(data => console.log(data)) // logs data
941
1539
  .catch(err => console.error(err)); // logs any error
942
1540
  ```
943
1541
 
1542
+ Template version data object may have next properties:
944
1543
 
1544
+ | Property | Description |
1545
+ |:----------|:------------------------------------------------------|
1546
+ | template | Content of the template. |
1547
+ | tag | Initial tag of the created version. If the template parameter is provided and the tag is missing, the default value **initial** is used. |
1548
+ | engine | The template engine to be used when rendering the template. Supported value are handlebars and go (golang template). The default if parameter is not provided is handlebars. |
1549
+ | comment | Version comment. This is valid only if a new version is being created. (template parameter is provided.) |
1550
+ | active | If this flag is set to yes, this version becomes active. |
1551
+ | headers | Key Value json dictionary of headers to be stored with the template. Where key is the header name and value is the header value. The header names **From**, **Subject**, and **Reply-To** are the only ones currently supported. These headers will be inserted into the mime at the time we attempt delivery.Headers set at the message level will override headers set on the template. e.g. Setting the From header at the time of sending will override the From header saved on the template. Additionally, headers generated by templates are not reflected on the accepted event as they are not prepended to the message until the message is prepped for delivery. if a From header is not provided either in the message or template, we will default to postmaster@your-sending-domain.tld |
1552
+
1553
+ Promise returns:
945
1554
  ```JS
946
1555
  {
947
- message: 'success',
948
1556
  status: 200,
1557
+ message: 'new version of the template has been stored',
1558
+ template: l {
1559
+ name: 'template_name',
1560
+ description: 'new template description',
1561
+ createdAt: new Date('2025-01-03T12:33:10.000Z'),
1562
+ createdBy: '',
1563
+ id: '46565d87-68b6-4edb-8b3c-34554af4bb77',
1564
+ version: {
1565
+ tag: 'v1',
1566
+ template: '<html>template content</html>',
1567
+ engine: 'handlebars',
1568
+ mjml: '',
1569
+ createdAt: new Date('2025-01-03T13:41:26.000Z'),
1570
+ comment: 'comment',
1571
+ active: true,
1572
+ id: '3efd2b85-0f41-4a1d-9898-05d7e7459c4a',
1573
+ headers: [Object]
1574
+ }
1575
+ }
949
1576
  }
950
1577
  ```
951
1578
 
952
- - #### deleteIp
953
- `mg.domains.deleteIp(domain, ip)`
1579
+ - #### updateVersion
1580
+ Update information or content of the specific template version.
1581
+ Existing fields not included in the request will not be changed
1582
+
1583
+ `mg.domains.domainTemplates.updateVersion('domainId', 'template_name', 'tag' , versionData)` [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Templates/#tag/Templates/operation/httpapi.(*TemplateAPIControler).PutVersion-fm-11)
954
1584
 
955
1585
  Example:
956
1586
 
957
- ```JS
958
- mg.domains.deleteIp('foobar.example.com', "192.168.0.3")
959
- .then(msg => console.log(msg)) // logs response data
1587
+ ```js
1588
+ mg.domains.domainTemplates.updateVersion('domainId', 'template_name', 'v1',{
1589
+ {
1590
+ template: `<html>template content</html>`,
1591
+ engine: 'handlebars',
1592
+ comment: 'comment',
1593
+ active: 'yes',
1594
+ headers: JSON.stringify({
1595
+ From: 'from value'
1596
+ })
1597
+ }
1598
+ })
1599
+ .then(data => console.log(data)) // logs data
960
1600
  .catch(err => console.error(err)); // logs any error
961
1601
  ```
962
1602
 
1603
+ Template version data object may have next properties:
1604
+
1605
+ | Property | Description |
1606
+ |:----------|:------------------------------------------------------|
1607
+ | template | Content of the template. |
1608
+ | engine | The template engine to be used when rendering the template. Supported value are handlebars and go (golang template). The default if parameter is not provided is handlebars. |
1609
+ | comment | Version comment. This is valid only if a new version is being created. (template parameter is provided.) |
1610
+ | active | If this flag is set to yes, this version becomes active. |
1611
+ | headers | Key Value json dictionary of headers to be stored with the template. Where key is the header name and value is the header value. The header names **From**, **Subject**, and **Reply-To** are the only ones currently supported. These headers will be inserted into the mime at the time we attempt delivery.Headers set at the message level will override headers set on the template. e.g. Setting the From header at the time of sending will override the From header saved on the template. Additionally, headers generated by templates are not reflected on the accepted event as they are not prepended to the message until the message is prepped for delivery. if a From header is not provided either in the message or template, we will default to postmaster@your-sending-domain.tld |
1612
+
1613
+ Promise returns:
963
1614
  ```JS
964
1615
  {
965
- message: 'success'
1616
+ status: 200,
1617
+ message: 'version has been updated',
1618
+ templateName: 'template_name',
1619
+ templateVersion: {
1620
+ tag: 'v1'
1621
+ }
966
1622
  }
967
1623
  ```
968
1624
 
1625
+ - #### destroyVersion
1626
+ Delete a specific template version.
1627
+
1628
+ `mg.domains.domainTemplates.destroyVersion('domainId', 'template_name', 'tag' )` [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Templates/#tag/Templates/operation/httpapi.(*TemplateAPIControler).DeleteVersion-fm-14)
1629
+
1630
+ Example:
1631
+
1632
+ ```js
1633
+ mg.domains.domainTemplates.destroyVersion('domainId', 'template_name', 'v1')
1634
+ .then(data => console.log(data)) // logs data
1635
+ .catch(err => console.error(err)); // logs any error
1636
+ ```
1637
+ Promise returns:
1638
+ ```JS
1639
+ {
1640
+ status: 200,
1641
+ message: 'version has been deleted',
1642
+ templateName: 'template_name',
1643
+ templateVersion: { tag: 'v1' }
1644
+ }
1645
+ ```
1646
+
969
1647
  ### Events
970
1648
 
971
1649
  - #### get
@@ -1023,7 +1701,7 @@ The following service methods are available to instantiated clients. The example
1023
1701
  ```
1024
1702
 
1025
1703
  ### Stats
1026
- - Stats Options
1704
+ - #### Stats Options
1027
1705
 
1028
1706
  | Parameter | Description |
1029
1707
  |:-----------|:---------------------------------------------------------------------------------------------------------------------------|
@@ -1110,6 +1788,145 @@ The following service methods are available to instantiated clients. The example
1110
1788
  }
1111
1789
  ```
1112
1790
 
1791
+
1792
+ ```
1793
+
1794
+ ### Metrics
1795
+ Mailgun collects many different events and generates event metrics which are available in your Control Panel. This data is also available via our analytics metrics [API endpoint](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Metrics/#tag/Metrics).
1796
+
1797
+ - #### getAccount
1798
+ Gets filtered metrics for an account
1799
+
1800
+ `mg.metrics.getAccount(MetricsQuery);`
1801
+
1802
+ Example:
1803
+ ```JS
1804
+ mg.metrics.getAccount({
1805
+ start: '2024-12-16T10:47:51.661Z',
1806
+ end: '2024-12-23T10:47:51.661Z',
1807
+ resolution: 'hour',
1808
+ metrics: ['opened_count'],
1809
+ filter: {
1810
+ AND: [{
1811
+ attribute: 'domain',
1812
+ comparator: 'contains',
1813
+ values: [{
1814
+ value: 'mailgun'
1815
+ }]
1816
+ }]
1817
+ },
1818
+ include_subaccounts: true,
1819
+ include_aggregates: true
1820
+ })
1821
+ .then(data => console.log(data)) // logs response data
1822
+ .catch(err => console.error(err)); //logs any error
1823
+ ```
1824
+ *getAccount* method accepts data object with next properties:
1825
+ | Property | Type |Description |
1826
+ |:--------------|:-----|:-----------------------------------------------------------------------------------------------------------------------------------|
1827
+ | start | String that contains date in RFC 2822 format: https://datatracker.ietf.org/doc/html/rfc2822.html#page-14 or JS Date object | A start date (default: 7 days before current time)|
1828
+ | end | String that contains date in RFC 2822 format: https://datatracker.ietf.org/doc/html/rfc2822.html#page-14 or JS Date object | An end date (default: current time)|
1829
+ | resolution | String | A resolution in the format of 'day' 'hour' 'month'. Default is day.|
1830
+ | duration | String | A duration in the format of '1d' '2h' '2m'. If duration is provided then it is calculated from the end date and overwrites the start date.|
1831
+ | dimensions | Array of strings | Attributes of the metric data such as 'subaccount'.|
1832
+ | metrics | Array of strings | Name of the metrics to receive the stats for such as 'processed_count'.|
1833
+ | filter | object | Filters to apply to the query. The 'AND' property is required and should contains array of filters objects. See this [document](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Metrics/#tag/Metrics/operation/api.(*MetricsAPI).PostMetricQuery-fm-3!path=filter&t=request) for an object shape. |
1834
+ | include_subaccounts | Boolean | Include stats from all subaccounts. |
1835
+ | include_aggregates | Boolean | Include top-level aggregate metrics.|
1836
+
1837
+ Promise returns: MetricsResult
1838
+
1839
+ ```JS
1840
+ {
1841
+ start: new Date('2024-12-16T01:00:00.000Z'),
1842
+ end: new Date('2024-12-23T00:00:00.000Z'),
1843
+ resolution: 'hour',
1844
+ dimensions: [ 'time' ],
1845
+ pagination: { sort: '', skip: 0, limit: 1500, total: 1 },
1846
+ items: [
1847
+ {
1848
+ dimensions: [{
1849
+ {
1850
+ dimension: 'time',
1851
+ value: 'Sat, 21 Dec 2024 17:00:00 +0000',
1852
+ display_value: 'Sat, 21 Dec 2024 17:00:00 +0000'
1853
+ }
1854
+ }],
1855
+ metrics: { opened_count: 1 }
1856
+ },
1857
+ ...
1858
+ ],
1859
+ aggregates: { metrics: { opened_count: 1 } },
1860
+ status: 200
1861
+ }
1862
+ ```
1863
+
1864
+ - #### getAccountUsage
1865
+ Gets filtered **usage metrics** for an account
1866
+ `mg.metrics.getAccountUsage(MetricsQuery);`
1867
+
1868
+ Example:
1869
+ ```JS
1870
+ mg.metrics.getAccountUsage({
1871
+ start: '2024-12-16T10:47:51.661Z',
1872
+ end: '2024-12-23T10:47:51.661Z',
1873
+ resolution: 'hour',
1874
+ metrics: ['opened_count'],
1875
+ filter: {
1876
+ AND: [{
1877
+ attribute: 'domain',
1878
+ comparator: 'contains',
1879
+ values: [{
1880
+ value: 'mailgun'
1881
+ }]
1882
+ }]
1883
+ },
1884
+ include_subaccounts: true,
1885
+ include_aggregates: true
1886
+ })
1887
+ .then(data => console.log(data)) // logs response data
1888
+ .catch(err => console.error(err)); //logs any error
1889
+ ```
1890
+ *getAccountUsage* method accepts data object with next properties:
1891
+ | Property | Type |Description |
1892
+ |:--------------|:-----|:-----------------------------------------------------------------------------------------------------------------------------------|
1893
+ | start | String that contains date in RFC 2822 format: https://datatracker.ietf.org/doc/html/rfc2822.html#page-14 or JS Date object | A start date (default: 7 days before current time)|
1894
+ | end | String that contains date in RFC 2822 format: https://datatracker.ietf.org/doc/html/rfc2822.html#page-14 or JS Date object | An end date (default: current time)|
1895
+ | resolution | String | A resolution in the format of 'day' 'hour' 'month'. Default is day.|
1896
+ | duration | String | A duration in the format of '1d' '2h' '2m'. If duration is provided then it is calculated from the end date and overwrites the start date.|
1897
+ | dimensions | Array of strings | Attributes of the metric data such as 'subaccount'.|
1898
+ | metrics | Array of strings | Name of the metrics to receive the stats for such as 'processed_count'.|
1899
+ | filter | object | Filters to apply to the query. The 'AND' property is required and should contains array of filters objects. See this [document](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Metrics/#tag/Metrics/operation/api.(*MetricsAPI).PostMetricQuery-fm-3!path=filter&t=request) for an object shape. |
1900
+ | include_subaccounts | Boolean | Include stats from all subaccounts. |
1901
+ | include_aggregates | Boolean | Include top-level aggregate metrics.|
1902
+
1903
+ Promise returns: MetricsResult
1904
+
1905
+ ```JS
1906
+ {
1907
+ start: new Date('2024-12-16T01:00:00.000Z'),
1908
+ end: new Date('2024-12-23T00:00:00.000Z'),
1909
+ resolution: 'hour',
1910
+ dimensions: [ 'time' ],
1911
+ pagination: { sort: '', skip: 0, limit: 1500, total: 1 },
1912
+ items: [
1913
+ {
1914
+ dimensions: [{
1915
+ {
1916
+ dimension: 'time',
1917
+ value: 'Sat, 21 Dec 2024 17:00:00 +0000',
1918
+ display_value: 'Sat, 21 Dec 2024 17:00:00 +0000'
1919
+ }
1920
+ }],
1921
+ metrics: { opened_count: 1 }
1922
+ },
1923
+ ...
1924
+ ],
1925
+ aggregates: { metrics: { opened_count: 1 } },
1926
+ status: 200
1927
+ }
1928
+ ```
1929
+
1113
1930
  ### Suppressions
1114
1931
 
1115
1932
  - #### list
@@ -3165,7 +3982,6 @@ A client to manage members within a specific mailing list.
3165
3982
  results: 'link to result page',
3166
3983
  }
3167
3984
  }
3168
- ```
3169
3985
 
3170
3986
  ## Navigation thru lists
3171
3987
  Most of the methods that return items in a list support pagination.