Templates

This API allows you to store predefined templates and use them to send messages using sending API. The API has following limitations:

  • 100 templates per domains
  • 10 versions per template
  • 100Kb max template size

Template API

Store new template

POST /<domain>/templates

This API stores a new template, storing its name, description and, optionally, the template content. If the content is provided a new version is automatically created and becomes the active version.

Parameter Description
name Name of the template being created. The name can contain alpha characters, digits and next symbols: .-_~
description Description of the template being created
template (Optional) Content of the template
tag (Optional) Initial tag of the created version. If template parameter is provided and tag is missing default value initial is used. The tag can contain alpha characters, digits and next symbols: .-_~
engine (Optional) The template engine to use to render the template. Valid only if template parameter is provided. Currently the API supports only one engine: handlebars
comment (Optional) Version comment. Valid only if new version is being created (template parameter is provided)

Example of storing template metadata only:

curl -s --user 'api:YOUR_API_KEY' -X POST \
  https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates \
  -F name='template.name' \
  -F description='template description'
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;

public class MGSample {

     // ...

    public static JsonNode createTemplate() throws UnirestException {

        HttpResponse <JsonNode> request = Unirest.post("https://api.mailgun.net/v3/" + YOUR_DOMAIN_NAME + "/templates")
                       .basicAuth("api", API_KEY)
                       .field("name", "template.name")
           .field("description", "template description")
                       .asJson();

        return request.getBody();
    }
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');
$domain = 'YOUR_DOMAIN_NAME';

# Issue the call to the client.
$result = $mgClient->post("$domain/templates", array(
    'name' => 'template.name',
    'description' => 'template description'
));
def store_template():
    return requests.post(
        "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates",
        auth=("api", "YOUR_API_KEY"),
        data={'name': 'template.name',
              'description': 'template description'})
def store_template
  RestClient.post "https://api:YOUR_API_KEY"\
  "@api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates",
  :name=> 'template.name',
  :description: => 'template description'
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;

public class StoreTemplatesChunk
{

    public static void Main (string[] args)
    {
        Console.WriteLine (StoreTemplate ().Content.ToString ());
    }

    public static IRestResponse StoreTemplate ()
    {
        RestClient client = new RestClient ();
        client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
        client.Authenticator =
            new HttpBasicAuthenticator ("api",
                                        "YOUR_API_KEY");
        RestRequest request = new RestRequest ();
        request.Resource = "{domain}/templates";
        request.AddParameter ("domain", "YOUR_DOMAIN_NAME", ParameterType.UrlSegment);
        request.AddParameter ("name", "template.name");
        request.AddParameter ("description", "template description")
        request.Method = Method.POST;
        return client.Execute (request);
    }

}
func CreateTemplate(domain, apiKey string) error {
    mg := mailgun.NewMailgun(domain, apiKey)

    ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
    defer cancel()

    return mg.CreateTemplate(ctx, &mailgun.Template{
        Name: "template.name",
        Version: mailgun.TemplateVersion{
            Template: `'<div class="entry"> <h1>{{.title}}</h1> <div class="body"> {{.body}} </div> </div>'`,
            Engine:   mailgun.TemplateEngineGo,
            Tag:      "v1",
        },
    })
}
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.post(`/${DOMAIN}/templates`, {"name" : "template.name",
                                      "description": "template description"},
                                      function (error, body) {
                                           console.log(body);
                                      });

Sample response:

{
  "template": {
      "createdAt": "Wed, 29 Aug 2018 23:31:13 UTC",
      "description": "template description",
      "name": "template.name",
  },
  "message": "template has been stored"
}

Example of storing template with a version:

curl -s --user 'api:YOUR_API_KEY' -X POST \
  https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates \
  -F name='template.name' \
  -F description='template description' \
  -F template='{{fname}} {{lname}}' \
  -F engine='handlebars'
  -F comment='version comment'
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;

public class MGSample {

     // ...

    public static JsonNode storeVersion() throws UnirestException {

        HttpResponse <JsonNode> request = Unirest.post("https://api.mailgun.net/v3/" + YOUR_DOMAIN_NAME + "/templates")
                       .basicAuth("api", API_KEY)
                       .field("name", "template.name")
           .field("description", "template description")
           .field("template", "{{fname}} {{lname}}")
           .field("engine", "handlebars")
           .field("commnt", "version comment")
                       .asJson();

        return request.getBody();
    }
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');
$domain = 'YOUR_DOMAIN_NAME';

# Issue the call to the client.
$result = $mgClient->post("$domain/templates", array(
    'name' => 'template.name',
    'description' => 'template description',
    'template' => '{{fname}} {{lname}}',
    'engine' => 'handlebars',
    'comment' => 'version comment'
));
def store_template():
    return requests.post(
        "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates",
        auth=("api", "YOUR_API_KEY"),
        data={'name': 'template.name',
              'description': 'template description',
              'template': '{{fname}} {{lname}}',
              'engine': 'handlebars',
              'comment': 'version comment'})
def store_template
  RestClient.post "https://api:YOUR_API_KEY"\
  "@api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates",
  :name => 'template.name',
  :description => 'template description',
  :template => '{{fname}} {{lname}}',
  :engine => 'handlebars',
  :comment => 'version comment'
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;

public class StoreTemplatesChunk
{

