Java SDK Samples - Organization Operations
Get Organization Details
Upload Organization Photo
package samples.src.com.zoho.crm.api.organization;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;
import com.zoho.crm.api.org.APIException;
import com.zoho.crm.api.org.ActionResponse;
import com.zoho.crm.api.org.LicenseDetails;
import com.zoho.crm.api.org.OrgOperations;
import com.zoho.crm.api.org.ResponseHandler;
import com.zoho.crm.api.org.ResponseWrapper;
import com.zoho.crm.api.org.SuccessResponse;
import com.zoho.crm.api.util.APIResponse;
import com.zoho.crm.api.util.Model;
import com.zoho.crm.api.util.StreamWrapper;
public class 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
*/
public static void uploadOrganizationPhoto(String absoluteFilePath) throws Exception
{
//example
//String absoluteFilePath = "/Users/user_name/Desktop/download.png";
//Get instance of OrgOperations Class
OrgOperations orgOperations = new OrgOperations();
//Get instance of FileBodyWrapper class that will contain the request file
com.zoho.crm.api.org.FileBodyWrapper fileBodyWrapper = new com.zoho.crm.api.org.FileBodyWrapper();
//Get instance of StreamWrapper class that takes absolute path of the file to be attached as parameter
StreamWrapper streamWrapper = new StreamWrapper(absoluteFilePath);
//Set file to the FileBodyWrapper instance
fileBodyWrapper.setFile(streamWrapper);
//Call uploadOrganizationPhoto method that takes FileBodyWrapper instance
APIResponse response = orgOperations.uploadOrganizationPhoto(fileBodyWrapper);
if(response != null)
{
//Get the status code from response
System.out.println("Status Code: " + response.getStatusCode());
//Check if expected response is received
if(response.isExpected())
{
//Get object from response
ActionResponse actionResponse = response.getObject();
//Check if the request is successful
if(actionResponse instanceof SuccessResponse)
{
//Get the received SuccessResponse instance
SuccessResponse successResponse = (SuccessResponse)actionResponse;
//Get the Status
System.out.println("Status: " + successResponse.getStatus().getValue());
//Get the Code
System.out.println("Code: " + successResponse.getCode().getValue());
System.out.println("Details: " );
if(successResponse.getDetails() != null)
{
//Get the details map
for(Map.Entry entry : successResponse.getDetails().entrySet())
{
//Get each value in the map
System.out.println(entry.getKey() + ": " + entry.getValue());
}
}
//Get the Message
System.out.println("Message: " + successResponse.getMessage().getValue());
}
//Check if the request returned an exception
else if(actionResponse instanceof APIException)
{
//Get the received APIException instance
APIException exception = (APIException) actionResponse;
//Get the Status
System.out.println("Status: " + exception.getStatus().getValue());
//Get the Code
System.out.println("Code: " + exception.getCode().getValue());
System.out.println("Details: " );
if(exception.getDetails() != null)
{
//Get the details map
for(Map.Entry entry : exception.getDetails().entrySet())
{
//Get each value in the map
System.out.println(entry.getKey() + ": " + entry.getValue());
}
}
//Get the Message
System.out.println("Message: " + exception.getMessage().getValue());
}
}
else
{//If response is not as expected
//Get model object from response
Model responseObject = response.getModel();
//Get the response object's class
Class extends Model> clas = responseObject.getClass();
//Get all declared fields of the response class
java.lang.reflect.Field[] fields = clas.getDeclaredFields();
for(java.lang.reflect.Field field : fields)
{
//Get each value
System.out.println(field.getName() + ":" + field.get(responseObject));
}
}
}
}
}