Skip to product menu
Skip to main content

PHP SDK Samples - Share Records Operations

Get Shared Record Details
Share a Record
              
              
<?php
namespace com\zoho\crm\sample\sharerecords;
use com\zoho\crm\api\ParameterMap;
use com\zoho\crm\api\modules\Module;
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\DeleteActionWrapper;
use com\zoho\crm\api\sharerecords\ResponseWrapper;
use com\zoho\crm\api\sharerecords\ShareRecord;
use com\zoho\crm\api\sharerecords\ShareRecordsOperations;
use com\zoho\crm\api\sharerecords\GetSharedRecordDetailsParam;
use com\zoho\crm\api\sharerecords\SharedThrough;
use com\zoho\crm\api\sharerecords\SuccessResponse;
use com\zoho\crm\api\users\User;
class ShareRecords
{
    /**
     * Share Record
     * This method is used to share the record and print the response.
     * @param moduleAPIName - The API Name of the module to shared record.
     * @param recordId - The ID of the record to be obtained.
     * @throws Exception
     */
    public static function shareRecord(string $moduleAPIName, string $recordId)
    {
        //example
        //$moduleAPIName = "Leads";
        //$recordId = "34770615177002";
        
        //Get instance of ShareRecordsOperations Class that takes moduleAPIName and recordId as parameter
        $shareRecordsOperations = new ShareRecordsOperations( $recordId,$moduleAPIName);
        
        //Get instance of BodyWrapper Class that will contain the request body
        $request = new BodyWrapper();
        
        //List of ShareRecord instances
        $shareList = array();
        
        //Get instance of ShareRecord Class
        $share1 = new ShareRecord();
        
        for($i = 0; $i setShareRelatedRecords(true);
            
            //Set the access permission given to the user for that record.
            $share1->setPermission("read_write");
            
            $user = new User();
            
            $user->setId("34770615791024");
            
            //Set the users details with whom the record is shared.
            $share1->setUser($user);
            
            array_push($shareList, $share1);
        }
        
        $share1 = new ShareRecord();
        
        $share1->setShareRelatedRecords(true);
        
        $share1->setPermission("read_write");
        
        $user = new User();
        
        $user->setId("34770615791024");
        
        $share1->setUser($user);
        
        array_push($shareList, $share1);
        
        $request->setShare($shareList);
        
        //Call getSharedRecordDetails method that takes paramInstance as parameter
        $response = $shareRecordsOperations->shareRecord($request);
        
        if($response != null)
        {
            //Get the status code from response
            echo("Status Code: " . $response->getStatusCode() . "\n");
            
            //Get object from response
            $actionHandler = $response->getObject();
            
            if($actionHandler instanceof ActionWrapper)
            {
                //Get the received ActionWrapper instance
                $actionWrapper = $actionHandler;
                
                //Get the list of obtained ActionResponse instances
                $actionResponses = $actionWrapper->getShare();
                
                foreach($actionResponses as $actionResponse)
                {
                    //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");
                        
                        if($successResponse->getDetails() != null)
                        {
                            echo("Details: " );
                        
                            //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 map
                        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");
                    }
                }
            }
            //Check if the request returned an exception
            else if($actionHandler instanceof APIException)
            {
                //Get the received APIException instance
                $exception = $actionHandler;
                
                //Get the Status
                echo("Status: " . $exception->getStatus()->getValue() . "\n");
                    
                //Get the Code
                echo("Code: " . $exception->getCode()->getValue() . "\n");
                
                echo("Details: " );
                
                //Get the details map
                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");
            }
        }
    }
}
 
Update Share Permissions
              
              
<?php
namespace com\zoho\crm\sample\sharerecords;
use com\zoho\crm\api\ParameterMap;
use com\zoho\crm\api\modules\Module;
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\DeleteActionWrapper;
use com\zoho\crm\api\sharerecords\ResponseWrapper;
use com\zoho\crm\api\sharerecords\ShareRecord;
use com\zoho\crm\api\sharerecords\ShareRecordsOperations;
use com\zoho\crm\api\sharerecords\GetSharedRecordDetailsParam;
use com\zoho\crm\api\sharerecords\SharedThrough;
use com\zoho\crm\api\sharerecords\SuccessResponse;
use com\zoho\crm\api\users\User;
class ShareRecords
{
    /**
     * Update Share Permissions
     * This method is used to update the sharing permissions of a record granted to users as Read-Write, Read-only, or grant full access.
     * @param moduleAPIName - The API Name of the module to update share permissions.
     * @param recordId - The ID of the record to be obtained.
     * @throws Exception
     */
    public static function updateSharePermissions(string $moduleAPIName, string $recordId)
    {
        //example
        //$moduleAPIName = "Leads";
        //$recordId = "34770615177002";
        
        //Get instance of ShareRecordsOperations Class that takes moduleAPIName and recordId as parameter
        $shareRecordsOperations = new ShareRecordsOperations( $recordId,$moduleAPIName);
        
        //Get instance of BodyWrapper Class that will contain the request body
        $request = new BodyWrapper();
        
        //List of ShareRecord instances
        $shareList = array();
        
        //Get instance of ShareRecord Class
        $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);
        