    public static void Main (string[] args)
    {
        Console.WriteLine (StoreTemplate ().Content.ToString ());
    }

    public static IRestResponse StoreTemplate ()
    {
        RestClient client = new RestClient ();
        client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
        client.Authenticator =
            new HttpBasicAuthenticator ("api",
                                        "YOUR_API_KEY");
        RestRequest request = new RestRequest ();
        request.Resource = "{domain}/templates";
        request.AddParameter ("domain", "YOUR_DOMAIN_NAME", ParameterType.UrlSegment);
        request.AddParameter ("name", "template.name");
        request.AddParameter ("description", "template description")
        request.AddParameter ("template", "{{fname}} {{lname}}")
        request.AddParameter ("engine", "handlebars")
        request.AddParameter ("comment", "version comment")
        request.Method = Method.POST;
        return client.Execute (request);
    }

}
func AddTemplateVersion(domain, apiKey string) error {
    mg := mailgun.NewMailgun(domain, apiKey)

    ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
    defer cancel()

    return mg.AddTemplateVersion(ctx, "template.name", &mailgun.TemplateVersion{
        Template: `'<div class="entry"> <h1>{{.title}}</h1> <div class="body"> {{.body}} </div> </div>'`,
        Engine:   mailgun.TemplateEngineGo,
        Tag:      "v2",
        Active:   true,
    })
}
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.post(`/${DOMAIN}/templates`, {"name" : "template.name",
                                      "description": "template description",
                                      "template": "{{fname}} {{lname}}",
                                      "engine": "handlebars"},
                                      function (error, body) {
                                              console.log(body);
                                      });

Sample response:

{
  "template": {
      "createdAt": "Wed, 29 Aug 2018 23:31:13 UTC",
      "description": "template description",
      "name": "template.name",
      "version": {
          "createdAt": "Wed, 29 Aug 2018 23:31:14 UTC",
          "engine": "handlebars",
          "tag": "initial",
          "comment": "version comment"
      }
  },
  "message": "template has been stored"
}

Get template

GET /<domain>/templates/<name>

Returns metadata information about a stored template specified in url. If the active flag is provided the content of active version of the template is returned.

Parameter Description
active (Optional) If this flag is set to yes the active version of the template is included into a response.

Example:

curl -s --user 'api:YOUR_API_KEY' \
  https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;

public class MGSample {

    // ...

    public static JsonNode getTemplate() throws UnirestException {

        HttpResponse <JsonNode> request = Unirest.get("https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME")
            .basicAuth("api", API_KEY)
            .asJson();

        return request.getBody();
    }
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');
$domain = 'YOUR_DOMAIN_NAME';
$name = 'TEMPLATE_NAME';

# Issue the call to the client.
$result = $mgClient->get("$domain/templates/$name");
def get_template():
    return requests.get(
        "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME",
        auth=("api", "YOUR_API_KEY"))
def get_template
  RestClient.
    get("https://api:YOUR_API_KEY"\
        "@api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME"){|response, request, result| response }
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;

public class GetTemplatesChunk
{

    public static void Main (string[] args)
    {
        Console.WriteLine (GetTemplate ().Content.ToString ());
    }

    public static IRestResponse GetTemplate ()
    {
        RestClient client = new RestClient ();
        client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
        client.Authenticator =
            new HttpBasicAuthenticator ("api",
                                        "YOUR_API_KEY");
        RestRequest request = new RestRequest ();
        request.Resource = "/{domain}/templates/{name}";
        request.AddUrlSegment ("domain", "YOUR_DOMAIN_NAME");
        request.AddUrlSegment ("name", "TEMPLATE_NAME");
        return client.Execute (request);
    }

}
func GetTemplate(domain, apiKey string) (mailgun.Template, error) {
    mg := mailgun.NewMailgun(domain, apiKey)

    ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
    defer cancel()

    return mg.GetTemplate(ctx, "my-template")
}
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.get('/domains/${DOMAIN}/templates/TEMPLATE_NAME', function (error, body) {
  console.log(body);
});

Sample response:

{
  "template": {
      "createdAt": "Wed, 29 Aug 2018 23:31:13 UTC",
      "description": "template description",
      "name": "template.name"
  }
}

Example of retrieving active version of a template:

curl -s --user 'api:YOUR_API_KEY' -X GET \
  https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME \
  -F active='yes'
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;

public class MGSample {

    // ...

