PHP SDK Samples - Share Records Operations

Get Shared Record Details
              
              
<?php
namespace samples\sharerecords;

use com\zoho\api\authenticator\OAuthBuilder;
use com\zoho\crm\api\dc\USDataCenter;
use com\zoho\crm\api\InitializeBuilder;
use com\zoho\crm\api\UserSignature;
use com\zoho\crm\api\ParameterMap;
use com\zoho\crm\api\sharerecords\APIException;
use com\zoho\crm\api\sharerecords\ResponseWrapper;
use com\zoho\crm\api\sharerecords\ShareRecordsOperations;
use com\zoho\crm\api\sharerecords\GetSharedRecordDetailsParam;
require_once "vendor/autoload.php";

class GetSharedRecordDetails
{
    public static function initialize()
    {
        $user = new UserSignature('myname@mydomain.com');
        $environment = USDataCenter::PRODUCTION();
        $token = (new OAuthBuilder())
        ->clientId("1000.xxxx")
        ->clientSecret("xxxxxx")
        ->refreshToken("1000.xxxxx.xxxxx")
        ->build();
        (new InitializeBuilder())
            ->user($user)
            ->environment($environment)
            ->token($token)
            ->initialize();
    }

	public static function getSharedRecordDetails(string $moduleAPIName, string $recordId)
	{
	    $shareRecordsOperations = new ShareRecordsOperations( $recordId,$moduleAPIName);
		$paramInstance = new ParameterMap();
		$paramInstance->add(GetSharedRecordDetailsParam::view(), "summary");
		// $paramInstance->add(GetSharedRecordDetailsParam::sharedTo(), "34770615791024");
		$response = $shareRecordsOperations->getSharedRecordDetails($paramInstance);
		if($response != null)
		{
            echo("Status code " . $response->getStatusCode() . "\n");
            if(in_array($response->getStatusCode(), array(204, 304)))
            {
                echo($response->getStatusCode() == 204? "No Content\n" : "Not Modified\n");
                return;
            }
            $responseHandler = $response->getObject();
            if($responseHandler instanceof ResponseWrapper)
            {
                $responseWrapper = $responseHandler;
                $shareRecords = $responseWrapper->getShare();
                if($shareRecords != null)
                {
                    foreach($shareRecords as $shareRecord)
                    {
                        echo("ShareRecord ShareRelatedRecords: "); print_r($shareRecord->getShareRelatedRecords()); echo("\n");
                        $sharedThrough = $shareRecord->getSharedThrough();
                        if($sharedThrough != null)
                        {
                            echo("RelatedRecord SharedThrough EntityName: " . $sharedThrough->getEntityName() . "\n");
                            $module = $sharedThrough->getModule();
                            if($module != null)
                            {
                                echo("RelatedRecord SharedThrough Module ID: " . $module->getId() . "\n");
                                echo("RelatedRecord SharedThrough Module Name: " . $module->getName() . "\n");
                            }
                            echo("RelatedRecord SharedThrough ID: " . $sharedThrough->getId() . "\n");
                        }
                        echo("ShareRecord SharedTime: "); print_r($shareRecord->getSharedTime()); echo("\n");
                        echo("ShareRecord Permission: " . $shareRecord->getPermission() . "\n");
                        $user = $shareRecord->getUser();
                        if($user != null)
                        {
                            echo("ShareRecord User-ID: " . $user->getId() . "\n");
                            echo("RelatedRecord User-FullName: " . $user->getFullName() . "\n");
                            echo("RelatedRecord User-Zuid: " . $user->getZuid() . "\n");
                        }
                        $sharedBy = $shareRecord->getSharedBy();
                        if($sharedBy != null)
                        {
                            echo("ShareRecord SharedBy User-ID: " . $sharedBy->getId() . "\n");
                            echo("RelatedRecord SharedBy User-FullName: " . $sharedBy->getFullName() . "\n");
                            echo("RelatedRecord SharedBy User-Zuid: " . $sharedBy->getZuid() . "\n");
                        }
                    }
                }
                if($responseWrapper->getShareableUser() != null)
                {
                    $shareableUsers = $responseWrapper->getShareableUser();
                    foreach($shareableUsers as $shareableUser)
                    {
                        echo("ShareRecord User-ID: " . $shareableUser->getId());
                        echo("ShareRecord User-FullName: " . $shareableUser->getFullName());
                        echo("ShareRecord User-Zuid: " . $shareableUser->getZuid());
                    }
                }
            }
            else if($responseHandler instanceof APIException)
			{
				$exception = $responseHandler;
				echo("Status: " . $exception->getStatus()->getValue() . "\n");
				echo("Code: " . $exception->getCode()->getValue() . "\n");
                if($exception->getDetails() != null)
                {
                    echo("Details: " );
                    foreach($exception->getDetails() as $key => $value)
                    {
                        echo($key . ": " .$value . "\n");
                    }
                }
				echo("Message: " . $exception->getMessage()->getValue() . "\n");
			}
		}
	}
}

