Skip to main content

Python SDK Samples - Share Records Operations

Get Shared Record Details
Share a Record
              
              
from zcrmsdk.src.com.zoho.crm.api.share_records import *
from zcrmsdk.src.com.zoho.crm.api.share_records import ShareRecord as ZCRMShareRecord
from zcrmsdk.src.com.zoho.crm.api.users import User
from zcrmsdk.src.com.zoho.crm.api import ParameterMap
class ShareRecord(object):
    @staticmethod
    def share_record(module_api_name, record_id):

        """
        This method is used to share the record and print the response.
        :param module_api_name: The API Name of the module to share record.
        :param record_id: The ID of the record to be shared
        """

        """
        example
        module_api_name = Contacts
        record_id = 3409643000002112011
        """

        # Get instance of ShareRecordsOperations Class that takes module_api_name and record_id as parameter
        shared_records_operations = ShareRecordsOperations(record_id, module_api_name)

        # Get instance of BodyWrapper Class that will contain the request body
        request = BodyWrapper()

        # List to hold ShareRecord instances
        share_record_list = []

        # Get instance of ShareRecord Class
        share_record = ZCRMShareRecord()

        # Set boolean value to share related records
        share_record.set_share_related_records(True)

        # Set the permission. Possible values - full_access, read_only, read_write
        share_record.set_permission('read_write')

        # Get instance of User Class
        user = User()

        # Set User ID
        user.set_id(3409643000000302031)

        # Set the User instance to user
        share_record.set_user(user)

        # Add the instance to list
        share_record_list.append(share_record)

        # Set the list to share of BodyWrapper instance
        request.set_share(share_record_list)

        # Call share_record method that takes BodyWrapper instance as parameter
        response = shared_records_operations.share_record(request)

        if response is not None:
            # Get the status code from response
            print('Status Code: ' + str(response.get_status_code()))

            # Get object from response
            response_object = response.get_object()

            if response_object is not None:

                # Check if expected ActionWrapper instance is received.
                if isinstance(response_object, ActionWrapper):

                    # Get the list of obtained ActionResponse instances
                    action_response_list = response_object.get_share()

                    for action_response in action_response_list:

                        # Check if the request is successful
                        if isinstance(action_response, SuccessResponse):
                            # Get the Status
                            print("Status: " + action_response.get_status().get_value())

                            # Get the Code
                            print("Code: " + action_response.get_code().get_value())

                            print("Details")

                            # Get the details dict
                            details = action_response.get_details()

                            for key, value in details.items():
                                print(key + ' : ' + str(value))

                            # Get the Message
                            print("Message: " + action_response.get_message().get_value())

                        # Check if the request returned an exception
                        elif isinstance(action_response, APIException):
                            # Get the Status
                            print("Status: " + action_response.get_status().get_value())

                            # Get the Code
                            print("Code: " + action_response.get_code().get_value())

                            print("Details")

                            # Get the details dict
                            details = action_response.get_details()

                            for key, value in details.items():
                                print(key + ' : ' + str(value))

                            # Get the Message
                            print("Message: " + action_response.get_message().get_value())

                # Check if the request returned an exception
                elif isinstance(response_object, APIException):
                    # Get the Status
                    print("Status: " + response_object.get_status().get_value())

                    # Get the Code
                    print("Code: " + response_object.get_code().get_value())

                    print("Details")

                    # Get the details dict
                    details = response_object.get_details()

                    for key, value in details.items():
                        print(key + ' : ' + str(value))

                    # Get the Message
                    print("Message: " + response_object.get_message().get_value())
 