    public static JsonNode getTemplate() throws UnirestException {

        HttpResponse <JsonNode> request = Unirest.get("https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME")
            .basicAuth("api", API_KEY)
             .queryString("active", "yes")
            .asJson();

        return request.getBody();
    }
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');
$domain = 'YOUR_DOMAIN_NAME';
$name = 'TEMPLATE_NAME';

# Issue the call to the client.
$result = $mgClient->get("$domain/templates/$name", array('active' => 'yes'));
def get_template():
    return requests.get(
        "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME",
        auth=("api", "YOUR_API_KEY"),
        params={"active": "yes"})
def get_template
   RestClient.get "https://api:YOUR_API_KEY"\
   "@api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME", :params => {
       :active => "yes"
   }
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;

public class GetTemplatesChunk
{

    public static void Main (string[] args)
    {
        Console.WriteLine (GetTemplate ().Content.ToString ());
    }

    public static IRestResponse GetTemplate ()
    {
        RestClient client = new RestClient ();
        client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
        client.Authenticator =
            new HttpBasicAuthenticator ("api",
                                        "YOUR_API_KEY");
        RestRequest request = new RestRequest ();
        request.Resource = "/{domain}/templates/{name}";
        request.AddUrlSegment ("domain", "YOUR_DOMAIN_NAME");
        request.AddUrlSegment ("name", "TEMPLATE_NAME");
        request.AddParameter ("active", "yes");
        return client.Execute (request);
    }

}
func ListActiveTemplates(domain, apiKey string) ([]mailgun.Template, error) {
    mg := mailgun.NewMailgun(domain, apiKey)
    it := mg.ListTemplates(&mailgun.ListTemplateOptions{Active: true})

    ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
    defer cancel()

    var page, result []mailgun.Template
    for it.Next(ctx, &page) {
        result = append(result, page...)
    }

    if it.Err() != nil {
        return nil, it.Err()
    }
    return result, nil
}
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.get('/${DOMAIN}/templates/TEMPLATE_NAME', {"active", "yes"}, function (error, body) {
  console.log(body);
});

Sample response:

{
  "template": {
      "createdAt": "Wed, 29 Aug 2018 23:31:13 UTC",
      "description": "template description",
      "name": "template.name",
      "version": {
          "createdAt": "Wed, 29 Aug 2018 23:31:15 UTC",
          "engine": "handlebars",
          "tag": "v0",
          "template": "{{fname}} {{lname}}",
          "comment": "version comment"
      }
  }
}

Update template

PUT /<domain>/templates/<name>

Update metadata information of a template specified in url

Parameter Description
description Updated description of the template

Example:

curl -s --user 'api:YOUR_API_KEY' -X PUT \
    https://api.mailgun.net/v3/domains/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME \
    -F description = 'new template description'
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;

public class MGSample {

    // ...

    public static JsonNode updateTemplate() throws UnirestException {

        HttpResponse <JsonNode> request = Unirest.put("https://api.mailgun.net/v3/" + YOUR_DOMAIN_NAME + "/templates" +TEMPLATE_NAME)
            .basicAuth("api", API_KEY)
            .field("description", "new template description")
            .asJson();

        return request.getBody();
    }
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');
$domain = 'YOUR_DOMAIN_NAME';
$name = 'TEMPLATE_NAME'

# Issue the call to the client.
$result = $mgClient->put("$domain/templates/$name", array(
    'description' => 'new template description'
));
def update_template():
    return requests.put(
        ("https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME"),
        auth=('api', 'YOUR_API_KEY'),
        data={'description': 'new template description'})
def update_template
  RestClient.put("https://api:YOUR_API_KEY" \
                 "@api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME",
                 :description => 'new template description')
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;

public class UpdateTemplateChunk
{

    public static void Main (string[] args)
    {
        Console.WriteLine (UpdateTemplate ().Content.ToString ());
    }

    public static IRestResponse UpdateTemplate ()
    {
        RestClient client = new RestClient ();
        client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
        client.Authenticator =
            new HttpBasicAuthenticator ("api",
                                        "YOUR_API_KEY");
        RestRequest request = new RestRequest ();
        request.Resource = "/YOUR_DOMAIN_NAME/template/TEMPLATE_NAME";
        request.AddParameter ("description", "new template description");
        request.Method = Method.PUT;
        return client.Execute (request);
    }

}
import (
    "context"
    "github.com/mailgun/mailgun-go/v3"
    "time"
)

func UpdateTemplate(domain, apiKey string) error {
    mg := mailgun.NewMailgun(domain, apiKey)

    ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
    defer cancel()

    return mg.UpdateTemplate(ctx, &mailgun.Template{
        Name:        "TEMPLATE_NAME",
        Description: "Add a description to the template",
    })
}
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.put(`/${DOMAIN}/templates/TEMPLATE_NAME`, {"description": "new template descripton"},
                                                  function (error, body) {
                                                       console.log(body);
                                                  });

Sample response:

{
  "message": "template has been updated",
  "template": {
      "createdAt": "Wed, 29 Aug 2018 23:31:15 UTC",
      "description": "new template description",
      "name": "template.name"
  }
}

Delete template

DELETE /<domain>/templates/<name>

Delete a template specified in url. This method deletes all versions of the specified template

Example:

curl -s --user 'api:YOUR_API_KEY' -X DELETE \
    https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;

public class MGSample {

