Email Templates
Purpose
To fetch the email templates in a module.
Request Details
Request URL
All - {api-domain}/crm/{version}/settings/email_templates
Specific - {api-domain}/crm/{version}/settings/email_templates/{id}
Header
Authorization: Zoho-oauthtoken <access_token>
Scope
scope=ZohoCRM.templates.email.READ
Parameters
- modulestring
The API name of the module you want to fetch email template from. Supported modules are:
Leads, Accounts, Contacts, Deals, Tasks, Events, Calls, Products, Price Books, Quotes, Sales Orders, Purchase Orders, Invoices, Campaigns, Vendors, Cases, Solutions, and Custom.
The content key contains the HTML of the email template and is rendered in the response only when you fetch a specific email template.
Sample Request
Copiedcurl "https://www.zohoapis.com/crm/v2.1/settings/email_templates"
-X GET
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
Copied<?php
class GetEmailTemplates{
public function execute(){
$curl_pointer = curl_init();
$curl_options = array();
$url = "https://www.zohoapis.com/crm/v2.1/settings/email_templates?";
$parameters = array();
$parameters['module'] ='Leads';
foreach ($parameters as $key=>$value){
$url =$url.$key."=".$value."&";
}
$curl_options[CURLOPT_URL] = $url;
$curl_options[CURLOPT_RETURNTRANSFER] = true;
$curl_options[CURLOPT_HEADER] = 1;
$curl_options[CURLOPT_CUSTOMREQUEST] = "GET";
$headersArray = array();
$headersArray[] = "Authorization". ":" . "Zoho-oauthtoken " ."1000.30f3a589XXXXXXXXXXXXXXXXXXX4077.dc5XXXXXXXXXXXXXXXXXXXee9e7c171c";
$curl_options[CURLOPT_HTTPHEADER]=$headersArray;
curl_setopt_array($curl_pointer, $curl_options);
$result = curl_exec($curl_pointer);
$responseInfo = curl_getinfo($curl_pointer);
curl_close($curl_pointer);
list ($headers, $content) = explode("\r\n\r\n", $result, 2);
if(strpos($headers," 100 Continue")!==false){
list( $headers, $content) = explode( "\r\n\r\n", $content , 2);
}
$headerArray = (explode("\r\n", $headers, 50));
$headerMap = array();
foreach ($headerArray as $key) {
if (strpos($key, ":") != false) {
$firstHalf = substr($key, 0, strpos($key, ":"));
$secondHalf = substr($key, strpos($key, ":") + 1);
$headerMap[$firstHalf] = trim($secondHalf);
}
}
$jsonResponse = json_decode($content, true);
if ($jsonResponse == null && $responseInfo['http_code'] != 204) {
list ($headers, $content) = explode("\r\n\r\n", $content, 2);
$jsonResponse = json_decode($content, true);
}
var_dump($headerMap);
var_dump($jsonResponse);
var_dump($responseInfo['http_code']);
}
}
(new GetEmailTemplates())->execute();
Response JSON Keys
- created_timestring
Represents the date and time at which the email template was created.
- attachmentsJSON array
Represents the attachments added in the template.
- subjectstring
Represents the subject of the email template.
- moduleJSON object
Represents the module with which the template is associated with.
- categorystring
Represents the type of the template. The possible values are custom_templates: the templates created by a user, system_templates: the templates present in the system by default, plugin_templates: the templates that are created and installed from the Zoho CRM extension, marketplace_templates: the templates that are created and installed from the published plugins.
- created_byJSON object
Represents the name and ID of the user who created the email template.
- layoutJSON object
Represents the layout the template is associated with.
- modified_timestring
Represents the date and time at which the email template was last modified.
- folderJSON object
Represents the name and unique ID of the template folder.
- last_usage_timestring
Represents the date and time at which the email template was last used.
- associatedboolean
Represents whether the template is associated or not.
- namestring
Represents the name of the email template.
- consent_linkedboolean
Represents whether the consent form is linked with the template.
- modified_byJSON object
Represents the name and ID of the user who last modified the email template.
- idstring
Represents the unique ID of the email template.
- editor_modestring
Represents the mode in which the email template is created. The possible values are gallery: the template is chosen from the template gallery and is customized, rich_text: a pre-designed custom template, plain_text: the template is built from scratch.
- favoriteboolean
Represents if the email template is marked as favorite.
Possible Errors
- BAD_REQUESTHTTP 400
The request method specified is invalid.
Resolution: Specify the request method as GET. - OAUTH_SCOPE_MISMATCHHTTP 401
The token does not have the scope ZohoCRM.templates.email.READ.
Resolution: Create a token with the scope ZohoCRM.templates.email.READ. - NO_PERMISSIONHTTP 403
You do not have the permission to read the email templates.
Resolution: Contact your administrator. - INVALID_URL_PATTERNHTTP 404
The request URL has syntactical errors.
Resolution: Correct the syntactical errors in the request URL.
Sample Response
Copied{
"email_templates": [
{
"created_time": "2022-03-23T18:52:17+05:30",
"attachments": null,
"subject": "Holidays",
"module": {
"api_name": "Leads",
"id": "4876876000000002175"
},
"type": "custom_templates",
"created_by": {
"name": "Patricia Boyle",
"id": "4876876000000327001"
},
"layout": {
"id": ""
},
"modified_time": "2022-03-23T18:52:17+05:30",
"folder": {
"name": "Holidays",
"id": "4876876000000888001"
},
"last_usage_time": null,
"associated": false,
"name": "HappyHolidays",
"consent_linked": false,
"modified_by": {
"name": "Patricia Boyle",
"id": "4876876000000327001"
},
"id": "4876876000000888006",
"editor_mode": "gallery",
"favorite": false
},
{
"created_time": "2021-08-09T09:52:11+05:30",
"attachments": null,
"subject": "Big Deal Alert",
"module": {
"api_name": "Deals",
"id": "4876876000000002181"
},
"type": "system_templates",
"created_by": {
"name": "Patricia Boyle",
"id": "4876876000000327001"
},
"layout": {
"id": ""
},
"modified_time": "2021-08-09T09:52:11+05:30",
"folder": {
"name": "Public Email Templates",
"id": "4876876000000000077"
},
"last_usage_time": null,
"associated": true,
"name": "Big Deal Alert",
"consent_linked": false,
"modified_by": {
"name": "Patricia Boyle",
"id": "4876876000000327001"
},
"id": "4876876000000000079",
"editor_mode": "gallery",
"favorite": false
}
],
"info": {
"per_page": 200,
"count": 2,
"page": 1,
"more_records": false
}
}