GetSharedRecordDetails::initialize();
$moduleAPIName = "Leads";
$recordId = "34770615623115";
GetSharedRecordDetails::getSharedRecordDetails($moduleAPIName, $recordId);
?>
Share a Record
              
              
<?php
namespace samples\sharerecords;

use com\zoho\api\authenticator\OAuthBuilder;
use com\zoho\crm\api\dc\USDataCenter;
use com\zoho\crm\api\InitializeBuilder;
use com\zoho\crm\api\UserSignature;
use com\zoho\crm\api\sharerecords\APIException;
use com\zoho\crm\api\sharerecords\ActionWrapper;
use com\zoho\crm\api\sharerecords\BodyWrapper;
use com\zoho\crm\api\sharerecords\ShareRecordsOperations;
use com\zoho\crm\api\sharerecords\SuccessResponse;
use com\zoho\crm\api\users\User;
require_once "vendor/autoload.php";

class ShareRecord
{
    public static function initialize()
    {
        $user = new UserSignature('myname@mydomain.com');
        $environment = USDataCenter::PRODUCTION();
        $token = (new OAuthBuilder())
        ->clientId("1000.xxxx")
        ->clientSecret("xxxxxx")
        ->refreshToken("1000.xxxxx.xxxxx")
        ->build();
        (new InitializeBuilder())
            ->user($user)
            ->environment($environment)
            ->token($token)
            ->initialize();
    }

	public static function shareRecord(string $moduleAPIName, string $recordId)
	{
	    $shareRecordsOperations = new ShareRecordsOperations( $recordId, $moduleAPIName);
		$request = new BodyWrapper();
		$shareList = array();
        $shareRecordClass = "com\zoho\crm\api\sharerecords\ShareRecord";
		for($i = 0; $i < 1; $i++)
		{
			$share1 = new $shareRecordClass();
			$share1->setShareRelatedRecords(true);
			$share1->setPermission("read_write");
			$user = new User();
			$user->setId("34770615791024");
			$share1->setUser($user);
			array_push($shareList, $share1);
        }
        $share1 = new $shareRecordClass();
		$share1->setShareRelatedRecords(true);
		$share1->setPermission("read_write");
		$user = new User();
		$user->setId("34770615791024");
		$share1->setUser($user);
		array_push($shareList, $share1);
		$request->setShare($shareList);
		$response = $shareRecordsOperations->shareRecord($request);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
            $actionHandler = $response->getObject();
            if($actionHandler instanceof ActionWrapper)
            {
                $actionWrapper = $actionHandler;
                $actionResponses = $actionWrapper->getShare();
                foreach($actionResponses as $actionResponse)
                {
                    if($actionResponse instanceof SuccessResponse)
                    {
                        $successResponse = $actionResponse;
                        echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
                        echo("Code: " . $successResponse->getCode()->getValue() . "\n");
                        if($successResponse->getDetails() != null)
                        {
                            echo("Details: " );
                            foreach($successResponse->getDetails() as $key => $value)
                            {
                                echo($key . " : " . $value . "\n");
                            }
                        }
                        echo("Message: " . $successResponse->getMessage()->getValue() . "\n");
                    }
                    else if($actionResponse instanceof APIException)
                    {
                        $exception = $actionResponse;
                        echo("Status: " . $exception->getStatus()->getValue() . "\n");
                        echo("Code: " . $exception->getCode()->getValue() . "\n");
                        echo("Details: " );
                        foreach($exception->getDetails() as $key => $value)
                        {
                            echo($key . " : " . $value . "\n");
                        }
                        echo("Message: " . $exception->getMessage()->getValue() . "\n");
                    }
                }
            }
            else if($actionHandler instanceof APIException)
            {
                $exception = $actionHandler;
                echo("Status: " . $exception->getStatus()->getValue() . "\n");
                echo("Code: " . $exception->getCode()->getValue() . "\n");
                echo("Details: " );
                foreach($exception->getDetails() as $key => $value)
                {
                    echo($key . " : " . $value . "\n");
                }
                echo("Message: " . $exception->getMessage()->getValue() . "\n");
            }
		}
	}
}