    // ...

    public static JsonNode deleteTemplate() throws UnirestException {

        HttpResponse<JsonNode> request = Unirest.delete("https://api.mailgun.net/v3/"+ YOUR_DOMAIN_NAME +"/templates/TEMPLATE_NAME")
            .basicAuth("api", API_KEY)
            .asJson();

        return request.getBody();
    }
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');
$domain = 'YOUR_DOMAIN_NAME';
$name = 'TEMPLATE_NAME';

# Issue the call to the client.
$result = $mgClient->delete("/$domain/templates/$name");
def delete_template():
    return requests.delete(
        "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME",
        auth=("api", "YOUR_API_KEY"))
def delete_template
  RestClient.delete "https://api:YOUR_API_KEY"\
  "@api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME"
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;

public class DeleteTemplate
{

    public static void Main (string[] args)
    {
        Console.WriteLine (DeleteTemplate ().Content.ToString ());
    }

    public static IRestResponse DeleteTemplate ()
    {
        RestClient client = new RestClient ();
        client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
        client.Authenticator =
            new HttpBasicAuthenticator ("api",
                                        "YOUR_API_KEY");
        RestRequest request = new RestRequest ();
        request.AddParameter ("domain", "YOUR_DOMAIN_NAME", ParameterType.UrlSegment);
        request.Resource = "{domain}/templates/{name}";
        request.AddUrlSegment ("name", "TEMPLATE_NAME");
        request.Method = Method.DELETE;
        return client.Execute (request);
    }

}
func DeleteTemplate(domain, apiKey string) error {
    mg := mailgun.NewMailgun(domain, apiKey)

    ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
    defer cancel()

    return mg.DeleteTemplate(ctx, "TEMPLATE_NAME")
}
var DOMAIN = 'YOUR_DOMAIN_NAME';
var TEMPLATE_ID = 'YOUR_TEMPLATE_ID';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.delete(`/${DOMAIN}/templates/${TEMPLATE_NAME}`, function (error, body) {
  console.log(body);
});

Sample response:

{
  "template": {
      "name": "template.name"
  },
  "message": "template has been deleted"
}

View all templates in domain

GET /<domain>/templates

Returns a list of stored templates for the domain

Parameter Description
page Name of a page to retrive. first, last, next, prev
limit Number of records to retrive. Default value is 10
p Pivot is used to retrieve records in chronological order

Example:

curl -s --user 'api:YOUR_API_KEY' -G \
  https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates \
  -d limit=10
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;

public class MGSample {

    // ...

    public static JsonNode listTemplates() throws UnirestException {

        HttpResponse <JsonNode> request = Unirest.get("https://api.mailgun.net/v3/" + YOUR_DOMAIN_NAME + "/templates")
            .basicAuth("api", API_KEY)
            .queryString("limit","10")
            .asJson();

        return request.getBody();
    }
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');
$domain = 'YOUR_DOMAIN_NAME';

# Issue the call to the client.
$result = $mgClient->get("$domain/templates", array('limit' => 10));
def list_templates():
    return requests.get(
        "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates",
        auth=("api", "YOUR_API_KEY"),
        params={"limit": 10})
def list_templates
  RestClient.get "https://api:YOUR_API_KEY"\
  "@api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates", :params => {
    :limit => 10
  }
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;

public class ListTemplatesChunk
{

    public static void Main (string[] args)
    {
        Console.WriteLine (ListTemplates ().Content.ToString ());
    }

    public static IRestResponse ListTemplates ()
    {
        RestClient client = new RestClient ();
        client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
        client.Authenticator =
            new HttpBasicAuthenticator ("api",
                                        "YOUR_API_KEY");
        RestRequest request = new RestRequest ();
        request.AddParameter ("domain", "YOUR_DOMAIN_NAME", ParameterType.UrlSegment);
        request.AddParameter ("limit", 10);
        request.Resource = "/{domain}/templates";
        return client.Execute (request);
    }

}
import (
    "context"
    "github.com/mailgun/mailgun-go/v3"
    "time"
)

func ListTemplates(domain, apiKey string) ([]mailgun.Template, error) {
    mg := mailgun.NewMailgun(domain, apiKey)
    it := mg.ListTemplates(nil)

    ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
    defer cancel()

    var page, result []mailgun.Template
    for it.Next(ctx, &page) {
        result = append(result, page...)
    }

    if it.Err() != nil {
        return nil, it.Err()
    }
    return result, nil
}
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.get('/${DOMAIN}/templates', {"limit": 5}, function (error, body) {
  console.log(body);
});

Sample response:

{
  "items": [
      {
          "createdAt": "Wed, 29 Aug 2018 23:31:15 UTC",
          "description": "Template description",
          "name": "template.0",
      },
      {
          "createdAt": "Wed, 29 Aug 2018 23:31:18 UTC",
          "description": "Template description",
          "name": "template.1"
      },
      {
          "createdAt": "Wed, 29 Aug 2018 23:31:21 UTC",
          "description": "Template description",
          "name": "template.2"
      }
  ],
  "paging": {
      "first": "https://api.mailgin.net/v3/YOUR_DOMAIN_NAME/templates?limit=10",
      "last": "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates?page=last&limit=10",
      "next": "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates?page=next&p=template.2&limit=10",
      "prev": "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates?page=prev&p=template.0&limit=10"
  }
}

Delete all template in domain

DELETE /<domain>/templates

Delete all stored templates for the domain

Example:

curl -s --user 'api:YOUR_API_KEY' -X DELETE \
    https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;

public class MGSample {

