Typescript SDK Samples - Organization Operations

Get Organization Details
              
              
import { LicenseDetails } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/org/license_details";
import { Org } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/org/org";
import {OrgOperations} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/org/org_operations"
import { ResponseHandler } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/org/response_handler";
import { APIException } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/org/api_exception";
import { SuccessResponse } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/org/success_response";
import { ResponseWrapper } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/org/response_wrapper";
import { APIResponse } from "@zohocrm/typescript-sdk-2.0/routes/controllers/api_response";
import { FileBodyWrapper } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/org/file_body_wrapper";
import { StreamWrapper } from "@zohocrm/typescript-sdk-2.0/utils/util/stream_wrapper";
import * as fs from "fs";
import { ActionResponse } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/org/action_response";

export class Organization{
    /**
     * Get Organization
     * This method is used to get the organization data and print the response.
     */
    public static async getOrganization(){

        //Get instance of OrgOperations Class
        let orgOperations: OrgOperations = new OrgOperations();

        //Call getOrganization method
        let response: APIResponse<ResponseHandler> = await orgOperations.getOrganization();

        if(response != null){

            //Get the status code from response
            console.log("Status Code: " + response.getStatusCode());

            if([204, 304].includes(response.getStatusCode())){
                console.log(response.getStatusCode() == 204? "No Content" : "Not Modified");

                return;
            }

            //Get object from response
            let responseObject: ResponseHandler = response.getObject();

            if(responseObject != null){

                //Check if expected ResponseWrapper instance is received
                if(responseObject instanceof ResponseWrapper){

                    //Get the list of obtained Org instances
                    let orgs: Org[] = responseObject.getOrg();

                    orgs.forEach(org => {

                        //Get the Country of each Organization
                        console.log("Organization Country: " + org.getCountry());
                        
                        //Get the PhotoId of each Organization
                        console.log("Organization PhotoId: " + org.getPhotoId());
                        
                        //Get the City of each Organization
                        console.log("Organization City: " + org.getCity());
                        
                        //Get the Description of each Organization
                        console.log("Organization Description: " + org.getDescription());
                        
                        //Get the McStatus of each Organization
                        console.log("Organization McStatus: " + org.getMcStatus());
                        
                        //Get the GappsEnabled of each Organization
                        console.log("Organization GappsEnabled: " + org.getGappsEnabled());
                        
                        //Get the DomainName of each Organization
                        console.log("Organization DomainName: " + org.getDomainName());
                        
                        //Get the TranslationEnabled of each Organization
                        console.log("Organization TranslationEnabled: " + org.getTranslationEnabled());
                        
                        //Get the Street of each Organization
                        console.log("Organization Street: " + org.getStreet());
                        
                        //Get the Alias of each Organization
                        console.log("Organization Alias: " + org.getAlias());
                        
                        //Get the Currency of each Organization
                        console.log("Organization Currency: " + org.getCurrency());
                        
                        //Get the Id of each Organization
                        console.log("Organization Id: " + org.getId());
                        
                        //Get the State of each Organization
                        console.log("Organization State: " + org.getState());
                        
                        //Get the Fax of each Organization
                        console.log("Organization Fax: " + org.getFax());
                        
                        //Get the EmployeeCount of each Organization
                        console.log("Organization EmployeeCount: " + org.getEmployeeCount());
                        
                        //Get the Zip of each Organization
                        console.log("Organization Zip: " + org.getZip());
                        
                        //Get the Website of each Organization
                        console.log("Organization Website: " + org.getWebsite());
                        
                        //Get the CurrencySymbol of each Organization
                        console.log("Organization CurrencySymbol: " + org.getCurrencySymbol());
                        
                        //Get the Mobile of each Organization
                        console.log("Organization Mobile: " + org.getMobile());
                        
                        //Get the CurrencyLocale of each Organization
                        console.log("Organization CurrencyLocale: " + org.getCurrencyLocale());
                        
                        //Get the PrimaryZuid of each Organization
                        console.log("Organization PrimaryZuid: " + org.getPrimaryZuid());
                        
                        //Get the ZiaPortalId of each Organization
                        console.log("Organization ZiaPortalId: " + org.getZiaPortalId());
                        
                        //Get the TimeZone of each Organization
                        console.log("Organization TimeZone: " + org.getTimeZone());
                        
                        //Get the Zgid of each Organization
                        console.log("Organization Zgid: " + org.getZgid());
                        
                        //Get the CountryCode of each Organization
                        console.log("Organization CountryCode: " + org.getCountryCode());
                        
                        //Get the Object obtained LicenseDetails instance
                        let licenseDetails: LicenseDetails = org.getLicenseDetails();
                        
                        //Check if licenseDetails is not null
                        if(licenseDetails != null && licenseDetails != undefined){
                            //Get the PaidExpiry of each LicenseDetails
                            console.log("Organization LicenseDetails PaidExpiry: " + licenseDetails.getPaidExpiry());
                            
                            //Get the UsersLicensePurchased of each LicenseDetails
                            console.log("Organization LicenseDetails UsersLicensePurchased: " + licenseDetails.getUsersLicensePurchased());
                            
                            //Get the TrialType of each LicenseDetails
                            console.log("Organization LicenseDetails TrialType: " + licenseDetails.getTrialType());
                            
                            //Get the TrialExpiry of each LicenseDetails
                            console.log("Organization LicenseDetails TrialExpiry: " + licenseDetails.getTrialExpiry());
                            
                            //Get the Paid of each LicenseDetails
                            console.log("Organization LicenseDetails Paid: " + licenseDetails.getPaid());
                            
                            //Get the PaidType of each LicenseDetails
                            console.log("Organization LicenseDetails PaidType: " + licenseDetails.getPaidType());
                        }
                        
                        //Get the Phone of each Organization
                        console.log("Organization Phone: " + org.getPhone());
                        
                        //Get the CompanyName of each Organization
                        console.log("Organization CompanyName: " + org.getCompanyName());
                        
                        //Get the PrivacySettings of each Organization
                        console.log("Organization PrivacySettings: " + org.getPrivacySettings());
                        
                        //Get the PrimaryEmail of each Organization
                        console.log("Organization PrimaryEmail: " + org.getPrimaryEmail());
                        
                        //Get the IsoCode of each Organization
                        console.log("Organization IsoCode: " + org.getIsoCode());
                    });
                }
                //Check if the request returned an exception
                else if(responseObject instanceof 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: Map<string,any> = 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());
                }
            }
        }
    }
}
 