ShareRecord::initialize();
$moduleAPIName = "Leads";
$recordId = "34770615623115";
ShareRecord::shareRecord($moduleAPIName, $recordId);
?>
Update Share Permissions
              
              
<?php
namespace samples\sharerecords;

use com\zoho\api\authenticator\OAuthBuilder;
use com\zoho\crm\api\dc\USDataCenter;
use com\zoho\crm\api\InitializeBuilder;
use com\zoho\crm\api\UserSignature;
use com\zoho\crm\api\sharerecords\APIException;
use com\zoho\crm\api\sharerecords\ActionWrapper;
use com\zoho\crm\api\sharerecords\BodyWrapper;
use com\zoho\crm\api\sharerecords\ShareRecord;
use com\zoho\crm\api\sharerecords\ShareRecordsOperations;
use com\zoho\crm\api\sharerecords\SuccessResponse;
use com\zoho\crm\api\users\User;
require_once "vendor/autoload.php";

class UpdateSharePermissions
{
    public static function initialize()
    {
        $user = new UserSignature('myname@mydomain.com');
        $environment = USDataCenter::PRODUCTION();
        $token = (new OAuthBuilder())
        ->clientId("1000.xxxx")
        ->clientSecret("xxxxxx")
        ->refreshToken("1000.xxxxx.xxxxx")
        ->build();
        (new InitializeBuilder())
            ->user($user)
            ->environment($environment)
            ->token($token)
            ->initialize();
    }

	public static function updateSharePermissions(string $moduleAPIName, string $recordId)
	{
	    $shareRecordsOperations = new ShareRecordsOperations($recordId, $moduleAPIName);
		$request = new BodyWrapper();
		$shareList = array();
		$share1 = new ShareRecord();
		$share1->setShareRelatedRecords(true);
		$share1->setPermission("full_access");
		$user = new User();
		$user->setId("34770615791024");
		$share1->setUser($user);
		array_push($shareList, $share1);
		$request->setShare($shareList);
		$response = $shareRecordsOperations->updateSharePermissions($request);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
            $actionHandler = $response->getObject();
            if($actionHandler instanceof ActionWrapper)
            {
                $actionWrapper = $actionHandler;
                $actionResponses = $actionWrapper->getShare();
                foreach($actionResponses as $actionResponse)
                {
                    if($actionResponse instanceof SuccessResponse)
                    {
                        $successResponse = $actionResponse;
                        echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
                        echo("Code: " . $successResponse->getCode()->getValue() . "\n");
                        if($successResponse->getDetails() != null)
                        {
                            echo("Details: " );
                            foreach($successResponse->getDetails() as $key => $value)
                            {
                                echo($key . " : " . $value . "\n");
                            }
                        }
                        echo("Message: " . $successResponse->getMessage()->getValue() . "\n");
                    }
                    else if($actionResponse instanceof APIException)
                    {
                        $exception = $actionResponse;
                        echo("Status: " . $exception->getStatus()->getValue() . "\n");
                        echo("Code: " . $exception->getCode()->getValue() . "\n");
                        echo("Details: " );
                        foreach($exception->getDetails() as $key => $value)
                        {
                            echo($key . " : " . $value . "\n");
                        }
                        echo("Message: " . $exception->getMessage()->getValue() . "\n");
                    }
                }
            }
            else if($actionHandler instanceof APIException)
            {
                $exception = $actionHandler;
                echo("Status: " . $exception->getStatus()->getValue() . "\n");
                echo("Code: " . $exception->getCode()->getValue() . "\n");
                echo("Details: " );
                foreach($exception->getDetails() as $key => $value)
                {
                    echo($key . " : " . $value . "\n");
                }
                echo("Message: " . $exception->getMessage()->getValue() . "\n");
            }
		}
	}
}