Update Share Permissions
              
              
from zcrmsdk.src.com.zoho.crm.api.share_records import *
from zcrmsdk.src.com.zoho.crm.api.share_records import ShareRecord as ZCRMShareRecord
from zcrmsdk.src.com.zoho.crm.api.users import User
from zcrmsdk.src.com.zoho.crm.api import ParameterMap
class ShareRecord(object):
    @staticmethod
    def update_share_permissions(module_api_name, record_id):

        """
        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 module_api_name: The API Name of the module to update share permissions.
        :param record_id: The ID of the record
        """

        """
        example
        module_api_name = Contacts
        record_id = 3409643000002112011
        """

        # Get instance of ShareRecordsOperations Class that takes module_api_name and record_id as parameter
        shared_records_operations = ShareRecordsOperations(record_id, module_api_name)

        # Get instance of BodyWrapper Class that will contain the request body
        request = BodyWrapper()

        # List to hold ShareRecord instances
        share_record_list = []

        # Get instance of ShareRecord Class
        share_record = ZCRMShareRecord()

        # Set boolean value to share related records
        share_record.set_share_related_records(True)

        # Set the permission. Possible values - full_access, read_only, read_write
        share_record.set_permission('full_access')

        # Get instance of User Class
        user = User()

        # Set User ID
        user.set_id(3409643000000302031)

        # Set the User instance to user
        share_record.set_user(user)

        # Add the instance to list
        share_record_list.append(share_record)

        # Set the list to share of BodyWrapper instance
        request.set_share(share_record_list)

        # Call update_share_permissions method that takes BodyWrapper instance as parameter
        response = shared_records_operations.update_share_permissions(request)

        if response is not None:
            # Get the status code from response
            print('Status Code: ' + str(response.get_status_code()))

            # Get object from response
            response_object = response.get_object()

            if response_object is not None:

                # Check if expected ActionWrapper instance is received.
                if isinstance(response_object, ActionWrapper):

                    # Get the list of obtained ActionResponse instances
                    action_response_list = response_object.get_share()

                    for action_response in action_response_list:

                        # Check if the request is successful
                        if isinstance(action_response, SuccessResponse):
                            # Get the Status
                            print("Status: " + action_response.get_status().get_value())

                            # Get the Code
                            print("Code: " + action_response.get_code().get_value())

                            print("Details")

                            # Get the details dict
                            details = action_response.get_details()

                            for key, value in details.items():
                                print(key + ' : ' + str(value))

                            # Get the Message
                            print("Message: " + action_response.get_message().get_value())

                        # Check if the request returned an exception
                        elif isinstance(action_response, APIException):
                            # Get the Status
                            print("Status: " + action_response.get_status().get_value())

                            # Get the Code
                            print("Code: " + action_response.get_code().get_value())

                            print("Details")

                            # Get the details dict
                            details = action_response.get_details()

                            for key, value in details.items():
                                print(key + ' : ' + str(value))

                            # Get the Message
                            print("Message: " + action_response.get_message().get_value())

                # Check if the request returned an exception
                elif isinstance(response_object, APIException):
                    # Get the Status
                    print("Status: " + response_object.get_status().get_value())

                    # Get the Code
                    print("Code: " + response_object.get_code().get_value())

                    print("Details")

                    # Get the details dict
                    details = response_object.get_details()

                    for key, value in details.items():
                        print(key + ' : ' + str(value))

                    # Get the Message
                    print("Message: " + response_object.get_message().get_value())

 
Revoke Access to a Shared Record
              
              
from zcrmsdk.src.com.zoho.crm.api.share_records import *
from zcrmsdk.src.com.zoho.crm.api.share_records import ShareRecord as ZCRMShareRecord
from zcrmsdk.src.com.zoho.crm.api.users import User
from zcrmsdk.src.com.zoho.crm.api import ParameterMap
class ShareRecord(object):
    @staticmethod
    def revoke_shared_record(module_api_name, record_id):

        """
        This method is used to revoke access to a shared record that was shared to users and print the response.
        :param module_api_name: The API Name of the module to revoke shared record.
        :param record_id: The ID of the record
        """

        """
        example
        module_api_name = Contacts
        record_id = 3409643000002112011
        """

        # Get instance of ShareRecordsOperations Class that takes module_api_name and record_id as parameter
        shared_records_operations = ShareRecordsOperations(record_id, module_api_name)

        # Call revoke_shared_record method
        response = shared_records_operations.revoke_shared_record()

        if response is not None:
            # Get the status code from response
            print('Status Code: ' + str(response.get_status_code()))

            # Get object from response
            response_object = response.get_object()

            if response_object is not None:

                # Check if expected ActionWrapper instance is received.
                if isinstance(response_object, DeleteActionWrapper):

                    # Get the list of obtained ActionResponse instances
                    action_response = response_object.get_share()

                    # Check if the request is successful
                    if isinstance(action_response, SuccessResponse):
                        # Get the Status
                        print("Status: " + action_response.get_status().get_value())

                        # Get the Code
                        print("Code: " + action_response.get_code().get_value())

                        print("Details")

                        # Get the details dict
                        details = action_response.get_details()

                        for key, value in details.items():
                            print(key + ' : ' + str(value))

                        # Get the Message
                        print("Message: " + action_response.get_message().get_value())

                    # Check if the request returned an exception
                    elif isinstance(action_response, APIException):
                        # Get the Status
                        print("Status: " + action_response.get_status().get_value())

                        # Get the Code
                        print("Code: " + action_response.get_code().get_value())

                        print("Details")

                        # Get the details dict
                        details = action_response.get_details()

                        for key, value in details.items():
                            print(key + ' : ' + str(value))

                        # Get the Message
                        print("Message: " + action_response.get_message().get_value())

                # Check if the request returned an exception
                elif isinstance(response_object, APIException):
                    # Get the Status
                    print("Status: " + response_object.get_status().get_value())

                    # Get the Code
                    print("Code: " + response_object.get_code().get_value())

                    print("Details")

                    # Get the details dict
                    details = response_object.get_details()

                    for key, value in details.items():
                        print(key + ' : ' + str(value))

                    # Get the Message
                    print("Message: " + response_object.get_message().get_value())