    // ...

    public static JsonNode deleteTemplates() throws UnirestException {

        HttpResponse<JsonNode> request = Unirest.delete("https://api.mailgun.net/v3/"+ YOUR_DOMAIN_NAME +"/templates")
            .basicAuth("api", API_KEY)
            .asJson();

        return request.getBody();
    }
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');
$domain = 'YOUR_DOMAIN_NAME';

# Issue the call to the client.
$result = $mgClient->delete("/$domain/templates");
def delete_templates():
    return requests.delete(
        "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates",
        auth=("api", "YOUR_API_KEY"))
def delete_templates
  RestClient.delete "https://api:YOUR_API_KEY"\
  "@api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates"
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;

public class DeleteTemplatesChunk
{

    public static void Main (string[] args)
    {
        Console.WriteLine (DeleteTemplates ().Content.ToString ());
    }

    public static IRestResponse DeleteTemplates ()
    {
        RestClient client = new RestClient ();
        client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
        client.Authenticator =
            new HttpBasicAuthenticator ("api",
                                        "YOUR_API_KEY");
        RestRequest request = new RestRequest ();
        request.AddParameter ("domain", "YOUR_DOMAIN_NAME", ParameterType.UrlSegment);
        request.Resource = "{domain}/templates";
        request.Method = Method.DELETE;
        return client.Execute (request);
    }

}
// Not implemented
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.delete(`/${DOMAIN}/templates`, function (error, body) {
  console.log(body);
});

Sample response:

{
  "message": "templates have been deleted"
}

Create new version

POST /<domain>/templates/<template>/versions

Create a new version of the template. If the template doesn’t contain any versions yet the first version becomes active

Parameter Description
template Content of the template
tag Tag of the version is being created
engine (Optional) Template engine. Only one engine are supported right now - handlebars.
comment (Optional) The comment of the stored version
active (Optional) If this flag is set to yes this version becomes active

Example:

curl -s --user 'api:YOUR_API_KEY' -X POST \
  https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME/versions \
  -F tag='v0' \
  -F template='{{fname}} {{lname}}' \
  -F engine='handlebars'
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;

public class MGSample {

     // ...

    public static JsonNode storeTemplateVersion() throws UnirestException {

        HttpResponse <JsonNode> request = Unirest.post("https://api.mailgun.net/v3/" + YOUR_DOMAIN_NAME + "/templates/TEMPLATE_NAME/versions")
                       .basicAuth("api", API_KEY)
           .field("tag", "v0")
                       .field("template", "{{fname}} {{lname}}")
           .field("engine", "handlebars")
                       .asJson();

        return request.getBody();
    }
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');
$domain = 'YOUR_DOMAIN_NAME';
$name = 'TEMPLATE_NAME'

# Issue the call to the client.
$result = $mgClient->post("$domain/templates/$name/versions", array(
    'tag' => 'v0',
    'template' => '{{fname}} {{lname}}',
    'engine' => 'handlebars'
));
def store_template_version():
    return requests.post(
        "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME/versions",
        auth=("api", "YOUR_API_KEY"),
        data={'tag': 'v0',
              'template': '{{fname}} {{lname}}',
              'engine': 'handlebars'})
def store_template_version
  RestClient.post "https://api:YOUR_API_KEY"\
  "@api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME/versions",
  :tag => 'v0',
  :template => '{{fname}} {{lname}}',
  :engine => 'handlebars'
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;

public class StoreTemplateVersionChunk
{

    public static void Main (string[] args)
    {
        Console.WriteLine (StoreTemplateVersion ().Content.ToString ());
    }

