Run your entire business on Zoho with our unified cloud software, designed to help you break down silos between departments and increase organizational efficiency.
package com.zoho.crm.sample.organization
import java.lang.reflect.Field
import java.util
import com.zoho.crm.api.org.{APIException, ActionResponse, FileBodyWrapper, LicenseDetails, OrgOperations, ResponseHandler, ResponseWrapper, SuccessResponse}
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.util.StreamWrapper
object Organization {
/**
* Get Organization
* This method is used to get the organization data and print the response.
*
* @throws Exception
*/
@throws[Exception]
def getOrganization(): Unit = { //Get instance of OrgOperations Class
val orgOperations = new OrgOperations
//Call getOrganization method
val responseOption = orgOperations.getOrganization
if (responseOption.isDefined ) { //Check response
val response=responseOption.get
println("Status Code: " + response.getStatusCode)
//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 list of obtained Org instances
val orgs = responseWrapper.getOrg
for (org {
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
Upload Organization Photo
package com.zoho.crm.sample.organization
import java.lang.reflect.Field
import java.util
import com.zoho.crm.api.org.{APIException, ActionResponse, FileBodyWrapper, LicenseDetails, OrgOperations, ResponseHandler, ResponseWrapper, SuccessResponse}
import com.zoho.crm.api.util.APIResponse
import com.zoho.crm.api.util.Model
import com.zoho.crm.api.util.StreamWrapper
object Organization {
/**
* Upload Organization Photo
* This method is used to upload the brand logo or image of the organization and print the response.
*
* @param absoluteFilePath - The absolute file path of the file to be attached
* @throws Exception
*/
@throws[Exception]
def uploadOrganizationPhoto(absoluteFilePath: String): Unit = { //example
//String absoluteFilePath = "/Users/user_name/Desktop/download.png"
val orgOperations = new OrgOperations
//Get instance of FileBodyWrapper class that will contain the request file
val fileBodyWrapper = new FileBodyWrapper
//Get instance of StreamWrapper class that takes absolute path of the file to be attached as parameter
val streamWrapper = new StreamWrapper(absoluteFilePath)
//Set file to the FileBodyWrapper instance
fileBodyWrapper.setFile(Option(streamWrapper))
//Call uploadOrganizationPhoto method that takes FileBodyWrapper instance
val responseOption = orgOperations.uploadOrganizationPhoto(fileBodyWrapper)
if (responseOption.isDefined ) { //Check response
val response=responseOption.get
println("Status Code: " + response.getStatusCode)
if (response.isExpected) {
val actionResponse = response.getObject
//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 {
val responseObject = response.getModel
val clas = responseObject.getClass
val fields = clas.getDeclaredFields
for (field