Scala SDK Samples - Email Templates Operations
Get Email Templates
package com.zoho.crm.sample.emailtemplates
import java.util
import com.zoho.crm.api.emailtemplates.EmailTemplatesOperations
import com.zoho.crm.api.emailtemplates.EmailTemplatesOperations.GetEmailTemplatesParam
import com.zoho.crm.api.emailtemplates.ResponseWrapper
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.emailtemplates.APIException
object EmailTemplates {
/*
* Get EmailTemplates - This method is used to get Email Templates
*
* @throws Exception
*/
@throws[Exception]
def getEmailTemplates(moduleAPIName: String): Unit = {
// Get instance of EmailTemplatesOperations Class
// String moduleAPIName = "Deals"
val emailTemplatesOperations = new EmailTemplatesOperations
val paramInstance = new ParameterMap
paramInstance.add(new GetEmailTemplatesParam().module, moduleAPIName)
// Call getEmailTemplates method
val responseOption = emailTemplatesOperations.getEmailTemplates(Option(paramInstance))
if (responseOption.isDefined) { //check response
var response = responseOption.get
println("Status Code: " + response.getStatusCode)
if (util.Arrays.asList(204, 304).contains(response.getStatusCode)) {
println(if (response.getStatusCode == 204) "No Content"
else "Not Modified")
return
}
// Check if expected response is received
if (response.isExpected) {
// Get object from response
val responseHandler = response.getObject
if (responseHandler.isInstanceOf[ResponseWrapper]) { //Get the received ResponseWrapper instance
// Get the received ResponseWrapper instance
val responseWrapper = responseHandler.asInstanceOf[ResponseWrapper]
// Get the list of obtained EmailTemplate instances
val emailTemplates = responseWrapper.getEmailTemplates
for (emailTemplate <- emailTemplates) {
// Get the CreatedTime of each EmailTemplate
println("EmailTemplate CreatedTime: " + emailTemplate.getCreatedTime)
val attachments = emailTemplate.getAttachments()
if (attachments != null) {
for (attachment <- attachments) {
// Get the File ID of each Attachment
println("EmailTemplate Attachment File ID: " + attachment.getFileId())
// Get the File Name of each Attachment
println("EmailTemplate Attachment File Name: " + attachment.getFileName())
// Get the Size of Attachment
println("EmailTemplate Attachment Size: " + attachment.getSize())
// Get the ID of Attachment
println("EmailTemplate Attachment ID: " + attachment.getId())
}
}
// Get the Subject of each EmailTemplate
println("EmailTemplate Subject: " + emailTemplate.getSubject())
// Get the Module of each EmailTemplate
val moduleOption = emailTemplate.getModule()
if (moduleOption.isDefined) {
val module = moduleOption.get
// Get the ID of Module
println("EmailTemplate Module ID: " + module.getId())
// Get the apiName of Module
println("EmailTemplate Module apiName: " + module.getAPIName())
}
// Get the Type of each EmailTemplate
println("EmailTemplate Type: " + emailTemplate.getType())
//Get the Created by
val createdByOption = emailTemplate.getCreatedBy()
if (createdByOption.isDefined) {
val createdBy = createdByOption.get
println("EmailTemplate Created By Name : " + createdBy.getName())
println("EmailTemplate Created By id : " + createdBy.getId())
println("EmailTemplate Created By Email : " + createdBy.getEmail())
}
// Get the ModifiedTime of each EmailTemplate
println("EmailTemplate ModifiedTime: " + emailTemplate.getModifiedTime())
//Get the Created by
val folderOption = emailTemplate.getFolder()
if (folderOption.isDefined) {
val folder = folderOption.get
println("EmailTemplate Folder id : " + folder.getId())
println("EmailTemplate Folder Name : " + folder.getName())
}
// Get the Last Usage time of each EmailTemplate
println("EmailTemplate Last Usage Time: " + emailTemplate.getLastUsageTime())
// Get the Associated of each EmailTemplate
println("EmailTemplate Associated: " + emailTemplate.getAssociated())
// Get the Name of each EmailTemplate
println("EmailTemplate Name: " + emailTemplate.getName())
// Get the Consent Linked of each EmailTemplate
println("EmailTemplate Consent Linked: " + emailTemplate.getConsentLinked())
//Get the Modified by
val modifiedByOption = emailTemplate.getModifiedBy()
if (modifiedByOption.isDefined) {
val modifiedBy = modifiedByOption.get
println("EmailTemplate Modified By Name : " + modifiedBy.getName())
println("EmailTemplate Modified By id : " + modifiedBy.getId())
println("EmailTemplate Modified By Email : " + modifiedBy.getEmail())
}
// Get the ID of each EmailTemplate
println("EmailTemplate ID: " + emailTemplate.getId())
println("EmailTemplate Content: " + emailTemplate.getContent())
// Get the Description of each EmailTemplate
println("EmailTemplate Description: " + emailTemplate.getDescription())
// Get the EditorMode of each EmailTemplate
println("EmailTemplate EditorMode: " + emailTemplate.getEditorMode())
// Get the Favourite of each EmailTemplate
println("EmailTemplate Favourite: " + emailTemplate.getFavorite())
// Get the Favourite of each EmailTemplate
println("EmailTemplate Subject: " + emailTemplate.getSubject())
}
//Get the Object obtained Info instance
val info = responseWrapper.getInfo.get
//Check if info is not null
if (info != null) {
println("Record Info PerPage: " + info.getPerPage.toString)
println("Record Info Count: " + info.getCount.toString)
println("Record Info Page: " + info.getPage.toString)
println("Record Info MoreRecords: " + info.getMoreRecords.toString)
}
}
else { //Check if the request returned an exception
responseHandler match {
case exception: APIException => //Get the received APIException instance
//Get the Status
println("Status: " + exception.getStatus.getValue)
//Get the Code
println("Code: " + exception.getCode.getValue)
println("Details: ")
exception.getDetails.foreach(entry => {
println(entry._1 + ": " + entry._2)
})
//Get the Message
println("Message: " + exception.getMessage.getValue)
case _ =>
}
}
}
else { //If response is not as expected
//Get model object from response
val responseObject = response.getModel
//Get the response object's class
val clas = responseObject.getClass
//Get all declared fields of the response class
val fields = clas.getDeclaredFields
for (field <- fields) { //Get each value
println(field.getName + ":" + field.get(responseObject))
}
}
}
}
}
class EmailTemplates {}
Get Email Template
package com.zoho.crm.sample.emailtemplates
import java.util
import com.zoho.crm.api.emailtemplates.EmailTemplatesOperations
import com.zoho.crm.api.emailtemplates.EmailTemplatesOperations.GetEmailTemplatesParam
import com.zoho.crm.api.emailtemplates.ResponseWrapper
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.emailtemplates.APIException
object EmailTemplates {
/*
* Get EmailTemplate - This method is used to get a single Email
* Template
*
* @param emailTemplateID The id of the Email Template
*
* @throws Exception
*/
@throws[Exception]
def getEmailTemplateById(emailTemplateID: Long): Unit = { //example,
// Get instance of EmailTemplatesOperations Class
val emailTemplatesOperations = new EmailTemplatesOperations()
val responseOption = emailTemplatesOperations.getEmailTemplateById(emailTemplateID)
if (responseOption.isDefined) {
var response= responseOption.get
println("Status Code: " + response.getStatusCode)
if (util.Arrays.asList(204, 304).contains(response.getStatusCode)) {
println(if (response.getStatusCode == 204) "No Content"
else "Not Modified")
return
}
// Check if expected response is received
if (response.isExpected) {
val responseHandler = response.getObject
responseHandler match {
case responseWrapper: ResponseWrapper =>
// Get the list of obtained EmailTemplate instances
val emailTemplates = responseWrapper.getEmailTemplates
for (emailTemplate <- emailTemplates) {
// Get the CreatedTime of each EmailTemplate
println("EmailTemplate CreatedTime: " + emailTemplate.getCreatedTime())
val attachments = emailTemplate.getAttachments()
if (attachments != null) {
for (attachment <- attachments) {
// Get the File ID of each Attachment
println("EmailTemplate Attachment File ID: " + attachment.getFileId())
// Get the File Name of each Attachment
println("EmailTemplate Attachment File Name: " + attachment.getFileName())
// Get the Size of Attachment
println("EmailTemplate Attachment Size: " + attachment.getSize())
// Get the ID of Attachment
println("EmailTemplate Attachment ID: " + attachment.getId())
}
}
// Get the Subject of each EmailTemplate
println("EmailTemplate Subject: " + emailTemplate.getSubject())
// Get the Module of each EmailTemplate
val moduleOption = emailTemplate.getModule()
if (moduleOption.isDefined) {
val module = moduleOption.get
// Get the ID of Module
println("EmailTemplate Module ID: " + module.getId())
// Get the apiName of Module
println("EmailTemplate Module apiName: " + module.getAPIName())
}
// Get the Type of each EmailTemplate
println("EmailTemplate Type: " + emailTemplate.getType())
//Get the Created by
val createdByOption = emailTemplate.getCreatedBy()
if (createdByOption.isDefined) {
val createdBy = createdByOption.get
println("EmailTemplate Created By Name : " + createdBy.getName())
println("EmailTemplate Created By id : " + createdBy.getId())
println("EmailTemplate Created By Name : " + createdBy.getEmail())
}
// Get the ModifiedTime of each EmailTemplate
println("EmailTemplate ModifiedTime: " + emailTemplate.getModifiedTime())
//Get the Created by
val folderOption = emailTemplate.getFolder()
if (folderOption.isDefined) {
val folder = folderOption.get
println("EmailTemplate Folder id : " + folder.getId())
println("EmailTemplate Folder Name : " + folder.getName())
}
// Get the Last Usage time of each EmailTemplate
println("EmailTemplate Last Usage Time: " + emailTemplate.getLastUsageTime())
// Get the Associated of each EmailTemplate
println("EmailTemplate Associated: " + emailTemplate.getAssociated())
// Get the Name of each EmailTemplate
println("EmailTemplate Name: " + emailTemplate.getName())
// Get the Consent Linked of each EmailTemplate
println("EmailTemplate Consent Linked: " + emailTemplate.getConsentLinked())
//Get the Modified by
val modifiedByOption = emailTemplate.getModifiedBy()
if (modifiedByOption.isDefined) {
val modifiedBy = modifiedByOption.get
println("EmailTemplate Modified By Name : " + modifiedBy.getName())
println("EmailTemplate Modified By id : " + modifiedBy.getId())
println("EmailTemplate Modified By Name : " + modifiedBy.getEmail())
}
// Get the ID of each EmailTemplate
println("EmailTemplate ID: " + emailTemplate.getId())
// Get the Editor mode of each EmailTemplate
println("EmailTemplate : " + emailTemplate.getEditorMode())
println("EmailTemplate Content: " + emailTemplate.getContent())
// Get the Description of each EmailTemplate
println("EmailTemplate Description: " + emailTemplate.getDescription())
// Get the EditorMode of each EmailTemplate
println("EmailTemplate EditorMode: " + emailTemplate.getEditorMode())
// Get the Favourite of each EmailTemplate
println("EmailTemplate Favourite: " + emailTemplate.getFavorite())
// Get the Favourite of each EmailTemplate
println("EmailTemplate Subject: " + emailTemplate.getSubject())
}
case exception: APIException =>
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
exception.getDetails.foreach(entry => {
println(entry._1 + ": " + entry._2)
})
println("Message: " + exception.getMessage.getValue)
case _ =>
}
}
else {
val responseObject = response.getModel
val clas = responseObject.getClass
val fields = clas.getDeclaredFields
for (field <- fields) {
println(field.getName + ":" + field.get(responseObject))
}
}
}
}
}
class EmailTemplates {}