Skip to main content

PHP SDK Samples - Organization Operations

Get Organization Details
Upload Organization Photo
              
              
<?php
namespace com\zoho\crm\sample\organization;
use com\zoho\crm\api\org\APIException;
use com\zoho\crm\api\org\OrgOperations;
use com\zoho\crm\api\org\ResponseWrapper;
use com\zoho\crm\api\org\SuccessResponse;
use com\zoho\crm\api\org\FileBodyWrapper;
use com\zoho\crm\api\util\StreamWrapper;
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 function uploadOrganizationPhoto(string $absoluteFilePath)
	{
		//Get instance of OrgOperations Class
		$orgOperations = new OrgOperations();
		//Get instance of FileBodyWrapper class that will contain the request file
		$fileBodyWrapper = new FileBodyWrapper();
		//Get instance of StreamWrapper class that takes absolute path of the file to be attached as parameter
		$streamWrapper = new StreamWrapper(null, null, $absoluteFilePath);
		//Set file to the FileBodyWrapper instance
		$fileBodyWrapper->setFile($streamWrapper);
		//Call uploadOrganizationPhoto method that takes FileBodyWrapper instance
		$response = $orgOperations->uploadOrganizationPhoto($fileBodyWrapper);
		if($response != null)
		{
			//Get the status code from response
			echo("Status Code: " . $response->getStatusCode() . "\n");
			//Get object from response
            $actionResponse = $response->getObject();
            //Check if the request is successful
            if($actionResponse instanceof SuccessResponse)
            {
                //Get the received SuccessResponse instance
                $successResponse = $actionResponse;
                //Get the Status
                echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
                //Get the Code
                echo("Code: " . $successResponse->getCode()->getValue() . "\n");
                echo("Details: " );
                if($successResponse->getDetails() != null)
                {
                    //Get the details map
                    foreach($successResponse->getDetails() as $key => $value)
                    {
                        //Get each value in the map
                        echo($key . " : " . $value . "\n");
                    }
                }
                //Get the Message
                echo("Message: " . $successResponse->getMessage()->getValue() . "\n");
            }
            //Check if the request returned an exception
            else if($actionResponse instanceof APIException)
			{
				//Get the received APIException instance
				$exception = $actionResponse;
				//Get the Status
				echo("Status: " . $exception->getStatus()->getValue() . "\n");
				//Get the Code
				echo("Code: " . $exception->getCode()->getValue() . "\n");
				echo("Details: " );
				//Get the details map4
				foreach($exception->getDetails() as $key => $value)
				{
					//Get each value in the map
					echo($key . ": " .$value . "\n");
				}
				//Get the Message
				echo("Message: " . $exception->getMessage()->getValue() . "\n");
			}
		}
	}
}
}