    public static IRestResponse StoreTemplateVersion ()
    {
        RestClient client = new RestClient ();
        client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
        client.Authenticator =
            new HttpBasicAuthenticator ("api",
                                        "YOUR_API_KEY");
        RestRequest request = new RestRequest ();
        request.Resource = "{domain}/templates/{name}/versions";
        request.AddParameter ("domain", "YOUR_DOMAIN_NAME", ParameterType.UrlSegment);
        request.AddParameter ("name", "TEMPLATE_NAME", ParameterType.UrlSegment);
        request.AddParameter ("tag", "v0");
        request.AddParameter ("template", "{{fname}} {{lname}}");
        request.AddParameter ("engine", "handlebars");
        request.Method = Method.POST;
        return client.Execute (request);
    }

}
import (
    "context"
    "github.com/mailgun/mailgun-go/v3"
    "time"
)

func AddTemplateVersion(domain, apiKey string) error {
    mg := mailgun.NewMailgun(domain, apiKey)

    ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
    defer cancel()

    return mg.AddTemplateVersion(ctx, "TEMPLATE_NAME", &mailgun.TemplateVersion{
        Template: `'<div class="entry"> <h1>{{.title}}</h1> <div class="body"> {{.body}} </div> </div>'`,
        Engine:   mailgun.TemplateEngineGo,
        Tag:      "v2",
        Active:   true,
    })
}
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.post(`/${DOMAIN}/templates/TEMPLATE_NAME/versions`, {"tag": "v0",
                                                             "template" : "{{fname}} {{lname}}",
                                                             "engine": "handlebars"},
                                                               function (error, body) {
                                                                   console.log(body);
                                                               });

Sample response:

{
  "template": {
      "createdAt": "Wed, 29 Aug 2018 23:31:11 UTC",
      "description": "template description",
      "name": "template.name",
      "version": {
          "createdAt": "Wed, 29 Aug 2018 23:31:21 UTC",
          "engine": "handlebars",
          "tag": "v1.0.0",
          "comment": "version comment"
      }
  },
  "message": "new version of the template has been stored"
}

Get version

GET /<domain>/templates/<name>/versions/<tag>

Retrieve information and content of specifed version of the template

Example:

curl -s --user 'api:YOUR_API_KEY' -G \
  https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME/versions/VERSION_TAG
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;

public class MGSample {

    // ...

    public static JsonNode getTemplateVersion() throws UnirestException {

        HttpResponse <JsonNode> request = Unirest.get("https://api.mailgun.net/v3/" + YOUR_DOMAIN_NAME + "/templates/TEMPLATE_NAME/versions/VERSION_TAG")
            .basicAuth("api", API_KEY)
            .asJson();

        return request.getBody();
    }
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');
$domain = 'YOUR_DOMAIN_NAME';
$name = 'TEMPLATE_NAME'
$tag  = 'VERSION_TAG'

# Issue the call to the client.
$result = $mgClient->get("$domain/templates/$name/versions/$tag");
def get_template_version():
    return requests.get(
        "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME/versions/VERSION_TAG",
        auth=("api", "YOUR_API_KEY"))
def get_template_version
  RestClient.get "https://api:YOUR_API_KEY"\
  "@api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME/versions/VERSION_TAG"
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;

public class GetTemplateVersionChunk
{

    public static void Main (string[] args)
    {
        Console.WriteLine (GetTemplateVersion ().Content.ToString ());
    }

    public static IRestResponse GetTemplateVersion ()
    {
        RestClient client = new RestClient ();
        client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
        client.Authenticator =
            new HttpBasicAuthenticator ("api",
                                        "YOUR_API_KEY");
        RestRequest request = new RestRequest ();
        request.Resource = "/{domain}/templates/{name}/versions/{tag}";
        request.AddParameter ("domain", "YOUR_DOMAIN_NAME", ParameterType.UrlSegment);
        request.AddParameter ("name", "TEMPLATE_NAME", ParameterType.UrlSegment);
        request.AddParameter ("tag", "VERSION_TAG", ParameterType.UrlSegment);

        return client.Execute (request);
    }

}
import (
    "context"
    "github.com/mailgun/mailgun-go/v3"
    "time"
)

func GetTemplateVersion(domain, apiKey string) (mailgun.TemplateVersion, error) {
    mg := mailgun.NewMailgun(domain, apiKey)

    ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
    defer cancel()

    // Get the template version tagged as 'VERSION_TAG'
    return mg.GetTemplateVersion(ctx, "TEMPLATE_NAME", "VERSION_TAG")
}
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.get('/${DOMAIN}/templates/TEMPLATE_NAME/versions/VERSION_TAG', function (error, body) {
  console.log(body);
});

Sample response:

{
  "template": {
      "createdAt": "Wed, 29 Aug 2018 23:31:11 UTC",
      "description": "template description",
      "name": "template.name",
      "version": {
          "createdAt": "Wed, 29 Aug 2018 23:31:21 UTC",
          "engine": "handlebars",
          "tag": "v1.1.0",
          "comment": "version comment",
          "template": "{{fname}} {{lname}}"
      }
  }
}

Update version

PUT /<domain>/templates/<name>/versions/<tag>

Update information or content of the specific version of the template

Parameter Description
template (Optional) The new content of the version
comment (Optional) New comment for the provided version
active (Optional) If this flag is set to yes this version becomes active

Example:

curl -s --user 'api:YOUR_API_KEY' -X PUT \
  https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME/versions/VERSION_TAG \
  -F template='{{fname}} {{lname}}' \
  -F comment='Updated version comment' \
  -F active='yes'
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;

public class MGSample {

     // ...