        //Call updateSharePermissions method that takes BodyWrapper instance as parameter
        $response = $shareRecordsOperations->updateSharePermissions($request);
        
        if($response != null)
        {
            //Get the status code from response
            echo("Status Code: " . $response->getStatusCode() . "\n");
            
            //Get object from response
            $actionHandler = $response->getObject();
            
            if($actionHandler instanceof ActionWrapper)
            {
                //Get the received ActionWrapper instance
                $actionWrapper = $actionHandler;
                
                //Get the list of obtained ActionResponse instances
                $actionResponses = $actionWrapper->getShare();
                
                foreach($actionResponses as $actionResponse)
                {
                    //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");
                        
                        if($successResponse->getDetails() != null)
                        {
                            echo("Details: " );
                        
                            //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 map
                        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");
                    }
                }
            }
            //Check if the request returned an exception
            else if($actionHandler instanceof APIException)
            {
                //Get the received APIException instance
                $exception = $actionHandler;
                
                //Get the Status
                echo("Status: " . $exception->getStatus()->getValue() . "\n");
                        
                //Get the Code
                echo("Code: " . $exception->getCode()->getValue() . "\n");
                
                echo("Details: " );
                
                //Get the details map
                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");
            }
        }
    }
}
 
Revoke Access to a Shared Record
              
              
<?php
namespace com\zoho\crm\sample\sharerecords;
use com\zoho\crm\api\ParameterMap;
use com\zoho\crm\api\modules\Module;
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\DeleteActionWrapper;
use com\zoho\crm\api\sharerecords\ResponseWrapper;
use com\zoho\crm\api\sharerecords\ShareRecord;
use com\zoho\crm\api\sharerecords\ShareRecordsOperations;
use com\zoho\crm\api\sharerecords\GetSharedRecordDetailsParam;
use com\zoho\crm\api\sharerecords\SharedThrough;
use com\zoho\crm\api\sharerecords\SuccessResponse;
use com\zoho\crm\api\users\User;
class ShareRecords
{
    /**
     * Revoke Shared Record 
     * This method is used to revoke access to a shared record that was shared to users and print the response.
     * @param moduleAPIName - The API Name of the module to revoke shared record.
     * @param recordId - The ID of the record to be obtained.
     * @throws Exception
     */
   public static function revokeSharedRecord(string $moduleAPIName, string $recordId)
    {
        //example
        //moduleAPIName = "Leads";
        //recordId = "34770615177002";
        
        //Get instance of ShareRecordsOperations Class that takes moduleAPIName and recordId as parameter
        $shareRecordsOperations = new ShareRecordsOperations( $recordId,$moduleAPIName);
        
        //Call revokeSharedRecord method
        $response = $shareRecordsOperations->revokeSharedRecord();
        
        if($response != null)
        {
            //Get the status code from response
            echo("Status Code: " . $response->getStatusCode() . "\n");
            
            //Get object from response
            $deleteActionHandler = $response->getObject();
            
            if($deleteActionHandler instanceof DeleteActionWrapper)
            {
                //Get the received DeleteActionWrapper instance
                $deleteActionWrapper = $deleteActionHandler;
                
                //Get the received DeleteActionResponse instance
                $deleteActionResponse = $deleteActionWrapper->getShare();
                
                //Check if the request is successful
                if($deleteActionResponse instanceof SuccessResponse)
                {
                    //Get the received SuccessResponse instance
                    $successResponse = $deleteActionResponse;
                    
                    //Get the Status
                    echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
                    
                    //Get the Code
                    echo("Code: " . $successResponse->getCode()->getValue() . "\n");
                    
                    echo("Details: " );
                    
                    //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($deleteActionResponse instanceof APIException)
                {
                    //Get the received APIException instance
                    $exception = $deleteActionResponse;
                    
                    //Get the Status
                    echo("Status: " . $exception->getStatus()->getValue() . "\n");
                            
                    //Get the Code
                    echo("Code: " . $exception->getCode()->getValue() . "\n");
                    
                    echo("Details: " );
                    
                    //Get the details map
                    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");
                }
            }
            //Check if the request returned an exception
            else if($deleteActionHandler instanceof APIException)
            {
                //Get the received APIException instance
                $exception = $deleteActionHandler;
                
                //Get the Status
                echo("Status: " . $exception->getStatus()->getValue() . "\n");
                        
                //Get the Code
                echo("Code: " . $exception->getCode()->getValue() . "\n");
                
                if($exception->getDetails() != null)
                {
                    echo("Details: " );
                
                    //Get the details map
                    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");
            }
        }
    }
}