Skip to main content

Python SDK Samples - Blueprint Operations

Get Blueprint Details
Update Blueprint

              
from zcrmsdk.src.com.zoho.crm.api.blue_print import *
from zcrmsdk.src.com.zoho.crm.api.blue_print import BluePrint as ZCRMBluePrint
from zcrmsdk.src.com.zoho.crm.api.record import Record

class BluePrint(object):
    
    @staticmethod
    def update_blueprint(module_api_name, record_id, transition_id):
        """
        This method is used to update a single record's Blueprint details with ID and print the response.
        :param module_api_name: The API Name of the record's module
        :param record_id: The ID of the record to update Blueprint
        :param transition_id: The ID of the Blueprint transition Id
        """

        """
        example
        module_api_name = "Leads"
        record_id = 34096432469044
        transition_id = 34096431172075
        """

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

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

        # List to contain BluePrint instances
        blue_print_list = []

        # Get instance of BluePrint Class
        blue_print = ZCRMBluePrint()

        # Set transitionId to the BluePrint instance
        blue_print.set_transition_id(transition_id)

        # Get instance of Record Class
        data = Record()

        lookup = dict()

        lookup['id'] = '8940372937'

        data.add_key_value('Data_3', lookup)

        data.add_key_value('Phone', '8940372937')

        data.add_key_value("Notes", "Updated via blueprint")

        check_list_item = {'item1': True}

        check_list_item_2 = {'item1': True}

        check_list_item_3 = {'item1': True}

        check_lists = [check_list_item, check_list_item_2, check_list_item_3]

        data.add_key_value("CheckLists", check_lists)

        # Set data to the BluePrint instance
        blue_print.set_data(data)

        # Add BluePrint instance to the list
        blue_print_list.append(blue_print)

        # Set the list to bluePrint in BodyWrapper instance
        request.set_blueprint(blue_print_list)

        # Call update_blueprint method that takes BodyWrapper instance as parameter
        response = blue_print_operations.update_blueprint(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 SuccessResponse instance is received.
                if isinstance(response_object, SuccessResponse):

                    # 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())

                # 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())