    public static JsonNode UpdateVersion() throws UnirestException {

        HttpResponse <JsonNode> request = Unirest.put("https://api.mailgun.net/v3/" + YOUR_DOMAIN_NAME + "/templates/TEMPLATE_NAME/versions/VERSION_TAG")
                       .basicAuth("api", API_KEY)
                       .field("template", "{{fname}} {{lname}}")
           .field("comment", "Updated version comment")
           .field("active", "yes")
                       .asJson();

        return request.getBody();
    }
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');
$domain = 'YOUR_DOMAIN_NAME';
$name = 'TEMPLATE_NAME'
$tag = 'VERSION_TAG'

# Issue the call to the client.
$result = $mgClient->put("$domain/templates/$name/versions/$tag", array(
    'template' => '{{fname}} {{lname}}',
    'comment' => 'Updated version comment',
    'active' => 'yes'
));
def update_version():
    return requests.put(
        "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME/versions/VERSION_TAG",
        auth=("api", "YOUR_API_KEY"),
        data={'template': '{{fname}} {{lname}}',
              'comment': 'Updated version comment',
              'active': 'yes'})
def update_version:
  RestClient.put "https://api:YOUR_API_KEY"\
  "@api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME/versions/VERSION_TAG",
  :template => '{{fname}} {{lname}}',
  :comment => 'Updated version comment',
  :active => 'yes'
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;

public class UpdateVersionChunk
{

    public static void Main (string[] args)
    {
        Console.WriteLine (UpdateVersion ().Content.ToString ());
    }

