Scala SDK Samples - Notes Operations
package com.zoho.crm.sample.notes
import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util
import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.attachments.Attachment
import com.zoho.crm.api.notes.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Info, Note, NotesOperations, ResponseHandler, ResponseWrapper, SuccessResponse}
import com.zoho.crm.api.notes.NotesOperations.DeleteNotesParam
import com.zoho.crm.api.notes.NotesOperations.GetNotesHeader
import com.zoho.crm.api.notes.NotesOperations.GetNotesParam
import com.zoho.crm.api.record.Record
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import scala.collection.mutable.ArrayBuffer
object Notes {
/**
* Create Notes
* This method is used to add new notes and print the response.
*
* @throws Exception
*/
@throws[Exception]
def createNotes(): Unit = {
val notesOperations = new NotesOperations
//Get instance of BodyWrapper Class that will contain the request body
val bodyWrapper = new BodyWrapper
//List of Note instances
val notes = new ArrayBuffer[Note]
for (i <- 1 to 5) { //Get instance of Note Class
val note = new Note
//Set Note_Title of the Note
note.setNoteTitle(Option("Contacted"))
//Set NoteContent of the Note
note.setNoteContent(Option("Need to do further tracking"))
//Get instance of Record Class
val parentRecord = new Record
//Set ID of the Record
parentRecord.setId(Option(34770610780177l))
//Set ParentId of the Note
note.setParentId(Option(parentRecord))
//Set SeModule of the Record
note.setseModule(Option("Leads"))
//Add Note instance to the list
notes.addOne(note)
}
//Set the list to notes in BodyWrapper instance
bodyWrapper.setData(notes)
//Call createNotes method that takes BodyWrapper instance as parameter
val responseOption = notesOperations.createNotes(bodyWrapper)
if (responseOption.isDefined) { //check response
var response= responseOption.get
println("Status Code: " + response.getStatusCode)
if (response.isExpected) {
val actionHandler = response.getObject
if (actionHandler.isInstanceOf[ActionWrapper]) { //Get the received ActionWrapper instance
val actionWrapper = actionHandler.asInstanceOf[ActionWrapper]
//Get the list of obtained ActionResponse instances
val actionResponses = actionWrapper.getData
for (actionResponse <- actionResponses) { //Check if the request is successful
if (actionResponse.isInstanceOf[SuccessResponse]) { //Get the received SuccessResponse instance
val successResponse = actionResponse.asInstanceOf[SuccessResponse]
println("Status: " + successResponse.getStatus.getValue)
println("Code: " + successResponse.getCode.getValue)
println("Details: ")
if (successResponse.getDetails != null) {
successResponse.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
}
println("Message: " + successResponse.getMessage.getValue)
}
else if (actionResponse.isInstanceOf[APIException]) {
val exception = actionResponse.asInstanceOf[APIException]
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
if (exception.getDetails != null) {
exception.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
}
println("Message: " + exception.getMessage.getValue)
}
}
}
else if (actionHandler.isInstanceOf[APIException]) {
val exception = actionHandler.asInstanceOf[APIException]
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
if (exception.getDetails != null) {
exception.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
}
println("Message: " + exception.getMessage.getValue)
}
}
else {
val responseObject = response.getModel
val clas = responseObject.getClass
val fields = clas.getDeclaredFields
for (field <- fields) {
println(field.getName + ":" + field.get(responseObject))
}
}
}
}
}
package com.zoho.crm.sample.notes
import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util
import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.attachments.Attachment
import com.zoho.crm.api.notes.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Info, Note, NotesOperations, ResponseHandler, ResponseWrapper, SuccessResponse}
import com.zoho.crm.api.notes.NotesOperations.DeleteNotesParam
import com.zoho.crm.api.notes.NotesOperations.GetNotesHeader
import com.zoho.crm.api.notes.NotesOperations.GetNotesParam
import com.zoho.crm.api.record.Record
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import scala.collection.mutable.ArrayBuffer
object Notes {
/**
* Update Notes
* This method is used to update an existing note and print the response.
*
* @throws Exception
*/
@throws[Exception]
def updateNotes(): Unit = {
val notesOperations = new NotesOperations
val bodyWrapper = new BodyWrapper
val notes = new ArrayBuffer[Note]
var note = new Note
note.setId(Option(3477061668001l))
note.setNoteTitle(Option("Contacted12"))
note.setNoteContent(Option("Need to do further tracking12"))
notes.addOne(note)
note = new Note
note.setId(Option(3477061668002l))
note.setNoteTitle(Option("Contacted13"))
note.setNoteContent(Option("Need to do further tracking13"))
notes.addOne(note)
bodyWrapper.setData(notes)
//Call updateNotes method that takes BodyWrapper instance as parameter
val responseOption = notesOperations.updateNotes(bodyWrapper)
if (responseOption.isDefined) { //check response
var response= responseOption.get
println("Status Code: " + response.getStatusCode)
if (response.isExpected) {
val actionHandler = response.getObject
if (actionHandler.isInstanceOf[ActionWrapper]) {
val actionWrapper = actionHandler.asInstanceOf[ActionWrapper]
val actionResponses = actionWrapper.getData
for (actionResponse <- actionResponses) {
if (actionResponse.isInstanceOf[SuccessResponse]) {
val successResponse = actionResponse.asInstanceOf[SuccessResponse]
println("Status: " + successResponse.getStatus.getValue)
println("Code: " + successResponse.getCode.getValue)
println("Details: ")
if (successResponse.getDetails != null) {
successResponse.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
}
println("Message: " + successResponse.getMessage.getValue)
}
else if (actionResponse.isInstanceOf[APIException]) {
val exception = actionResponse.asInstanceOf[APIException]
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
if (exception.getDetails != null) {
if (exception.getDetails != null) {
exception.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
}
}
println("Message: " + exception.getMessage.getValue)
}
}
}
else if (actionHandler.isInstanceOf[APIException]) {
val exception = actionHandler.asInstanceOf[APIException]
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
if (exception.getDetails != null) {
exception.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
}
println("Message: " + exception.getMessage.getValue)
}
}
else {
val responseObject = response.getModel
val clas = responseObject.getClass
val fields = clas.getDeclaredFields
for (field <- fields) {
println(field.getName + ":" + field.get(responseObject))
}
}
}
}
}
package com.zoho.crm.sample.notes
import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util
import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.attachments.Attachment
import com.zoho.crm.api.notes.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Info, Note, NotesOperations, ResponseHandler, ResponseWrapper, SuccessResponse}
import com.zoho.crm.api.notes.NotesOperations.DeleteNotesParam
import com.zoho.crm.api.notes.NotesOperations.GetNotesHeader
import com.zoho.crm.api.notes.NotesOperations.GetNotesParam
import com.zoho.crm.api.record.Record
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import scala.collection.mutable.ArrayBuffer
object Notes {
/**
* This method is used to delete notes in bulk and print the response.
*
* @param notesId - The List of Note IDs to be deleted
* @throws Exception
*/
@throws[Exception]
def deleteNotes(notesId: ArrayBuffer[Long]): Unit = { //example
//ArrayList<Long> notesId = new ArrayList<Long>(Arrays.asList(34770616153001l,347706153002l))
val notesOperations = new NotesOperations
val paramInstance = new ParameterMap
for (id <- notesId) {
paramInstance.add(new DeleteNotesParam().ids, id)
}
//Call deleteNotes method that takes paramInstance as parameter
val responseOption = notesOperations.deleteNotes(Option(paramInstance))
if (responseOption.isDefined) { //check response
var response= responseOption.get
println("Status Code: " + response.getStatusCode)
if (response.isExpected) {
val actionHandler = response.getObject
if (actionHandler.isInstanceOf[ActionWrapper]) {
val actionWrapper = actionHandler.asInstanceOf[ActionWrapper]
val actionResponses = actionWrapper.getData
for (actionResponse <- actionResponses) {
if (actionResponse.isInstanceOf[SuccessResponse]) {
val successResponse = actionResponse.asInstanceOf[SuccessResponse]
println("Status: " + successResponse.getStatus.getValue)
println("Code: " + successResponse.getCode.getValue)
println("Details: ")
if (successResponse.getDetails != null) {
successResponse.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
}
println("Message: " + successResponse.getMessage.getValue)
}
else if (actionResponse.isInstanceOf[APIException]) {
val exception = actionResponse.asInstanceOf[APIException]
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
if (exception.getDetails != null) {
if (exception.getDetails != null) {
exception.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
}
}
println("Message: " + exception.getMessage.getValue)
}
}
}
else if (actionHandler.isInstanceOf[APIException]) {
val exception = actionHandler.asInstanceOf[APIException]
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
if (exception.getDetails != null) {
exception.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
}
println("Message: " + exception.getMessage.getValue)
}
}
else {
val responseObject = response.getModel
val clas = responseObject.getClass
val fields = clas.getDeclaredFields
for (field <- fields) {
println(field.getName + ":" + field.get(responseObject))
}
}
}
}
}
package com.zoho.crm.sample.notes
import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util
import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.attachments.Attachment
import com.zoho.crm.api.notes.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Info, Note, NotesOperations, ResponseHandler, ResponseWrapper, SuccessResponse}
import com.zoho.crm.api.notes.NotesOperations.DeleteNotesParam
import com.zoho.crm.api.notes.NotesOperations.GetNotesHeader
import com.zoho.crm.api.notes.NotesOperations.GetNotesParam
import com.zoho.crm.api.record.Record
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import scala.collection.mutable.ArrayBuffer
object Notes {
/**
* Get Note
* This method is used to get the note and print the response.
*
* @param noteId - The ID of the Note to be obtained
* @throws Exception
*/
@throws[Exception]
def getNote(noteId: Long): Unit = { //example
//Long noteId = 34770653005l
val notesOperations = new NotesOperations
//Call getNote method that takes noteId as parameter
val responseOption = notesOperations.getNote(noteId)
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
}
if (response.isExpected) {
val responseHandler = response.getObject
if (responseHandler.isInstanceOf[ResponseWrapper]) {
val responseWrapper = responseHandler.asInstanceOf[ResponseWrapper]
val notes = responseWrapper.getData
for (note <- notes) {
val ownerOption = note.getOwner
//Check if owner is not null
if (ownerOption.isDefined) { //Get the name of the owner User
val owner= ownerOption.get
println("Note Owner User-Name: " + owner.getName)
println("Note Owner User-ID: " + owner.getId)
println("Note Owner Email: " + owner.getEmail)
}
println("Note ModifiedTime: " + note.getModifiedTime)
val attachments = note.getattachments()
if (attachments != null) {
for (attachment <- attachments) {
printAttachment(attachment)
}
}
println("Note CreatedTime: " + note.getCreatedTime)
val parentIdOption = note.getParentId
//Check if parentId is not null
if (parentIdOption.isDefined) {
val parentId = parentIdOption.get
if (parentId.getKeyValue("name") != null) println("Note parent record Name: " + parentId.getKeyValue("name"))
println("Note parent record ID: " + parentId.getId)
}
println("Note Editable: " + note.toString)
println("Note SeModule: " + note.getseModule())
println("Note IsSharedToClient: " + note.getisSharedToClient().toString)
val modifiedByOption = note.getModifiedBy
//Check if modifiedBy is not null
if (modifiedByOption.isDefined) { //Get the Name of the modifiedBy User
val modifiedBy=modifiedByOption.get
println("Note Modified By User-Name: " + modifiedBy.getName)
println("Note Modified By User-ID: " + modifiedBy.getId)
println("Note Modified By User-Email: " + modifiedBy.getEmail)
}
println("Note Size: " + note.getsize())
println("Note State: " + note.getstate())
println("Note VoiceNote: " + note.getvoiceNote().toString)
println("Note Id: " + note.getId)
val createdByOption = note.getCreatedBy
//Check if createdBy is not null
if (createdByOption.isDefined) { //Get the Name of the createdBy User
val createdBy=createdByOption.get
println("Note Created By User-Name: " + createdBy.getName)
println("Note Created By User-ID: " + createdBy.getId)
println("Note Created By User-Email: " + createdBy.getEmail)
}
println("Note NoteTitle: " + note.getNoteTitle)
println("Note NoteContent: " + note.getNoteContent)
}
}
else if (responseHandler.isInstanceOf[APIException]) {
val exception = responseHandler.asInstanceOf[APIException]
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
if (exception.getDetails != null) {
exception.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
}
println("Message: " + exception.getMessage.getValue)
}
}
else {
val responseObject = response.getModel
val clas = responseObject.getClass
val fields = clas.getDeclaredFields
for (field <- fields) {
println(field.getName + ":" + field.get(responseObject))
}
}
}
}
}
package com.zoho.crm.sample.notes
import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util
import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.attachments.Attachment
import com.zoho.crm.api.notes.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Info, Note, NotesOperations, ResponseHandler, ResponseWrapper, SuccessResponse}
import com.zoho.crm.api.notes.NotesOperations.DeleteNotesParam
import com.zoho.crm.api.notes.NotesOperations.GetNotesHeader
import com.zoho.crm.api.notes.NotesOperations.GetNotesParam
import com.zoho.crm.api.record.Record
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import scala.collection.mutable.ArrayBuffer
object Notes {
/**
* Update Note
* This method is used to update an existing note and print the response.
*
* @param noteId - The ID of the Note to be obtained
* @throws Exception
*/
@throws[Exception]
def updateNote(noteId: Long): Unit = {
val notesOperations = new NotesOperations
val bodyWrapper = new BodyWrapper
val notes = new ArrayBuffer[Note]
val note = new Note
note.setNoteTitle(Option("Contacted12"))
note.setNoteContent(Option("Need to do further tracking12"))
val parentRecord = new Record
parentRecord.setId(Option(34770610255001l))
note.setParentId(Option(parentRecord))
note.setseModule(Option("Contacts"))
notes.addOne(note)
bodyWrapper.setData(notes)
//Call updateNote method that takes BodyWrapper instance and noteId as parameter
val responseOption = notesOperations.updateNote(noteId,bodyWrapper)
if (responseOption.isDefined) { //check response
var response= responseOption.get
println("Status Code: " + response.getStatusCode)
if (response.isExpected) {
val actionHandler = response.getObject
if (actionHandler.isInstanceOf[ActionWrapper]) {
val actionWrapper = actionHandler.asInstanceOf[ActionWrapper]
val actionResponses = actionWrapper.getData
for (actionResponse {
println(entry._1 + ": " + entry._2)
})
}
println("Message: " + successResponse.getMessage.getValue)
}
else if (actionResponse.isInstanceOf[APIException]) {
val exception = actionResponse.asInstanceOf[APIException]
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
if (exception.getDetails != null) {
if (exception.getDetails != null) {
exception.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
}
}
println("Message: " + exception.getMessage.getValue)
}
}
}
else if (actionHandler.isInstanceOf[APIException]) {
val exception = actionHandler.asInstanceOf[APIException]
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
if (exception.getDetails != null) {
exception.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
}
println("Message: " + exception.getMessage.getValue)
}
}
else {
val responseObject = response.getModel
val clas = responseObject.getClass
val fields = clas.getDeclaredFields
for (field
package com.zoho.crm.sample.notes
import java.lang.reflect.Field
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.util
import com.zoho.crm.api.HeaderMap
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.attachments.Attachment
import com.zoho.crm.api.notes.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, Info, Note, NotesOperations, ResponseHandler, ResponseWrapper, SuccessResponse}
import com.zoho.crm.api.notes.NotesOperations.DeleteNotesParam
import com.zoho.crm.api.notes.NotesOperations.GetNotesHeader
import com.zoho.crm.api.notes.NotesOperations.GetNotesParam
import com.zoho.crm.api.record.Record
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import scala.collection.mutable.ArrayBuffer
object Notes {
/**
* Delete Note
* This method is used to delete single Note with ID and print the response.
*
* @param noteID - The ID of the Note to be deleted
* @throws Exception
*/
@@throws[Exception]
def deleteNote(noteID: Long): Unit = {
val notesOperations = new NotesOperations
//Call deleteNote method that takes noteID as parameter
val responseOption = notesOperations.deleteNote(noteID)
if (responseOption.isDefined) { //check response
var response= responseOption.get
println("Status Code: " + response.getStatusCode)
if (response.isExpected) {
val actionHandler = response.getObject
if (actionHandler.isInstanceOf[ActionWrapper]) {
val actionWrapper = actionHandler.asInstanceOf[ActionWrapper]
val actionResponses = actionWrapper.getData
for (actionResponse <- actionResponses) {
if (actionResponse.isInstanceOf[SuccessResponse]) {
val successResponse = actionResponse.asInstanceOf[SuccessResponse]
println("Status: " + successResponse.getStatus.getValue)
println("Code: " + successResponse.getCode.getValue)
println("Details: ")
if (successResponse.getDetails != null) {
successResponse.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
}
println("Message: " + successResponse.getMessage.getValue)
}
else if (actionResponse.isInstanceOf[APIException]) {
val exception = actionResponse.asInstanceOf[APIException]
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
if (exception.getDetails != null) {
if (exception.getDetails != null) {
exception.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
}
}
println("Message: " + exception.getMessage.getValue)
}
}
}
else if (actionHandler.isInstanceOf[APIException]) {
val exception = actionHandler.asInstanceOf[APIException]
println("Status: " + exception.getStatus.getValue)
println("Code: " + exception.getCode.getValue)
println("Details: ")
if (exception.getDetails != null) {
exception.getDetails.foreach(entry=>{
println(entry._1 + ": " + entry._2)
})
}
println("Message: " + exception.getMessage.getValue)
}
}
else {
val responseObject = response.getModel
val clas = responseObject.getClass
val fields = clas.getDeclaredFields
for (field <- fields) {
println(field.getName + ":" + field.get(responseObject))
}
}
}
}
}