Skip to main content

PHP SDK Samples - Blueprint Operations

Get Blueprint Details
Update Blueprint
              
              
<?php
namespace com\zoho\crm\sample\blueprint;
use com\zoho\crm\api\blueprint\BluePrintOperations;
use com\zoho\crm\api\blueprint\BodyWrapper;
use com\zoho\crm\api\blueprint\ResponseWrapper;
use com\zoho\crm\api\blueprint\APIException;
use com\zoho\crm\api\record\Record;
use com\zoho\crm\api\blueprint\SuccessResponse;
class BluePrint
{
    /**
     * Update Blueprint
     * This method is used to update a single record's Blueprint details with ID and print the response.
     * @param moduleAPIName The API Name of the record's module
     * @param recordId The ID of the record to get Blueprint
     * @param transitionId The ID of the Blueprint transition Id
     * @throws Exception
     */
    public static function updateBlueprint(string $moduleAPIName, string $recordId, string $transitionId)
    {
        //ID of the BluePrint to be updated
        //$transitionId = "34770610173096";
                
        //Get instance of BluePrintOperations Class that takes moduleAPIName and recordId as parameter
        $bluePrintOperations = new BluePrintOperations($recordId,$moduleAPIName);
        
        //Get instance of BodyWrapper Class that will contain the request body
        $bodyWrapper = new BodyWrapper();
        
        //List of BluePrint instances
        $bluePrintList = array();

        $bluePrintClass = 'com\zoho\crm\api\blueprint\BluePrint'; 
        
        //Get instance of BluePrint Class
        $bluePrint = new $bluePrintClass();
        
        //Set transition_id to the BluePrint instance
        $bluePrint->setTransitionId($transitionId);
        
        //Get instance of Record Class
        $data = new Record();

        $lookup = array();
        
        $lookup["Phone"] = "8940372937";
        
        $lookup["id"] = "8940372937";
        
        // $data->addKeyValue("Lookup_2", (object)$lookup);
        
        $data->addKeyValue("Phone", "8940372937");
        
        $data->addKeyValue("Notes", "Updated via blueprint");
        
        $attachments = array();
        
        $fileIds = array();
        
        array_push($fileIds, "blojtd2d13b5f044e4041a3315e0793fb21ef");
        
        $attachments['$file_id'] = $fileIds;
        
        $data->addKeyValue("Attachments", $attachments);
        
        $checkLists = array();
        
        $list = array();
        
        $list["list 1"] = true;
        
        array_push($checkLists, $list);
        
        $list = array();
        
        $list["list 2"] = true;
        
        array_push($checkLists, $list);
        
        $list = array();
        
        $list["list 3"] =  true;
        
        array_push($checkLists, $list);
        
        $data->addKeyValue("CheckLists", $checkLists);
        
        //Set data to the BluePrint instance
        $bluePrint->setData($data);
        
        //Add BluePrint instance to the list
        array_push($bluePrintList, $bluePrint);
       
        //Set the list to bluePrint in BodyWrapper instance
        $bodyWrapper->setBlueprint($bluePrintList);
        
        // var_dump($bodyWrapper);
        
        //Call updateBluePrint method that takes BodyWrapper instance 
        $response = $bluePrintOperations->updateBlueprint($bodyWrapper);
        
        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 $keyName => $keyValue) 
                    {
                        //Get each value in the map
                        echo($keyName . ": " . $keyValue . "\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: " );
                
                if($exception->getDetails() != null)
                {
                    //Get the details map
                    foreach ($exception->getDetails() as $keyName => $keyValue) 
                    {
                        //Get each value in the map
                        echo($keyName . ": " . $keyValue . "\n");
                    }
                }
                
                //Get the Message
                echo("Message: " . $exception->getMessage()->getValue() . "\n");
            }
        }
    }
}