    public static IRestResponse UpdateVersion ()
    {
        RestClient client = new RestClient ();
        client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
        client.Authenticator =
            new HttpBasicAuthenticator ("api",
                                        "YOUR_API_KEY");
        RestRequest request = new RestRequest ();
        request.Resource = "{domain}/templates/{name}/versions/{tag}";
        request.AddParameter ("domain", "YOUR_DOMAIN_NAME", ParameterType.UrlSegment);
        request.AddParameter ("name", "TEMPLATE_NAME", ParameterType.UrlSegment);
        request.AddParameter ("tag", "VERSION_TAG", ParameterType.UrlSegment);
        request.AddParameter ("template", "{{fname}} {{lname}}");
        request.AddParameter ("comment", "Updated version comment");
        request.AddParameter ("active", "yes");
        request.Method = Method.PUT;
        return client.Execute (request);
    }

}
import (
    "context"
    "github.com/mailgun/mailgun-go/v3"
    "time"
)

func UpdateTemplateVersion(domain, apiKey string) error {
    mg := mailgun.NewMailgun(domain, apiKey)

    ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
    defer cancel()

    return mg.UpdateTemplateVersion(ctx, "TEMPLATE_NAME", &mailgun.TemplateVersion{
        Comment: "Add a comment to the template and make it 'active'",
        Tag:     "VERSION_TAG",
        Active:  true,
    })
}
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.put(`/${DOMAIN}/templates/TEMPLATE_NAME/versions/VERSION_TAG`,
            {"template" : "{{fname}} {{lname}}",
             "comment": "Updated version comment",
             "active": "yes"},
             function (error, body) {
                 console.log(body);
             });

Sample response:

{
  "template": {
      "name": "template.name",
      "version": {
        "tag": "v1.2.0"
      }
   "message": "version has been udpated"
}

Delete version

DELETE /<domain>/templates/<template>/versions/<version>

Delete a specific version of the template

Example:

curl -s --user 'api:YOUR_API_KEY' -X DELETE -G \
   https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME/versions/VERSION_TAG
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;

public class MGSample {

    // ...

    public static JsonNode deleteTemplateVersion() throws UnirestException {

        HttpResponse <JsonNode> request = Unirest.delete (
                               "https://api.mailgun.net/v3/" + YOUR_DOMAIN_NAME + "/templates/TEMPLATE_NAME/versions/VERSION_TAG")
            .basicAuth("api", API_KEY)
            .asJson();

        return request.getBody();
    }
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');
$domain = 'YOUR_DOMAIN_NAME';
$name = 'TEMPLATE_NAME'
$tag = 'VERSION_TAG'

# Issue the call to the client.
$result = $mgClient->delete("$domain/templates/$name/versions/$tag");
def delete_template_version():
    return requests.delete(
        "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME/versions/VERSION_TAG",
        auth=("api", "YOUR_API_KEY"))
def delete_template_version
  RestClient.get "https://api:YOUR_API_KEY"\
  "@api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME/versions/VERSION_TAG"

end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;

public class DeleteTemplateVersionChunk
{

    public static void Main (string[] args)
    {
        Console.WriteLine (DeleteTemplateVersion ().Content.ToString ());
    }

    public static IRestResponse DeleteTemplateVersion ()
    {
        RestClient client = new RestClient ();
        client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
        client.Authenticator =
            new HttpBasicAuthenticator ("api",
                                        "YOUR_API_KEY");
        RestRequest request = new RestRequest ();

        request.Resource = "/{domain}/templates/{name}/versions/{tag}";
        request.AddParameter ("domain", "YOUR_DOMAIN_NAME", ParameterType.UrlSegment);
        request.AddParameter ("name", "TEMPLATE_NAME", ParameterType.UrlSegment);
        request.AddParameter ("tag", "VERSION_TAG", ParameterType.UrlSegment);

        request.Method = Method.DELETE
        return client.Execute (request);
    }

}
import (
    "context"
    "github.com/mailgun/mailgun-go/v3"
    "time"
)

func DeleteTemplateVersion(domain, apiKey string) error {
    mg := mailgun.NewMailgun(domain, apiKey)

    ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
    defer cancel()

    // Delete the template version tagged as 'VERSION_TAG'
    return mg.DeleteTemplateVersion(ctx, "TEMPLATE_NAME", "VERSION_TAG")
}
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.delete('/${DOMAIN}/templates/TEMPLATE_NAME/versions/VERSION_TAG', function (error, body) {
  console.log(body);
});

Sample response:

{
  "template": {
      "name": "template.name",
      "version": {
        "tag": "v1.3.0"
      }
   "message": "version has been deleted"
}

View all versions in template

GET /<domain>/templates/<template>/versions

Returns a list of stored versions of the template

Parameter Description
page Name of a page to retrive. first, last, next, prev
limit Number of records to retrive. Default value is 10
p Pivot is used to retrieve records in chronological order

Example:

curl -s --user 'api:YOUR_API_KEY' -G \
  https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME/versions
  -d limit=10
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;

public class MGSample {

    // ...

    public static JsonNode listTemplateVersions() throws UnirestException {

        HttpResponse <JsonNode> request = Unirest.get("https://api.mailgun.net/v3/" + YOUR_DOMAIN_NAME + "/templates/TEMPLATE_NAME/versions")
            .basicAuth("api", API_KEY)
            .asJson();

        return request.getBody();
    }
}
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('YOUR_API_KEY');
$domain = 'YOUR_DOMAIN_NAME';
$name = 'TEMPLATE_NAME'

# Issue the call to the client.
$result = $mgClient->get("$domain/templates/$name/versions");
def list_template_versions():
    return requests.get(
        "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME/versions",
        auth=("api", "YOUR_API_KEY"))
def list_template_version
  RestClient.get "https://api:YOUR_API_KEY"\
  "@api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/TEMPLATE_NAME/versions"
end
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;

public class ListTemplateVersionsChunk
{

    public static void Main (string[] args)
    {
        Console.WriteLine (ListTemplateVersions ().Content.ToString ());
    }

    public static IRestResponse GetTemplateVersion ()
    {
        RestClient client = new RestClient ();
        client.BaseUrl = new Uri ("https://api.mailgun.net/v3");
        client.Authenticator =
            new HttpBasicAuthenticator ("api",
                                        "YOUR_API_KEY");
        RestRequest request = new RestRequest ();
        request.AddParameter ("domain", "YOUR_DOMAIN_NAME", ParameterType.UrlSegment);
        request.AddParameter ("name", "TEMPLATE_NAME", ParameterType.UrlSegment);
        request.Resource = "/{domain}/templates/{name}/versions";
        return client.Execute (request);
    }

}
import (
    "context"
    "github.com/mailgun/mailgun-go/v3"
    "time"
)

func ListTemplateVersions(domain, apiKey string) ([]mailgun.TemplateVersion, error) {
    mg := mailgun.NewMailgun(domain, apiKey)
    it := mg.ListTemplateVersions("TEMPLATE_NAME", nil)

    ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
    defer cancel()

    var page, result []mailgun.TemplateVersion
    for it.Next(ctx, &page) {
        result = append(result, page...)
    }

    if it.Err() != nil {
        return nil, it.Err()
    }
    return result, nil
}
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({ apiKey: "YOUR_API_KEY", domain: DOMAIN });

mailgun.get('/${DOMAIN}/templates/TEMPLATE_NAME/versions', function (error, body) {
  console.log(body);
});

Sample response:

{
  "template": {
      "createdAt": "Wed, 29 Aug 2018 23:31:11 UTC",
      "description": "Template description",
      "name": "template.name",
      "versions": [
          {
              "createdAt": "Wed, 29 Aug 2018 23:31:21 UTC",
              "engine": "handlebars",
              "tag": "v0",
              "comment": "Version comment"
          },
          {
              "createdAt": "Wed, 29 Aug 2018 23:31:31 UTC",
              "engine": "handlebars",
              "tag": "v1",
              "comment": "Version comment"
          },
          {
              "createdAt": "Wed, 29 Aug 2018 23:31:41 UTC",
              "engine": "handlebars",
              "tag": "v2",
              "comment": "Version comment"
          }
      ]
  },
  "paging": {
      "first": "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/z4ujt7CiEeik0RJbspqxaQ/versions?limit=10",
      "last": "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/z4ujt7CiEeik0RJbspqxaQ/versions?page=last&limit=10",
      "next": "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/z4ujt7CiEeik0RJbspqxaQ/versions?page=next&p=v2&limit=10",
      "prev": "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/templates/z4ujt7CiEeik0RJbspqxaQ/versions?page=prev&p=v0&limit=10"
  }
}