Scala SDK Samples - Variable Operations
package com.zoho.crm.sample.variables
import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.variablegroups.VariableGroup
import com.zoho.crm.api.variables.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, Variable, VariablesOperations}
import com.zoho.crm.api.variables.VariablesOperations.DeleteVariablesParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariableByIDParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariableForAPINameParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariablesParam
import scala.collection.mutable.ArrayBuffer
object Variables {
/**
* Get Variables
* This method is used to retrieve all the available variables through an API request and print the response.
*
* @throws Exception
*/
@throws[Exception]
def getVariables(): Unit = { //Get instance of VariablesOperations Class
val variablesOperations = new VariablesOperations
//Get instance of ParameterMap Class
val paramInstance = new ParameterMap
paramInstance.add(new VariablesOperations.GetVariablesParam().group, "created")
//Call getVariables method that takes paramInstance as parameter
val responseOption = variablesOperations.getVariables(Option(paramInstance))
if (responseOption.isDefined) { //check response
var response= responseOption.get
println("Status Code: " + response.getStatusCode)//Get the status code from response
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
val responseWrapper = responseHandler.asInstanceOf[ResponseWrapper]
//Get the obtained Variable instance
val variables = responseWrapper.getVariables
for (variable {
println(entry._1 + ": " + entry._2)
})
//Get the Message
println("Message: " + exception.getMessage.getValue)
}
}
}
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
package com.zoho.crm.sample.variables
import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.variablegroups.VariableGroup
import com.zoho.crm.api.variables.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, Variable, VariablesOperations}
import com.zoho.crm.api.variables.VariablesOperations.DeleteVariablesParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariableByIDParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariableForAPINameParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariablesParam
import scala.collection.mutable.ArrayBuffer
object Variables {
/**
* Update Variables
* This method is used to update details of variables in CRM and print the response.
*
* @throws Exception
*/
@throws[Exception]
def updateVariables(): Unit = {
val variablesOperations = new VariablesOperations
val request = new BodyWrapper
val variableList = new ArrayBuffer[Variable]
var variable1 = new Variable
variable1.setId(Option(352403306489001L))
variable1.setValue("4763")
variable1.setDescription(Option("This is a new description"))
variableList.addOne(variable1)
variable1 = new Variable
variable1.setId(Option(352406489003L))
variable1.setDescription(Option("Thissd is a new description"))
variableList.addOne(variable1)
request.setVariables(variableList)
//Call updateVariables method that takes BodyWrapper class instance as parameter
val responseOption = variablesOperations.updateVariables(request)
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.getVariables
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: ")
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: ")
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.variables
import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.variablegroups.VariableGroup
import com.zoho.crm.api.variables.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, Variable, VariablesOperations}
import com.zoho.crm.api.variables.VariablesOperations.DeleteVariablesParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariableByIDParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariableForAPINameParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariablesParam
import scala.collection.mutable.ArrayBuffer
object Variables {
/**
* Delete Variables
* This method is used to delete details of multiple variables in CRM simultaneously and print the response.
*
* @param variableIds - The List of the Variable IDs to be deleted
* @throws Exception
*/
@throws[Exception]
def deleteVariables(variableIds: ArrayBuffer[Long]): Unit = { //example
val variablesOperations = new VariablesOperations
val paramInstance = new ParameterMap
for (variableId {
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: ")
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: ")
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.variables
import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.variablegroups.VariableGroup
import com.zoho.crm.api.variables.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, Variable, VariablesOperations}
import com.zoho.crm.api.variables.VariablesOperations.DeleteVariablesParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariableByIDParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariableForAPINameParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariablesParam
import scala.collection.mutable.ArrayBuffer
object Variables {
/**
* Get Variable By Id
* This method is used to get the details of any specific variable.
* Specify the unique ID of the variable in your API request to get the data for that particular variable group.
*
* @param variableId - The ID of the Variable to be obtained
* @throws Exception
*/
@throws[Exception]
def getVariableById(variableId: Long): Unit = { //Long variableId = 34770320163l
val variablesOperations = new VariablesOperations
val paramInstance = new ParameterMap
// paramInstance.add(new GetVariableByIDParam().group, "347706089001") //"General"
//Call getVariableById method that takes paramInstance and variableId as parameter
val responseOption = variablesOperations.getVariableById(variableId,Option(paramInstance))
if (responseOption.isDefined) { //Get the status code from 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 variables = responseWrapper.getVariables
for (variable {
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.variables
import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.variablegroups.VariableGroup
import com.zoho.crm.api.variables.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, Variable, VariablesOperations}
import com.zoho.crm.api.variables.VariablesOperations.DeleteVariablesParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariableByIDParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariableForAPINameParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariablesParam
import scala.collection.mutable.ArrayBuffer
object Variables {
/**
* Update Variable By Id
* This method is used to update details of a specific variable in CRM and print the response.
*
* @param variableId - The ID of the Variable to be updated
* @throws Exception
*/
@throws[Exception]
def updateVariableById(variableId: Long): Unit = {
val variablesOperations = new VariablesOperations
val request = new BodyWrapper
val variableList = new ArrayBuffer[Variable]
val variable1 = new Variable
variable1.setAPIName(Option("TestAPIName"))
variableList.addOne(variable1)
request.setVariables(variableList)
//Call updateVariableById method that takes BodyWrapper instance and variableId as parameter
val responseOption = variablesOperations.updateVariableById(variableId,request)
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.getVariables
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: ")
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: ")
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.variables
import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.variablegroups.VariableGroup
import com.zoho.crm.api.variables.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, Variable, VariablesOperations}
import com.zoho.crm.api.variables.VariablesOperations.DeleteVariablesParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariableByIDParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariableForAPINameParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariablesParam
import scala.collection.mutable.ArrayBuffer
object Variables {
/**
* Delete Variable
* This method is used to delete details of a specific variable in CRM and print the response.
*
* @param variableId - The ID of the Variable to be deleted
* @throws Exception
*/
@throws[Exception]
def deleteVariable(variableId: Long): Unit = {
val variablesOperations = new VariablesOperations
//Call deleteVariable method that takes variableId as parameter
val responseOption = variablesOperations.deleteVariable(variableId)
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.getVariables
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: ")
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: ")
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.variables
import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.variablegroups.VariableGroup
import com.zoho.crm.api.variables.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, Variable, VariablesOperations}
import com.zoho.crm.api.variables.VariablesOperations.DeleteVariablesParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariableByIDParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariableForAPINameParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariablesParam
import scala.collection.mutable.ArrayBuffer
object Variables {
/**
* Get Variable for API Name
* This method is used to get the details of any specific variable.
* Specify the unique name of the variable in your API request to get the data for that particular variable group.
*
* @param variableName - The name of the Variable to be obtained
* @throws Exception
*/
@throws[Exception]
def getVariableForAPIName(variableName: String): Unit = { //String variableName = "Variable55"
val variablesOperations = new VariablesOperations
val paramInstance = new ParameterMap
// paramInstance.add(new GetVariableForAPINameParam().group, "General") //"3477061000003089001"
//Call getVariableForAPIName method that takes paramInstance and variableName as parameter
val responseOption = variablesOperations.getVariableForAPIName(variableName,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
}
if (response.isExpected) {
val responseHandler = response.getObject
if (responseHandler.isInstanceOf[ResponseWrapper]) {
val responseWrapper = responseHandler.asInstanceOf[ResponseWrapper]
val variables = responseWrapper.getVariables
for (variable {
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.variables
import java.util
import com.zoho.crm.api.ParameterMap
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.variablegroups.VariableGroup
import com.zoho.crm.api.variables.{APIException, ActionHandler, ActionResponse, ActionWrapper, BodyWrapper, ResponseHandler, ResponseWrapper, SuccessResponse, Variable, VariablesOperations}
import com.zoho.crm.api.variables.VariablesOperations.DeleteVariablesParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariableByIDParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariableForAPINameParam
import com.zoho.crm.api.variables.VariablesOperations.GetVariablesParam
import scala.collection.mutable.ArrayBuffer
object Variables {
/**
* This method is used to update details of a specific variable in CRM and print the response.
*
* @param variableName - The name of the Variable to be updated
* @throws Exception
*/
@throws[Exception]
def updateVariableByAPIName(variableName: String): Unit = {
val variablesOperations = new VariablesOperations
val request = new BodyWrapper
val variableList = new ArrayBuffer[Variable]
val variable1 = new Variable
variable1.setDescription(Option("Test update Variable By APIName"))
variableList.addOne(variable1)
request.setVariables(variableList)
//Call updateVariableByAPIName method that takes BodyWrapper instance and variableName as parameter
val responseOption = variablesOperations.updateVariableByAPIName(variableName,request)
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.getVariables
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: ")
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: ")
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