Email Templates
- Topics:
- REST API
CREATED FOR:
- Admin
Email Template Endpoint Reference
Email templates form the basis for each new email in Marketo. While emails can be unlinked from templates through HTML replacement, emails must be created initially with a template as the basis. Templates are created as pure HTML documents in Marketo with metadata such as names and descriptions. There are few restrictions on content, but the HTML of the template must be valid, and must contain at least one editable section, which follows the requirements outlined here.
Query
Querying email templates follows the standard pattern for assets, allowing for queries by id, by name and browsing a given folder.
By Id
GET /rest/asset/v1/emailTemplate/{id}.json
{
"success": true,
"warnings": [ ],
"errors": [ ],
"requestId": "14f9e#14a12955df1",
"result": [
{
"id": 19,
"name": "aFgSxuZrBI",
"description": "fUMhVfIyVkhHzRolYzjGyWouTMfjXCPIAZxHMAEmszAjguVKDtbznEeqbqiDuNBzQoHwBJFdXiMzYiMlGUwtuklUhjGfJlDbhaTL",
"createdAt": "2014-11-14T02:41:26Z+0000",
"updatedAt": "2014-11-14T02:41:26Z+0000",
"folder": {
"type": "Folder",
"value": 15
},
"status": "Draft",
"workspace": "Default"
}
]
}
By Name
GET /rest/asset/v1/emailTemplate/byName.json?name=Test Template
{
"success": true,
"warnings": [ ],
"errors": [ ],
"requestId": "14f9e#14a12955df1",
"result": [
{
"id": 19,
"name": "aFgSxuZrBI",
"description": "fUMhVfIyVkhHzRolYzjGyWouTMfjXCPIAZxHMAEmszAjguVKDtbznEeqbqiDuNBzQoHwBJFdXiMzYiMlGUwtuklUhjGfJlDbhaTL",
"createdAt": "2014-11-14T02:41:26Z+0000",
"updatedAt": "2014-11-14T02:41:26Z+0000",
"folder": {
"type": "Folder",
"value": 15
},
"status": "Draft",
"workspace": "Default"
}
]
}
Browse
GET /rest/asset/v1/emailTemplates.json
{
"success":true,
"warnings":[ ],
"errors":[ ],
"requestId":"33c4#14a1832b4a8",
"result":[
{
"id":18,
"name":"AAA0unit3CreateTestEmailTemplateName.2314673e-7bc2-47da-a1e8-66dfdd8a1f1d",
"description":"AssetAPI: getTemplates test",
"createdAt":"2014-11-03T19:52:58Z+0000",
"updatedAt":"2014-11-03T19:52:58Z+0000",
"folder":{
"type":"Folder",
"value":15
},
"status":"Draft",
"workspace":"Default"
},
{
"id":177,
"name":"ABfRGutnwN",
"description":"HMmHkdTRrGaRpPakdgGKICxfMunCEWDUWiThgAbInfaBXxGxSFfjKQIwerngCHRlGTnAJhKPmwlXLcsjGPtWEiILGyeIJTNVHoHg",
"createdAt":"2014-11-20T19:31:06Z+0000",
"updatedAt":"2014-11-20T19:31:06Z+0000",
"folder":{
"type":"Folder",
"value":15
},
"status":"Draft",
"workspace":"Default"
},
{
"id":148,
"name":"ADVHJBQLyw",
"description":null,
"createdAt":"2014-11-20T06:42:57Z+0000",
"updatedAt":"2014-11-20T06:42:57Z+0000",
"folder":{
"type":"Folder",
"value":15
},
"status":"Draft",
"workspace":"Default"
},
{
"id":201,
"name":"AIpwuwiaqb",
"description":null,
"createdAt":"2014-11-25T20:49:06Z+0000",
"updatedAt":"2014-11-25T20:49:06Z+0000",
"folder":{
"type":"Folder",
"value":15
},
"status":"Draft",
"workspace":"Default"
},
{
"id":240,
"name":"aqZGoAskEF",
"description":"uOMEhLpXOEWkwdZxkpcdDjTjKfokxuHEYHPVIVsADFIUEUobzIEaDiqFFxezwfovGfwjuPTJRxUmuHmGpyIklJdDdVosPJdyOVom",
"createdAt":"2014-11-26T21:11:56Z+0000",
"updatedAt":"2014-11-26T21:11:56Z+0000",
"folder":{
"type":"Folder",
"value":15
},
"status":"Draft",
"workspace":"Default"
},
{
"id":199,
"name":"BAxnkVfLGi",
"description":"TzUMQKzKXdgukNCCcaiJHUWASceqlZswhCqDQFDFZULqzYkEiyKcwtQRzKERynReqtMHOhqjnhExCsZopyfzglmXAOjEJdxNURCX",
"createdAt":"2014-11-25T20:49:06Z+0000",
"updatedAt":"2014-11-25T20:49:06Z+0000",
"folder":{
"type":"Folder",
"value":15
},
"status":"Draft",
"workspace":"Default"
},
{
"id":278,
"name":"bcBNCUIHrL",
"description":"UJEPYBRGTSYosZRnMnahMyVtdyxjRpzJMSXyncATKwcLlDAqDnSCFezGVsDZFpZwPzQvBlvaOZzOzBIsIAtqIerZhJFfpqMogoiB",
"createdAt":"2014-11-30T11:30:07Z+0000",
"updatedAt":"2014-11-30T11:30:07Z+0000",
"folder":{
"type":"Folder",
"value":15
},
"status":"Draft",
"workspace":"Default"
}
]
}
Querying the record itself will return just metadata about the record. To get content, refer to the #content section.
Create and Update
Creating or updating a template is fairly straightforward. The content of each template is stored as an HTML document and must be passed into Marketo using a multipart/form-data type of POST. You must pass the appropriate Content-Type header that includes a boundary as described in the RFCs for multipart and multipart/form-data.
Creating a template requires you to include three parameters: name, folder, content. An optional description parameter may be included. The HTML document is passed in the content parameter, which must also include the conventional filename parameter as part of its Content-Disposition header.
POST /rest/asset/v1/emailTemplates.json
Content-Type: multipart/form-data; boundary=mktoBoundary1480963323998
--mktoBoundary1480963323998
Content-Disposition: form-data; name="name"
Sample Email Template
--mktoBoundary1480963323998
Content-Disposition: form-data; name="folder"
{"id":15,"type":"Folder"}
--mktoBoundary1480963323998
Content-Disposition: form-data; name="content"; filename="testHTML.html"
Content-Type: text/html
<html>
<body>
<h1>TEST HTML</h1>
</body>
</html>
--mktoBoundary1480963323998
Content-Disposition: form-data; name="description"
Create email template using API
--mktoBoundary1480963323998--
{
"success": true,
"warnings": [ ],
"errors": [ ],
"requestId": "a99f#14e22b2b85e",
"result": [
{
"id": 1022,
"name": "Sample Email Template",
"description": "Create email template using API",
"createdAt": "2015-06-23T23:13:34Z+0000",
"updatedAt": "2015-06-23T23:13:34Z+0000",
"url": "https://app-abm.marketo.com/#ET1022B2ZN12",
"folder": {
"type": "Folder",
"value": 15,
"folderName": "Templates"
},
"status": "draft",
"workspace": "Default",
"version": 1
}
]
}
Updating content is done using a separate endpoint which requires the id of the Email template. This endpoint only allows the submission of the content parameter in the body. When an update is made, whatever is passed in the content parameter will completely replace the existing content of the email in a new draft if updating an approved version, or replace the current draft if the asset is in a draft-only state.
POST /rest/asset/v1/emailTemplate/{id}/content.json
Content-Type: multipart/form-data; boundary=mktoBoundaryEiJFFFPFKK2WovsT
--mktoBoundaryEiJFFFPFKK2WovsT
Content-Disposition: form-data; name="content"; filename="testHTML2.html"
Content-Type: text/html
<html>
<body>
<h1>TEST HTML WITH UPDATE</h1>
<div class="mktEditable"></div>
</body>
</html>
--mktoBoundaryEiJFFFPFKK2WovsT--
{
"success": true,
"warnings": [ ],
"errors": [ ],
"requestId": "f8e2#158d0ae24f8",
"result":[
{
"id":1022,
"status":"Draft",
"content":"<html>\n<body>\n<h1>TEST HTML WITH UPDATE</h1>\n<div class="mktEditable"></div>\n</body>\n</html>"
}
]
}
Update Metadata
To update a template’s metadata, name and description, you can use the same endpoint as to update content, but pass an application/x-www-url-formencoded POST instead, with the name and description parameters.
POST /rest/asset/v1/emailTemplate/{id}.json
Content-Type: application/x-www-form-urlencoded
description=Updated description&name=New Name
{
"success": true,
"warnings": [ ],
"errors": [ ],
"requestId": "17ca5#14a12ab900a",
"result": [
{
"id": 19,
"name": "New Name",
"description": "Updated description",
"createdAt": "2014-11-14T02:41:26Z+0000",
"updatedAt": "2014-11-14T02:41:26Z+0000",
"folder": {
"type": "Folder",
"value": 15
},
"status": "Draft",
"workspace": "Default"
}
]
}
Approval
Email templates follow the standard pattern for approvals of asset records. You can approve a draft, unapprove an approved version, and discard an existing draft of an email template through each of their own endpoints.
Approve
When calling the approval endpoint, the email will be validated against the rules for Marketo emails. The from name, from email, reply to email, and subject have to be populated before the email can be approved.
POST /rest/asset/v1/emailTemplate/{id}/approveDraft.json
{
"success":true,
"warnings":[ ],
"errors":[ ],
"requestId":"abe2#14a1832a97d",
"result":[
{
"id":338,
"name":"lvAVYMZqPS",
"description":"fZLJQSJRvnYbjGTUpIHHqDOuQgQzXQcWIXoOUPwrVLdMHKcbRqwLoSLkWZTUmaMiCIJSfQiufnnrgITUIqjuAPBLpmliiKuIUFYG",
"createdAt":"2014-12-05T02:06:21Z+0000",
"updatedAt":"2014-12-05T02:06:21Z+0000",
"folder":{
"type":"Folder",
"value":15
},
"status":"Approved",
"workspace":"Default"
}
]
}
Unapprove
The unapprove endpoint can only be used on approved templates.
POST /rest/asset/v1/emailTemplate/{id}/unapprove.json
{
"success":true,
"warnings":[ ],
"errors":[ ],
"requestId":"17bfa#14a1832b3c4",
"result":[
{
"id":344,
"name":"LkilkvKrkp",
"description":"yAyUEXuWMtdhpODUmnCkGjpBcyEKnYucxaSoTyYeQzyNbYanxCXWPOzwiIWmeXPUwjfGAUmgnxlhgOPluVqwNittuvxJmNTaHxYM",
"createdAt":"2014-12-05T02:06:23Z+0000",
"updatedAt":"2014-12-05T02:06:23Z+0000",
"folder":{
"type":"Folder",
"value":15
},
"status":"Draft",
"workspace":"Default"
}
]
}
Discard
The draft version of the template is created after an approved email is updated.
POST /rest/asset/v1/emailTemplate/{id}/discardDraft.json
{
"success":true,
"warnings":[ ],
"errors":[ ],
"requestId":"17bfa#14a1832b3c4",
"result":[
{
"id":344,
"name":"LkilkvKrkp",
"description":"yAyUEXuWMtdhpODUmnCkGjpBcyEKnYucxaSoTyYeQzyNbYanxCXWPOzwiIWmeXPUwjfGAUmgnxlhgOPluVqwNittuvxJmNTaHxYM",
"createdAt":"2014-12-05T02:06:23Z+0000",
"updatedAt":"2014-12-05T02:06:23Z+0000",
"folder":{
"type":"Folder",
"value":15
},
"status":"Draft",
"workspace":"Default"
}
]
}
Delete
POST /rest/asset/v1/emailTemplate/{id}/delete.json
{
"success":true,
"warnings":[ ],
"errors":[ ],
"requestId":"15cef#149d3de83db",
"result":[
{
"id":12
}
]
}
Clone
Marketo provides a simple method for cloning an Email Template. Unlike creating, this type of request is made with an application/x-www-url-formencoded POST, and takes two required parameters, name, and folder, an embedded JSON object with id and type. Description is also an optional parameter.
POST /rest/asset/v1/emailTemplate/{id}/clone.json
Content-Type: application/x-www-form-urlencoded
name=Sample Template 01 - deverly&folder={"id":12,"type":"Folder"}&description=This is a sample template
{
"success": true,
"warnings": [],
"errors": [],
"requestId": "905e#14e22c693f8",
"result": [
{
"id": 1024,
"name": "Sample Template 01 - deverly",
"description": "This is a sample template",
"createdAt": "2015-06-23T23:35:16Z+0000",
"updatedAt": "2015-06-23T23:35:16Z+0000",
"url": "https://app-abm.marketo.com/#ET1024B2ZN12",
"folder": {
"type": "Folder",
"value": 12,
"folderName": "Templates"
},
"status": "draft",
"workspace": "Default"
}
]
}
Query Email Dependencies
Use the Get Email Template Used By endpoint to retrieve a list of emails that depend on a given email template. The id
path parameter specifies the parent email template.
There are 2 optional parameters. maxReturn
is a integer that limits the number of results (default is 20, maximum is 200), and offset
is an integer that can be used with maxReturn
to read through large result sets (default is 0).
GET /rest/asset/v1/emailTemplates/{id}/usedBy.json
{
"success": true,
"errors": [],
"requestId": "18b0#16fa3344169",
"warnings": [],
"result": [
{
"id": 1022,
"name": "EmailPr.Email2",
"type": "Email",
"status": "approved",
"updatedAt": "2019-12-02T00:42:21Z+0000"
},
{
"id": 1023,
"name": "Default.Email1.email1",
"type": "Email",
"status": "approved",
"updatedAt": "2019-12-02T00:42:21Z+0000"
},
{
"id": 1025,
"name": "Defa.E1",
"type": "Email",
"status": "draft",
"updatedAt": "2019-12-02T00:42:21Z+0000"
},
{
"id": 1052,
"name": "Email v1 Program.Email v1 Email",
"type": "Email",
"status": "draft",
"updatedAt": "2019-06-07T20:07:16Z+0000"
}
]
}