mailgun.js 10.4.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,65 +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)
139
156
  - [Stats Options](#stats-options)
140
157
  - [getDomain](#getdomain)
141
158
  - [getAccount](#getaccount)
142
- - [Metrics](#metrics)
159
+ - [metrics](#metrics)
143
160
  - [getAccount](#getaccount-1)
144
161
  - [getAccountUsage](#getaccountusage)
145
162
  - [suppressions](#suppressions)
146
- - [list](#list-1)
163
+ - [list](#list-2)
147
164
  - [Bounces Example](#bounces-example)
148
165
  - [Unsubscribes Example](#unsubscribes-example)
149
166
  - [Complaints Example](#complaints-example)
150
- - [get](#get-2)
167
+ - [get](#get-3)
151
168
  - [Bounces Example](#bounces-example-1)
152
169
  - [Unsubscribes Example](#unsubscribes-example-1)
153
170
  - [Complaints Example](#complaints-example-1)
154
- - [create](#create-2)
171
+ - [create](#create-3)
155
172
  - [Bounces Example](#bounces-example-2)
156
173
  - [Unsubscribes Example](#unsubscribes-example-2)
157
174
  - [Unsubscribe from one tag](#unsubscribe-from-one-tag)
158
175
  - [Unsubscribe from particular tags](#unsubscribe-from-particular-tags)
159
176
  - [Complaints Example](#complaints-example-2)
160
- - [destroy](#destroy-1)
177
+ - [destroy](#destroy-2)
161
178
  - [Bounces Example](#bounces-example-3)
162
179
  - [Unsubscribes Example](#unsubscribes-example-3)
163
180
  - [Complaints Example](#complaints-example-3)
164
181
  - [webhooks](#webhooks)
165
- - [list](#list-2)
166
- - [get](#get-3)
167
- - [create](#create-3)
168
- - [update](#update-1)
169
- - [destroy](#destroy-2)
170
- - [routes](#routes)
171
182
  - [list](#list-3)
172
183
  - [get](#get-4)
173
184
  - [create](#create-4)
174
185
  - [update](#update-2)
175
186
  - [destroy](#destroy-3)
176
- - [validate](#validate)
177
- - [get](#get-5)
178
- - [multiple validation](#multiple-validation)
179
- - [create](#create-5)
187
+ - [routes](#routes)
180
188
  - [list](#list-4)
181
189
  - [get](#get-5)
190
+ - [create](#create-5)
191
+ - [update](#update-3)
182
192
  - [destroy](#destroy-4)
183
- - [mailing lists](#mailing-lists)
184
- - [list](#list-5)
193
+ - [validate](#validate)
185
194
  - [get](#get-6)
195
+ - [multiple validation](#multiple-validation)
186
196
  - [create](#create-6)
187
- - [update](#update-3)
197
+ - [list](#list-5)
198
+ - [get](#get-7)
188
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)
189
206
  - [mailing list members](#mailing-list-members)
190
207
  - [listMembers](#listmember)
191
208
  - [getMember](#getmember)
@@ -194,38 +211,38 @@ The following service methods are available to instantiated clients. The example
194
211
  - [updateMember](#updatemember)
195
212
  - [destroyMember](#destroymember)
196
213
  - [subaccounts](#subaccounts)
197
- - [list](#list-6)
198
- - [get](#get-8)
199
- - [create](#create-7)
214
+ - [list](#list-7)
215
+ - [get](#get-9)
216
+ - [create](#create-8)
200
217
  - [enable](#enable)
201
218
  - [disable](#disable)
202
- - [Inbox Placements](#inbox-placements)
219
+ - [inbox placements](#inbox-placements)
203
220
  - [SeedsLists](#seedslists)
204
- - [list](#list-7)
205
- - [get](#get-9)
206
- - [create](#create-8)
207
- - [update](#update-4)
208
- - [destroy](#destroy-6)
221
+ - [list](#list-8)
222
+ - [get](#get-10)
223
+ - [create](#create-9)
224
+ - [update](#update-5)
225
+ - [destroy](#destroy-7)
209
226
  - [SeedsLists Attributes](#attributes)
210
- - [list](#list-8)
211
- - [get](#get-10)
212
- - [SeedsLists Filters](#filters)
213
227
  - [list](#list-9)
228
+ - [get](#get-11)
229
+ - [SeedsLists Filters](#filters)
230
+ - [list](#list-10)
214
231
  - [Providers](#providers)
215
- - [list](#list-10)
216
- - [Results](#results)
217
232
  - [list](#list-11)
218
- - [get](#get-11)
219
- - [destroy](#destroy-7)
233
+ - [Results](#results)
234
+ - [list](#list-12)
235
+ - [get](#get-12)
236
+ - [destroy](#destroy-8)
220
237
  - [getResultByShareId](#getresultbyshareid)
221
238
  - [Results Attributes](#attributes-1)
222
- - [list](#list-12)
223
- - [get](#get-12)
224
- - [Results Filters](#filters-1)
225
239
  - [list](#list-13)
226
- - [Sharing](#sharing)
227
240
  - [get](#get-13)
228
- - [update](#update-5)
241
+ - [Results Filters](#filters-1)
242
+ - [list](#list-14)
243
+ - [Sharing](#sharing)
244
+ - [get](#get-14)
245
+ - [update](#update-6)
229
246
  - [Run Test](#run-test)
230
247
  - [Navigation thru lists](#navigation-thru-lists)
231
248
  - [Browser Demo](#browser-demo)
@@ -521,10 +538,11 @@ The following service methods are available to instantiated clients. The example
521
538
  ```
522
539
 
523
540
  ### Domains
541
+ Domains API manages domains, domain keys and DNS verification.
524
542
 
525
543
  - #### list
526
-
527
- `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)
528
546
 
529
547
  Example:
530
548
 
@@ -538,18 +556,23 @@ The following service methods are available to instantiated clients. The example
538
556
 
539
557
  ```JS
540
558
  [{
541
- created_at: 'Sun, 19 Oct 2014 18:49:36 GMT',
542
559
  name: 'testing.example.com',
543
- receiving_dns_records: null,
544
560
  require_tls: true,
545
- sending_dns_records: null,
546
561
  skip_verification: true,
547
- smtp_login: 'postmaster@testing.example.com',
548
- smtp_password: 'password',
549
- spam_action: 'disabled',
550
562
  state: 'unverified',
551
- type: 'custom',
552
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
553
576
  }]
554
577
  ```
555
578
 
@@ -559,159 +582,248 @@ The following service methods are available to instantiated clients. The example
559
582
  |:----------|:------------------------------------------------------|
560
583
  | limit | Maximum number of records to return. (100 by default) |
561
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|
562
589
 
563
590
  - #### get
591
+ Fetches representation of a domain that includes details about the domain's state and settings.
564
592
 
565
- `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-)
566
594
 
567
595
  Example:
568
596
 
569
597
  ```JS
570
- mg.domains.get('testing.example.com')
571
- .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
572
602
  .catch(err => console.error(err)); // logs any error
573
603
  ```
574
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
+
575
612
  Promise returns: Domain instance
576
613
 
577
614
  ```JS
578
615
  {
579
- created_at: 'Sun, 19 Oct 2014 18:49:36 GMT',
580
616
  name: 'testing.example.com',
581
- receiving_dns_records: [{
582
- "name": "testing.example.com",
583
- "record_type": "TXT",
584
- "valid": "unknown",
585
- "value": "v=spf1 include:mailgun.org ~all"
586
- },
587
- {
588
- "name": "k1._domainkey.testing.example.com",
589
- "record_type": "TXT",
590
- "valid": "unknown",
591
- "value": "k=rsa; 123456"
592
- },
593
- {
594
- "name": "email.testing.example.com",
595
- "record_type": "CNAME",
596
- "valid": "unknown",
597
- "value": "mailgun.org"
598
- }],
599
617
  require_tls: true,
600
- sending_dns_records: [{
601
- "priority": "10",
602
- "record_type": "MX",
603
- "valid": "unknown",
604
- "value": "mxa.mailgun.org"
605
- },
606
- {
607
- "priority": "10",
608
- "record_type": "MX",
609
- "valid": "unknown",
610
- "value": "mxb.mailgun.org"
611
- }],
612
618
  skip_verification: true,
613
- smtp_login: 'postmaster@testing.example.com',
614
- smtp_password: 'password',
615
- spam_action: 'disabled',
616
619
  state: 'unverified',
617
- type: 'custom',
618
620
  wildcard: true,
619
- 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',
620
649
  is_disabled: false,
621
650
  web_prefix: 'email',
622
- 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.
623
655
  }
624
656
  ```
625
657
 
626
658
  - #### create
659
+ Creates a domain for sending emails
627
660
 
628
- `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)
629
662
 
630
663
  Example:
631
664
 
632
665
  ```js
633
- mg.domains.create({name: 'foobar.example.com'})
634
- .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
635
683
  .catch(err => console.error(err)); // logs any error
636
684
  ```
637
685
 
638
686
  Create method accepts data object with next properties:
639
687
 
640
- | Parameter | Description |
641
- |--- |--- |
642
- | name | Name of the domain (ex. domain.com) |
643
- | smtp_password | Password for SMTP authentication |
644
- | 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`. |
645
- | 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`. |
646
- | 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`. |
647
- | dkim_key_size | **1024** or **2048**<br>Set the length of your domain’s generated DKIM key<br>The default is **1024** |
648
- | 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. |
649
- | 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) |
650
- | 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. |
651
705
 
652
706
  Promise returns:
653
707
 
654
708
  ```JS
655
- name: 'foobar.example.com',
656
- require_tls: false,
657
- skip_verification: false,
658
- state: 'unverified',
659
- wildcard: false,
660
- spam_action: 'disabled',
661
- created_at: 'Tue, 04 Jul 2023 14:09:18 GMT',
662
- smtp_password: undefined,
663
- smtp_login: 'postmaster@foobar.example.com',
664
- type: 'custom',
665
- receiving_dns_records: [{
666
- "name": "foobar.example.com",
667
- "record_type": "TXT",
668
- "valid": "unknown",
669
- "value": "v=spf1 include:mailgun.org ~all"
670
- },
671
- {
672
- "name": "k1._domainkey.foobar.example.com",
673
- "record_type": "TXT",
674
- "valid": "unknown",
675
- "value": "k=rsa; 123456"
676
- },
677
- {
678
- "name": "email.foobar.example.com",
679
- "record_type": "CNAME",
680
- "valid": "unknown",
681
- "value": "mailgun.org"
682
- }
683
- ],
684
- sending_dns_records: [{
685
- "priority": "10",
686
- "record_type": "MX",
687
- "valid": "unknown",
688
- "value": "mxa.mailgun.org"
689
- },
690
- {
691
- "priority": "10",
692
- "record_type": "MX",
693
- "valid": "unknown",
694
- "value": "mxb.mailgun.org"
695
- }],
696
- id: '64a4291ebbe4ec7e1d78bc80',
697
- is_disabled: false,
698
- web_prefix: 'email',
699
- 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
+ }
700
805
  ```
701
806
 
807
+
702
808
  - #### update
809
+ Update domains configuration like smtp credentials, enable/disable automatic sender security, spam actions, wildcard, or tracking web scheme.
703
810
 
704
- `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-)
705
812
 
706
813
  Example:
707
814
 
708
815
  ```js
709
816
  mg.domains.update('foobar.example.com',{
710
- 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
711
822
  web_scheme: 'http',
712
- spam_action: 'disabled',
823
+ web_prefix: 'web_prefix_value'
824
+ wildcard: 'true',
713
825
  })
714
- .then(msg => console.log(msg)) // logs response data
826
+ .then(data => console.log(data)) // logs response data
715
827
  .catch(err => console.error(err)); // logs any error
716
828
  ```
717
829
 
@@ -719,8 +831,13 @@ The following service methods are available to instantiated clients. The example
719
831
 
720
832
  | Property | Description |
721
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 |
722
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`|
723
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 |
724
841
  | wildcard | Can be string `'true'` or `'false'` or `boolean`. Determines whether the domain will accept email for sub-domains. The default is `false`.|
725
842
 
726
843
  Promise returns:
@@ -733,7 +850,7 @@ The following service methods are available to instantiated clients. The example
733
850
  state: 'unverified',
734
851
  wildcard: true,
735
852
  spam_action: 'disabled',
736
- created_at: 'Tue, 04 Jul 2023 14:09:18 GMT',
853
+ created_at: new Date('2025-01-08T12:52:29.000Z'),
737
854
  smtp_password: undefined,
738
855
  smtp_login: 'postmaster@foobar.example.com',
739
856
  type: 'custom',
@@ -744,16 +861,9 @@ The following service methods are available to instantiated clients. The example
744
861
  priority: '10',
745
862
  record_type: 'MX',
746
863
  valid: 'unknown',
747
- value: 'mxa.mailgun.org'
864
+ value: 'receiving_dns_record_value'
748
865
  },
749
- {
750
- is_active: true,
751
- cached: [],
752
- priority: '10',
753
- record_type: 'MX',
754
- valid: 'unknown',
755
- value: 'mxb.mailgun.org'
756
- }
866
+ ...
757
867
  ],
758
868
  sending_dns_records: [
759
869
  {
@@ -762,47 +872,45 @@ The following service methods are available to instantiated clients. The example
762
872
  name: 'foobar.example.com',
763
873
  record_type: 'TXT',
764
874
  valid: 'unknown',
765
- value: 'v=spf1 include:mailgun.org ~all'
875
+ value: 'sending_dns_record_value'
766
876
  },
767
- {
768
- is_active: true,
769
- cached: [],
770
- name: 'email.foobar.example.com',
771
- record_type: 'CNAME',
772
- valid: 'unknown',
773
- value: 'mailgun.org'
774
- }
877
+ ...
775
878
  ],
776
879
  id: '64a5880eere4eg7e1d85bc69',
777
880
  is_disabled: false,
778
- web_prefix: 'email',
779
- web_scheme: 'http'
881
+ web_prefix: 'test',
882
+ web_scheme: 'https',
883
+ use_automatic_sender_security: true
780
884
  }
781
885
  ```
782
886
 
783
- - #### destroy
784
887
 
785
- `mg.domains.destroy(domainAddress)`
888
+
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-)
786
892
 
787
893
  Example:
788
894
 
789
895
  ```JS
790
896
  mg.domains.destroy('foobar.example.com')
791
- .then(msg => console.log(msg)) // logs response data
897
+ .then(data => console.log(data)) // logs response data
792
898
  .catch(err => console.error(err)); // logs any error
793
899
  ```
794
900
 
795
- Promise returns:
901
+ Promise returns message:
796
902
 
797
903
  ```JS
798
904
  {
799
- message: "Domain has been deleted"
905
+ message: "Domain will be deleted in the background"
800
906
  }
801
907
  ```
802
908
 
909
+
803
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.
804
912
 
805
- `mg.domains.getTracking(domainAddress)`
913
+ `mg.domains.getTracking(domainAddress)` [api docs](https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Domain-Tracking/#tag/Domain-Tracking)
806
914
 
807
915
  Example:
808
916
 
@@ -831,13 +939,18 @@ The following service methods are available to instantiated clients. The example
831
939
  ```
832
940
 
833
941
  - #### updateTracking
942
+ A common method to turn on/off the click, open, and unsubscribe tracking at the domain level.
834
943
 
835
944
  `mg.domains.updateTracking(domain, trackingType, data)`
836
945
 
837
946
  - Open Tracking Example:
838
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)
839
949
  ```js
840
- mg.domains.updateTracking('foobar.example.com', 'open', {active: true})
950
+ mg.domains.updateTracking('foobar.example.com', 'open', {
951
+ active: true,
952
+ place_at_the_top: true,
953
+ })
841
954
  .then(msg => console.log(msg)) // logs response data
842
955
  .catch(err => console.error(err)); // logs any error
843
956
  ```
@@ -847,6 +960,7 @@ The following service methods are available to instantiated clients. The example
847
960
  | Property | Description |
848
961
  |:----------|:-------------------------------------------|
849
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. |
850
964
 
851
965
  Promise returns:
852
966
 
@@ -854,13 +968,15 @@ The following service methods are available to instantiated clients. The example
854
968
  {
855
969
  message: 'Tracking settings have been updated',
856
970
  open: {
857
- active: true
971
+ active: true,
972
+ place_at_the_top: true,
858
973
  }
859
974
  }
860
975
  ```
861
976
 
862
977
  - Click Tracking Example:
863
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)
864
980
  ```JS
865
981
  mg.domains.updateTracking('foobar.example.com', 'click', {active: true})
866
982
  .then(msg => console.log(msg)) // logs response data
@@ -884,8 +1000,9 @@ The following service methods are available to instantiated clients. The example
884
1000
  }
885
1001
  ```
886
1002
 
887
- - Unsubscribe Tracking Example:
1003
+ - Unsubscribe Tracking Example
888
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)
889
1006
  ```js
890
1007
  mg.domains.updateTracking('foobar.example.com', 'unsubscribe', {
891
1008
  active: true,
@@ -909,58 +1026,181 @@ The following service methods are available to instantiated clients. The example
909
1026
  ```JS
910
1027
  {
911
1028
  message: 'Tracking settings have been updated',
912
- "unsubscribe": {
913
- "active": true,
914
- "html_footer": "\n<br>\n<p><a href=\"%unsubscribe_url%\">unsubscribe</a></p>\n",
915
- "text_footer": "\n\nTo unsubscribe click: <%unsubscribe_url%>\n\n"
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'
916
1033
  }
917
1034
  }
918
1035
  ```
919
1036
 
920
- - #### getIps
921
- `mg.domains.getIps(domain)`
922
-
923
- Example:
924
-
925
- ```js
926
- mg.domains.getIps('foobar.example.com')
927
- .then(msg => console.log(msg)) // logs response data
928
- .catch(err => console.error(err)); // logs any error
929
- ```
930
-
931
- Promise returns:
932
-
933
- ```JS
934
- ["192.168.0.1", "192.168.0.2"]
935
- ```
1037
+ - #### getConnection
1038
+ Returns domain's delivery connection settings.
936
1039
 
937
- - #### assignIp
938
- `mg.domains.assignIp(domain, ip)`
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)
939
1041
 
940
1042
  Example:
941
1043
 
942
1044
  ```JS
943
- mg.domains.assignIp('foobar.example.com', "192.168.0.3")
944
- .then(msg => console.log(msg)) // logs response data
1045
+ mg.domains.getConnection(domainAddress)
1046
+ .then(data => console.log(data)) // logs response data
945
1047
  .catch(err => console.error(err)); // logs any error
946
1048
  ```
947
1049
 
1050
+ Promise returns:
948
1051
 
949
1052
  ```JS
950
1053
  {
951
- message: 'success',
952
- status: 200,
1054
+ require_tls: false,
1055
+ skip_verification: false
953
1056
  }
954
1057
  ```
955
1058
 
956
- - #### deleteIp
957
- `mg.domains.deleteIp(domain, ip)`
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)
958
1063
 
959
1064
  Example:
960
1065
 
961
1066
  ```JS
962
- mg.domains.deleteIp('foobar.example.com', "192.168.0.3")
963
- .then(msg => console.log(msg)) // logs response data
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
964
1204
  .catch(err => console.error(err)); // logs any error
965
1205
  ```
966
1206
 
@@ -970,6 +1210,440 @@ The following service methods are available to instantiated clients. The example
970
1210
  }
971
1211
  ```
972
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.
1301
+
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)
1303
+
1304
+ Example:
1305
+
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
1319
+ .catch(err => console.error(err)); // logs any error
1320
+ ```
1321
+
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
1336
+
1337
+ ```JS
1338
+ {
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
+ }
1355
+ }
1356
+ ```
1357
+
1358
+ - #### update
1359
+ Update the description of a template.
1360
+
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)
1362
+
1363
+ Example:
1364
+
1365
+ ```js
1366
+ mg.domains.domainTemplates.update('domainId', 'templateName', {
1367
+ description: 'new template description',
1368
+ }).then(data => console.log(data)) // logs data
1369
+ .catch(err => console.error(err)); // logs any error
1370
+ ```
1371
+
1372
+ Data object may have next properties:
1373
+
1374
+ | Property | Description |
1375
+ |:----------|:------------------------------------------------------|
1376
+ | description | Update description of the template being updated. |
1377
+
1378
+ Promise returns:
1379
+ ```JS
1380
+ {
1381
+ status: 200,
1382
+ message: 'template has been updated',
1383
+ templateName: 'template_name'
1384
+ }
1385
+ ```
1386
+
1387
+ - #### destroy
1388
+ Delete the template specified in the url. NOTE: This method deletes all versions of the specified template.
1389
+
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)
1391
+
1392
+ Example:
1393
+
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
+ ```
1399
+
1400
+ Promise returns:
1401
+ ```JS
1402
+ {
1403
+ status: 200,
1404
+ message: 'template has been deleted',
1405
+ templateName: 'template_name'
1406
+ }
1407
+ ```
1408
+
1409
+ - #### destroyAll
1410
+ Delete all templates and their versions for the domain.
1411
+
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)
1413
+
1414
+ Example:
1415
+
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
+ ```
1421
+
1422
+ Promise returns:
1423
+ ```JS
1424
+ {
1425
+ status: 200,
1426
+ message: "templates have been deleted"
1427
+ }
1428
+ ```
1429
+
1430
+ - #### listVersions
1431
+ Returns a paginated list of template versions.
1432
+
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)
1434
+
1435
+ Example:
1436
+
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
+ ```
1444
+
1445
+ Query data object may have next properties:
1446
+
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'|
1451
+
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
+ ```
1475
+
1476
+ - #### getVersion
1477
+
1478
+ Retrieve the information and content of the specified version of a template.
1479
+
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)
1481
+
1482
+ Example:
1483
+
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
+ ```
1489
+
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
+ ```
1517
+
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.
1520
+
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)
1522
+
1523
+ Example:
1524
+
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
1539
+ .catch(err => console.error(err)); // logs any error
1540
+ ```
1541
+
1542
+ Template version data object may have next properties:
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:
1554
+ ```JS
1555
+ {
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
+ }
1576
+ }
1577
+ ```
1578
+
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)
1584
+
1585
+ Example:
1586
+
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
1600
+ .catch(err => console.error(err)); // logs any error
1601
+ ```
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:
1614
+ ```JS
1615
+ {
1616
+ status: 200,
1617
+ message: 'version has been updated',
1618
+ templateName: 'template_name',
1619
+ templateVersion: {
1620
+ tag: 'v1'
1621
+ }
1622
+ }
1623
+ ```
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
+
973
1647
  ### Events
974
1648
 
975
1649
  - #### get