JavaScript SDK Samples - Organization Operations
Get Organization Details
Upload Organization Photo
class Organization
{
/**
* Upload Organization Photo
* This method is used to upload the brand logo or image of the organization and print the response.
*/
static async uploadOrganizationPhoto() {
//example
//let absoluteFilePath = "/Users/user_name/Desktop/logo.png";
//Get instance of OrgOperations Class
let orgOperations = new ZCRM.Org.Operations();
//Get instance of FileBodyWrapper class that will contain the request file
let fileBodyWrapper = new ZCRM.Org.Model.FileBodyWrapper();
/** StreamWrapper can be initialized in any of the following ways */
var filesToLoad = document.getElementById("org").files;
var file = filesToLoad[0];
/**
* param 1 -> fileName
* param 2 -> Read Stream.
*/
let streamWrapper = new StreamWrapper.Model.StreamWrapper(null, file);
/**
* param 1 -> fileName
* param 2 -> Read Stream
* param 3 -> Absolute File Path of the file to be attached
*/
// let streamWrapper = new StreamWrapper(null, null, absoluteFilePath);
//Set file to the FileBodyWrapper instance
fileBodyWrapper.setFile(streamWrapper);
//Call uploadOrganizationPhoto method that takes FileBodyWrapper instance as parameter
let response = await orgOperations.uploadOrganizationPhoto(fileBodyWrapper);
if (response != null) {
//Get the status code from response
console.log("Status Code: " + response.getStatusCode());
//Get object from response
let responseObject = response.getObject();
if (responseObject != null) {
//Check if the request is successful
if (responseObject instanceof ZCRM.Org.Model.SuccessResponse) {
//Get the Status
console.log("Status: " + responseObject.getStatus().getValue());
//Get the Code
console.log("Code: " + responseObject.getCode().getValue());
console.log("Details");
let details = responseObject.getDetails();
//Get the details map
if (details != null) {
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
//Get the Message
console.log("Message: " + responseObject.getMessage().getValue());
}
//Check if the request returned an exception
else if (responseObject instanceof ZCRM.Org.Model.APIException) {
//Get the Status
console.log("Status: " + responseObject.getStatus().getValue());
//Get the Code
console.log("Code: " + responseObject.getCode().getValue());
console.log("Details");
//Get the details map
let details = responseObject.getDetails();
if (details != null) {
Array.from(details.keys()).forEach(key => {
console.log(key + ": " + details.get(key));
});
}
//Get the Message
console.log("Message: " + responseObject.getMessage().getValue());
}
}
}
}
}