Upload Organization Photo
              
              
import { LicenseDetails } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/org/license_details";
import { Org } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/org/org";
import {OrgOperations} from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/org/org_operations"
import { ResponseHandler } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/org/response_handler";
import { APIException } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/org/api_exception";
import { SuccessResponse } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/org/success_response";
import { ResponseWrapper } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/org/response_wrapper";
import { APIResponse } from "@zohocrm/typescript-sdk-2.0/routes/controllers/api_response";
import { FileBodyWrapper } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/org/file_body_wrapper";
import { StreamWrapper } from "@zohocrm/typescript-sdk-2.0/utils/util/stream_wrapper";
import * as fs from "fs";
import { ActionResponse } from "@zohocrm/typescript-sdk-2.0/core/com/zoho/crm/api/org/action_response";

export 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
     */
    public static async uploadOrganizationPhoto(absoluteFilePath: string){

        //example
        //let absoluteFilePath = "/Users/user_name/Desktop/logo.png";

        //Get instance of OrgOperations Class
        let orgOperations: OrgOperations = new OrgOperations();

        //Get instance of FileBodyWrapper class that will contain the request file
        let fileBodyWrapper:FileBodyWrapper = new FileBodyWrapper();
        
        /** StreamWrapper can be initialized in any of the following ways */ 

        /**
         * param 1 -> fileName 
         * param 2 -> Read Stream.
         */
        let streamWrapper = new StreamWrapper(undefined, undefined, absoluteFilePath);

        /**
         * 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: APIResponse<ActionResponse> = 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: ActionResponse = response.getObject();

            if(responseObject != null){

                //Check if the request is successful
                if(responseObject instanceof SuccessResponse){

                    //Get the Status
                    console.log("Status: " + responseObject.getStatus().getValue());

                    //Get the Code
                    console.log("Code: " + responseObject.getCode().getValue());

                    console.log("Details");

                    let details: Map<string,any> = 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 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: Map<string,any> = 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());
                } 
            }
        }
    }
}