UpdateSharePermissions::initialize();
$moduleAPIName = "Leads";
$recordId = "34770615623115";
UpdateSharePermissions::updateSharePermissions($moduleAPIName, $recordId);
?>
Revoke Access to a Shared Record
              
              
<?php
namespace samples\sharerecords;

use com\zoho\api\authenticator\OAuthBuilder;
use com\zoho\crm\api\dc\USDataCenter;
use com\zoho\crm\api\InitializeBuilder;
use com\zoho\crm\api\UserSignature;
use com\zoho\crm\api\sharerecords\APIException;
use com\zoho\crm\api\sharerecords\DeleteActionWrapper;
use com\zoho\crm\api\sharerecords\ShareRecordsOperations;
use com\zoho\crm\api\sharerecords\SuccessResponse;
require_once "vendor/autoload.php";

class RevokeSharedRecord
{
    public static function initialize()
    {
        $user = new UserSignature('myname@mydomain.com');
        $environment = USDataCenter::PRODUCTION();
        $token = (new OAuthBuilder())
        ->clientId("1000.xxxx")
        ->clientSecret("xxxxxx")
        ->refreshToken("1000.xxxxx.xxxxx")
        ->build();
        (new InitializeBuilder())
            ->user($user)
            ->environment($environment)
            ->token($token)
            ->initialize();
    }

	public static function revokeSharedRecord(string $moduleAPIName, string $recordId)
	{
	    $shareRecordsOperations = new ShareRecordsOperations($recordId, $moduleAPIName);
		$response = $shareRecordsOperations->revokeSharedRecord();
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
            $deleteActionHandler = $response->getObject();
            if($deleteActionHandler instanceof DeleteActionWrapper)
            {
                $deleteActionWrapper = $deleteActionHandler;
                $deleteActionResponse = $deleteActionWrapper->getShare();
                if($deleteActionResponse instanceof SuccessResponse)
                {
                    $successResponse = $deleteActionResponse;
                    echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
                    echo("Code: " . $successResponse->getCode()->getValue() . "\n");
                    echo("Details: " );
                    foreach($successResponse->getDetails() as $key => $value)
                    {
                        echo($key . " : " . $value . "\n");
                    }
                    echo("Message: " . $successResponse->getMessage()->getValue() . "\n");
                }
                else if($deleteActionResponse instanceof APIException)
                {
                    $exception = $deleteActionResponse;
                    echo("Status: " . $exception->getStatus()->getValue() . "\n");
                    echo("Code: " . $exception->getCode()->getValue() . "\n");
                    echo("Details: " );
                    foreach($exception->getDetails() as $key => $value)
                    {
                        echo($key . " : " . $value . "\n");
                    }
                    echo("Message: " . $exception->getMessage()->getValue() . "\n");
                }
            }
            else if($deleteActionHandler instanceof APIException)
            {
                $exception = $deleteActionHandler;
                echo("Status: " . $exception->getStatus()->getValue() . "\n");
                echo("Code: " . $exception->getCode()->getValue() . "\n");
                if($exception->getDetails() != null)
                {
                    echo("Details: " );
                    foreach($exception->getDetails() as $key => $value)
                    {
                        echo($key . " : " . $value . "\n");
                    }
                }
                echo("Message: " . $exception->getMessage()->getValue() . "\n");
            }
		}
	}
}

RevokeSharedRecord::initialize();
$moduleAPIName = "Leads";
$recordId = "34770615623115";
RevokeSharedRecord::revokeSharedRecord($moduleAPIName, $recordId);
?>