PHP SDK Samples - Records Operations

Get a Record

              
<?php
namespace samples\record;

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\HeaderMap;
use com\zoho\crm\api\ParameterMap;
use com\zoho\crm\api\layouts\Layout;
use com\zoho\crm\api\record\APIException;
use com\zoho\crm\api\record\FileBodyWrapper;
use com\zoho\crm\api\record\FileDetails;
use com\zoho\crm\api\record\LineTax;
use com\zoho\crm\api\record\Participants;
use com\zoho\crm\api\record\PricingDetails;
use com\zoho\crm\api\record\RecordOperations;
use com\zoho\crm\api\record\RecurringActivity;
use com\zoho\crm\api\record\RemindAt;
use com\zoho\crm\api\record\ResponseWrapper;
use com\zoho\crm\api\tags\Tag;
use com\zoho\crm\api\record\GetRecordHeader;
use com\zoho\crm\api\record\GetRecordParam;
use com\zoho\crm\api\util\Choice;
use com\zoho\crm\api\record\Comment;
use com\zoho\crm\api\record\Consent;
use com\zoho\crm\api\attachments\Attachment;
use com\zoho\crm\api\record\ImageUpload;
use com\zoho\crm\api\users\User;
require_once "vendor/autoload.php";

class GetRecord
{
	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 getRecord(string $moduleAPIName, string $recordId, string $destinationFolder)
	{
		$recordOperations = new RecordOperations();
		$paramInstance = new ParameterMap();
		$paramInstance->add(GetRecordParam::approved(), "false");
		$paramInstance->add(GetRecordParam::converted(), "false");
		$fieldNames = array("Deal_Name", "Company");
		foreach($fieldNames as $fieldName)
		{
			$paramInstance->add(GetRecordParam::fields(), $fieldName);
        }
		$startdatetime = date_create("2020-06-27T15:10:00");
        $paramInstance->add(GetRecordParam::startDateTime(), $startdatetime);
		$enddatetime = date_create("2020-06-29T15:10:00");
		$paramInstance->add(GetRecordParam::endDateTime(), $enddatetime);
		$paramInstance->add(GetRecordParam::territoryId(), "34770613051357");
        $paramInstance->add(GetRecordParam::includeChild(), "true");
		$headerInstance = new HeaderMap();
		$ifmodifiedsince = date_create("2020-06-02T11:03:06+05:30")->setTimezone(new \DateTimeZone(date_default_timezone_get()));
		$headerInstance->add(GetRecordHeader::IfModifiedSince(), $ifmodifiedsince);
		// $headerInstance->add(GetRecordHeader::XEXTERNAL(), "Leads.External");
		$response = $recordOperations->getRecord( $recordId,$moduleAPIName,$paramInstance, $headerInstance);
		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;
			}
			if($response->isExpected())
			{
				$responseHandler = $response->getObject();
				if($responseHandler instanceof ResponseWrapper)
				{
					$responseWrapper = $responseHandler;
					$records = $responseWrapper->getData();
					if($records != null)
					{
						$recordClass = 'com\zoho\crm\api\record\Record';
						foreach($records as $record)
						{
							echo("Record ID: " . $record->getId() . "\n");
							$createdBy = $record->getCreatedBy();
							if($createdBy != null)
							{
								echo("Record Created By User-ID: " . $createdBy->getId() . "\n");
								echo("Record Created By User-Name: " . $createdBy->getName() . "\n");
								echo("Record Created By User-Email: " . $createdBy->getEmail() . "\n");
							}
							echo("Record CreatedTime: "); print_r($record->getCreatedTime()); echo("\n");
							$modifiedBy = $record->getModifiedBy();
							if($modifiedBy != null)
							{
								echo("Record Modified By User-ID: " . $modifiedBy->getId() . "\n");
								echo("Record Modified By User-Name: " . $modifiedBy->getName() . "\n");
								echo("Record Modified By User-Email: " . $modifiedBy->getEmail() . "\n");
							}
							echo("Record ModifiedTime: "); print_r($record->getModifiedTime()); echo("\n");
							$tags = $record->getTag();
							if($tags != null)
							{
								foreach($tags as $tag)
								{
									echo("Record Tag Name: " . $tag->getName() . "\n");
									echo("Record Tag ID: " . $tag->getId() . "\n");
								}
							}
							//To get particular field value
							echo("Record Field Value: " . $record->getKeyValue("Last_Name") . "\n");// FieldApiName
							echo("Record KeyValues : \n" );
							foreach($record->getKeyValues() as $keyName => $value)
							{
								if($value != null)
								{
									if((is_array($value) && sizeof($value) > 0) && isset($value[0]))
									{
										if($value[0] instanceof FileDetails)
										{
											$fileDetails = $value;
											foreach($fileDetails as $fileDetail)
											{
												echo("Record FileDetails Extn: " . $fileDetail->getExtn() . "\n");
												echo("Record FileDetails IsPreviewAvailable: " . $fileDetail->getIsPreviewAvailable() . "\n");
												echo("Record FileDetails DownloadUrl: " . $fileDetail->getDownloadUrl() . "\n");
												echo("Record FileDetails DeleteUrl: " . $fileDetail->getDeleteUrl() . "\n");
												echo("Record FileDetails EntityId: " . $fileDetail->getEntityId() . "\n");
												echo("Record FileDetails Mode: " . $fileDetail->getMode() . "\n");
												echo("Record FileDetails OriginalSizeByte: " . $fileDetail->getOriginalSizeByte() . "\n");
												echo("Record FileDetails PreviewUrl: " . $fileDetail->getPreviewUrl() . "\n");
												echo("Record FileDetails FileName: " . $fileDetail->getFileName() . "\n");
												echo("Record FileDetails FileId: " . $fileDetail->getFileId() . "\n");
												echo("Record FileDetails AttachmentId: " . $fileDetail->getAttachmentId() . "\n");
												echo("Record FileDetails FileSize: " . $fileDetail->getFileSize() . "\n");
												echo("Record FileDetails CreatorId: " . $fileDetail->getCreatorId() . "\n");
												echo("Record FileDetails LinkDocs: " . $fileDetail->getLinkDocs() . "\n");
											}
										}
										else if($value[0] instanceof Choice)
										{
											$choice = $value;
											foreach($choice as $choiceValue)
		
									{
												echo("Record " . $keyName . " : " . $choiceValue->getValue() . "\n");
											}
										}
										else if($value[0] instanceof Tag)
										{
											$tagList = $value;
											foreach($tagList as $tag)
											{
												echo("Record Tag Name: " . $tag->getName() . "\n");
												echo("Record Tag ID: " . $tag->getId() . "\n");
											}
										}
										else if($value[0] instanceof PricingDetails)
										{
											$pricingDetails = $value;
											foreach($pricingDetails as $pricingDetail)
											{
												echo("Record PricingDetails ToRange: " . $pricingDetail->getToRange(). "\n");
												echo("Record PricingDetails Discount: " . $pricingDetail->getDiscount(). "\n");
												echo("Record PricingDetails ID: " . $pricingDetail->getId() . "\n");
												echo("Record PricingDetails FromRange: " . $pricingDetail->getFromRange(). "\n");
											}
										}
										else if($value[0] instanceof Participants)
										{
											$participants = $value;
											foreach($participants as $participant)
											{
												echo("RelatedRecord Participants Name: " . $participant->getName() . "\n");
												echo("RelatedRecord Participants Invited: " . $participant->getInvited() . "\n");
												echo("RelatedRecord Participants ID: " . $participant->getId() . "\n");
												echo("RelatedRecord Participants Type: " . $participant->getType() . "\n");
												echo("RelatedRecord Participants Participant: " . $participant->getParticipant() . "\n");
												echo("RelatedRecord Participants Status: " . $participant->getStatus() . "\n");
											}
										}
										else if($value[0] instanceof $recordClass)
										{
											$recordList = $value;
											foreach($recordList as $record1)
											{
												foreach($record1->getKeyValues() as $key => $value1)
												{
													echo($key . " : " ); print_r($value1); echo("\n");
												}
											}
										}
										else if($value[0] instanceof LineTax)
										{
											$lineTaxes = $value;
											foreach($lineTaxes as $lineTax)
											{
												echo("Record ProductDetails LineTax Percentage: " . $lineTax->getPercentage(). "\n");
												echo("Record ProductDetails LineTax Name: " . $lineTax->getName() . "\n");
												echo("Record ProductDetails LineTax Id: " . $lineTax->getId() . "\n");
												echo("Record ProductDetails LineTax Value: " . $lineTax->getValue(). "\n");
											}
										}
										else if($value[0] instanceof Comment)
										{
											$comments = $value;
											foreach($comments as $comment)
											{
												echo("Record Comment CommentedBy: " . $comment->getCommentedBy() . "\n");
												echo("Record Comment CommentedTime: "); print_r($comment->getCommentedTime()); echo("\n");
												echo("Record Comment CommentContent: " . $comment->getCommentContent(). "\n");
												echo("Record Comment Id: " . $comment->getId() . "\n");
											}
										}
										else if($value[0] instanceof Attachment)
										{
											$attachments = $value;
											foreach ($attachments as $attachment)
											{
												$owner = $attachment->getOwner();
												if($owner != null)
												{
													echo("Record Attachment Owner User-Name: " . $owner->getName() . "\n");
													echo("Record Attachment Owner User-ID: " . $owner->getId() . "\n");
													echo("Record Attachment Owner User-Email: " . $owner->getEmail() . "\n");
												}
												echo("Record Attachment Modified Time: "); print_r($attachment->getModifiedTime()); echo("\n");
												echo("Record Attachment File Name: " . $attachment->getFileName() . "\n");
												echo("Record Attachment Created Time: " ); print_r($attachment->getCreatedTime()); echo("\n");
												echo("Record Attachment File Size: " . $attachment->getSize() . "\n");
												$parentId = $attachment->getParentId();
												if($parentId != null)
												{
													echo("Record Attachment parent record Name: " . $parentId->getKeyValue("name") . "\n");
													echo("Record Attachment parent record ID: " . $parentId->getId() . "\n");
												}
												echo("Record Attachment is Editable: " . $attachment->getEditable() . "\n");
												echo("Record Attachment File ID: " . $attachment->getFileId() . "\n");
												echo("Record Attachment File Type: " . $attachment->getType() . "\n");
												echo("Record Attachment seModule: " . $attachment->getSeModule() . "\n");
												$modifiedBy = $attachment->getModifiedBy();
												if($modifiedBy != null)
												{
													echo("Record Attachment Modified By User-Name: " . $modifiedBy->getName() . "\n");
													echo("Record Attachment Modified By User-ID: " . $modifiedBy->getId() . "\n");
													echo("Record Attachment Modified By User-Email: " . $modifiedBy->getEmail() . "\n");
												}
												echo("Record Attachment State: " . $attachment->getState() . "\n");
												echo("Record Attachment ID: " . $attachment->getId() . "\n");
												$createdBy = $attachment->getCreatedBy();
												if($createdBy != null)
												{
													echo("Record Attachment Created By User-Name: " . $createdBy->getName() . "\n");
													echo("Record Attachment Created By User-ID: " . $createdBy->getId() . "\n");
													echo("Record Attachment Created By User-Email: " . $createdBy->getEmail() . "\n");
												}
												echo("Record Attachment LinkUrl: " . $attachment->getLinkUrl() . "\n");
											}
										}
										else if($value[0] instanceof ImageUpload)
										{
											$imageUploads = $value;
											foreach($imageUploads as $imageUpload)
											{
												echo("Record " . $keyName . " Description: " . $imageUpload->getDescription() . "\n");
												echo("Record " . $keyName . " PreviewId: " . $imageUpload->getPreviewId() . "\n");
												echo("Record " . $keyName . " File_Name: " . $imageUpload->getFileName() . "\n");
												echo("Record " . $keyName . " State: "); print_r($imageUpload->getState()); echo("\n");
												echo("Record " . $keyName . " Size: " . $imageUpload->getSize() . "\n");
												echo("Record " . $keyName . " SequenceNumber: " . $imageUpload->getSequenceNumber() . "\n");
												echo("Record " . $keyName . " Id: " . $imageUpload->getId() . "\n");
												echo("Record " . $keyName . " FileId: " . $imageUpload->getFileId() . "\n");
											}
										}
										else
										{
											echo($keyName . " : "); print_r($value); echo("\n");
										}
									}
									else if($value instanceof Layout)
									{
										$layout = $value;
										if($layout != null)
										{
											echo("Record " . $keyName. " ID: " . $layout->getId() . "\n");
											echo("Record " . $keyName . " Name: " . $layout->getName() . "\n");
										}
									}
									else if($value instanceof User)
									{
										$user = $value;
										if($user != null)
										{
											echo("Record " . $keyName . " User-ID: " . $user->getId() . "\n");
											echo("Record " . $keyName . " User-Name: " . $user->getName() . "\n");
											echo("Record " . $keyName . " User-Email: " . $user->getEmail() . "\n");
										}
									}
									else if($value instanceof $recordClass)
									{
										$recordValue = $value;
										echo("Record " . $keyName . " ID: " . $recordValue->getId() . "\n");
										echo("Record " . $keyName . " Name: " . $recordValue->getKeyValue("name") . "\n");
									}
									else if($value instanceof Choice)
									{
										$choiceValue = $value;
										echo("Record " . $keyName . " : " . $choiceValue->getValue() . "\n");
									}
									else if($value instanceof RemindAt)
									{
										echo($keyName . ": " . $value->getAlarm() . "\n");
									}
									else if($value instanceof RecurringActivity)
									{
										echo($keyName . " : RRULE" . ": " . $value->getRrule() . "\n");
									}
									else if($value instanceof Consent)
									{
										$consent = $value;
										echo("Record Consent ID: " . $consent->getId());
										$owner = $consent->getOwner();
										if($owner != null)
										{
											echo("Record Consent Owner Name: " . $owner->getName());
											echo("Record Consent Owner ID: " . $owner->getId());
											echo("Record Consent Owner Email: " . $owner->getEmail());
										}
										$consentCreatedBy = $consent->getCreatedBy();
										if($consentCreatedBy != null)
										{
											echo("Record Consent CreatedBy Name: " . $consentCreatedBy->getName());
											echo("Record Consent CreatedBy ID: " . $consentCreatedBy->getId());
											echo("Record Consent CreatedBy Email: " . $consentCreatedBy->getEmail());
										}
										$consentModifiedBy = $consent->getModifiedBy();
										if($consentModifiedBy != null)
										{
											echo("Record Consent ModifiedBy Name: " . $consentModifiedBy->getName());
											echo("Record Consent ModifiedBy ID: " . $consentModifiedBy->getId());
											echo("Record Consent ModifiedBy Email: " . $consentModifiedBy->getEmail());
										}
										echo("Record Consent CreatedTime: " . $consent->getCreatedTime());
										echo("Record Consent ModifiedTime: " . $consent->getModifiedTime());
										echo("Record Consent ContactThroughEmail: " . $consent->getContactThroughEmail());
										echo("Record Consent ContactThroughSocial: " . $consent->getContactThroughSocial());
										echo("Record Consent ContactThroughSurvey: " . $consent->getContactThroughSurvey());
										echo("Record Consent ContactThroughPhone: " . $consent->getContactThroughPhone());
										echo("Record Consent MailSentTime: " . $consent->getMailSentTime());
										echo("Record Consent ConsentDate: " . $consent->getConsentDate());
										echo("Record Consent ConsentRemarks: " . $consent->getConsentRemarks());
										echo("Record Consent ConsentThrough: " . $consent->getConsentThrough());
										echo("Record Consent DataProcessingBasis: " . $consent->getDataProcessingBasis());
										//To get custom values
										echo("Record Consent Lawful Reason: " . $consent->getKeyValue("Lawful_Reason"));
									}
									else
									{
										echo($keyName . " : "); print_r($value); echo("\n");
									}
								}
								else
								{
									echo($keyName . " : "); print_r($value); echo("\n");
								}
							}
						}
					}
				}
				else if($responseHandler instanceof FileBodyWrapper)
				{
					$fileBodyWrapper = $responseHandler;
					$streamWrapper = $fileBodyWrapper->getFile();
					//Create a file instance with the absolute_file_path
					$fp = fopen($destinationFolder."/".$streamWrapper->getName(), "w");
					$stream = $streamWrapper->getStream();
					fputs($fp, $stream);
					fclose($fp);
				}
				else if($responseHandler instanceof APIException)
				{
					$exception = $responseHandler;
					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
			{
				print_r($response);
			}
		}
	}
}

GetRecord::initialize();
$moduleAPIName = "Leads";
$recordId = "347706112184003";
$destinationFolder = "/Desktop/";
GetRecord::getRecord($moduleAPIName, $recordId, $destinationFolder);
?>

 
Update a Record

              

<?php
namespace samples\record;

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\HeaderMap;
use com\zoho\crm\api\record\APIException;
use com\zoho\crm\api\record\ActionWrapper;
use com\zoho\crm\api\record\BodyWrapper;
use com\zoho\crm\api\record\FileDetails;
use com\zoho\crm\api\record\LineItemProduct;
use com\zoho\crm\api\record\LineTax;
use com\zoho\crm\api\record\RecordOperations;
use com\zoho\crm\api\record\SuccessResponse;
use com\zoho\crm\api\tags\Tag;
use com\zoho\crm\api\record\{ApplyFeatureExecution, Leads, Deals, Sales_Orders, Contacts, Quotes, Purchase_Orders};
use com\zoho\crm\api\record\Consent;
use com\zoho\crm\api\users\User;
require_once "vendor/autoload.php";

class UpdateRecord
{
    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 updateRecord(string $moduleAPIName, string $recordId)
	{
		$recordOperations = new RecordOperations();
		$request = new BodyWrapper();
        $records = array();
        $recordClass = 'com\zoho\crm\api\record\Record';
		$record1 = new $recordClass();
		$apply_feature_execution = new ApplyFeatureExecution();
		$apply_feature_execution->setName("layout_rules");
		$apply_feature_list = array();
		array_push($apply_feature_list,$apply_feature_execution);
		$request->setApplyFeatureExecution($apply_feature_list);
		/*
		 * Call addFieldValue method that takes two arguments
		 * 1 -> Call Field "." and choose the module from the displayed list and press "." and choose the field name from the displayed list.
		 * 2 -> Value
		*/
		$record1->addFieldValue(Leads::City(), "City");
		$record1->addFieldValue(Leads::LastName(), "Last Name");
		$record1->addFieldValue(Leads::FirstName(), "First Name");
		$record1->addFieldValue(Leads::Company(), "KKRNP");
		// $accounts = new $recordClass();
		// $accounts->addKeyValue("id", "34770615848009");
		// $record1->addFieldValue(Contacts::AccountName(), $accounts);
		/*
		 * Call addKeyValue method that takes two arguments
		 * 1 -> A string that is the Field's API Name
		 * 2 -> Value
		 */
		$record1->addKeyValue("Custom_field", "Value");
		$record1->addKeyValue("Custom_field_2", "value");
		$record1->addKeyValue("Date_1", new \DateTime('2020-03-08'));
		$record1->addKeyValue("Date_Time_2", date_create("2021-06-02T11:03:06+05:30")->setTimezone(new \DateTimeZone(date_default_timezone_get())));
		$fileDetails = array();
		$fileDetail1 = new FileDetails();
		$fileDetail1->setAttachmentId("347005");
		$fileDetail1->setDelete("null");
		array_push($fileDetails, $fileDetail1);
		$fileDetail2 = new FileDetails();
		$fileDetail2->setFileId("ae9c7cefa418aec1d6a5cc2d9ab35c32244f4e660f3702f05463e2fd0a2d8c1c");
		array_push($fileDetails, $fileDetail2);
		$fileDetail3 = new FileDetails();
		$fileDetail3->setFileId("ae9c7cefa418aec1d6a5cc2d9ab35c326a3f4c7562925ac9afc0f7433dd2098c");
		array_push($fileDetails, $fileDetail3);
		$record1->addKeyValue("File_Upload", $fileDetails);
		$recordOwner = new User();
		$recordOwner->setEmail("abc@zoho.com");
        $record1->addKeyValue("Owner", $recordOwner);
		//Used when GDPR is enabled
		$dataConsent = new Consent();
		$dataConsent->setConsentRemarks("Approved.");
		$dataConsent->setConsentThrough("Email");
		$dataConsent->setContactThroughEmail(true);
		$dataConsent->setContactThroughSocial(false);
		$record1->addKeyValue("Data_Processing_Basis_Details", $dataConsent);
		$subformList = [];
		$subform = new $recordClass();
		$subform->addKeyValue("Subform FieldAPIName", "FieldValue");
		array_push($subformList, $subform);
		$record1->addKeyValue("Subform Name", $subformList);
		
		/** Following methods are being used only by Inventory modules */
		$dealName = new $recordClass();
		$dealName->addFieldValue(Deals::id(), "3477061012112003");
		$record1->addFieldValue(Sales_Orders::DealName(), $dealName);
		$contactName = new $recordClass();
		$contactName->addFieldValue(Contacts::id(), "3477061011853001");
		$record1->addFieldValue(Purchase_Orders::ContactName(), $contactName);
		$accountName = new $recordClass();
		$accountName->addKeyValue("name", "automatedAccount");
		$record1->addFieldValue(Quotes::AccountName(), $accountName);
		$record1->addKeyValue("Discount", 10.5);
		$inventoryLineItemList = [];
		$inventoryLineItem = new $recordClass();
		$lineItemProduct = new LineItemProduct();
		$lineItemProduct->setId("3477061012107031");
		// $lineItemProduct->addKeyValue("Products_External", "AutomatedSDKExternal");
		$inventoryLineItem->addKeyValue("Description", "asd");
		$inventoryLineItem->addKeyValue("Discount", "5");
		$parentId = new $recordClass();
		$parentId->setId("35240337331017");
		// inventoryLineItem->addKeyValue("Parent_Id", 5);
		$inventoryLineItem->addKeyValue("Sequence_Number", "1");
		$lineitemProduct = new LineItemProduct();
		$lineitemProduct->setId("35240333659082");
		$inventoryLineItem->addKeyValue("Product_Name", $lineItemProduct);
		$inventoryLineItem->addKeyValue("Sequence_Number", "1");
		$inventoryLineItem->addKeyValue("Quantity",123.2);
		$inventoryLineItem->addKeyValue("Tax",123.2);
		array_push($inventoryLineItemList, $inventoryLineItem);
		$productLineTaxes = [];
		$productLineTax = new LineTax();
		$productLineTax->setName("MyT2ax1134");
		$productLineTax->setPercentage(20.0);
		array_push($productLineTaxes, $productLineTax);
		$inventoryLineItem->addKeyValue("Line_Tax", $productLineTaxes);
		array_push($inventoryLineItemList, $inventoryLineItem);
		$record1->addKeyValue("Quoted_Items", $inventoryLineItemList);
		$lineTaxes = [];
		$lineTax = new LineTax();
		$lineTax->setName("MyT2ax1134");
		$lineTax->setPercentage(20.0);
		array_push($lineTaxes, $lineTax);
		$record1->addKeyValue('$line_tax', $lineTaxes);
		/** End Inventory **/
		$tagList = [];
		$tag = new Tag();
		$tag->setName("Testtask1");
		array_push($tagList, $tag);
		$record1->setTag($tagList);
		array_push($records, $record1);
		$request->setData($records);
		$trigger = array("approval", "workflow", "blueprint");
		$request->setTrigger($trigger);
		$headerInstance = new HeaderMap();
		// $headerInstance->add(UpdateRecordHeader::XEXTERNAL(), "Quotes.Quoted_Items.Product_Name.Products_External");
		$response = $recordOperations->updateRecord($recordId, $moduleAPIName, $request, $headerInstance);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
			if($response->isExpected())
			{
				$actionHandler = $response->getObject();
				if($actionHandler instanceof ActionWrapper)
				{
					$actionWrapper = $actionHandler;
					$actionResponses = $actionWrapper->getData();
					foreach($actionResponses as $actionResponse)
					{
						if($actionResponse instanceof SuccessResponse)
						{
							$successResponse = $actionResponse;
							echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
							echo("Code: " . $successResponse->getCode()->getValue() . "\n");
							echo("Details: " );
							foreach($successResponse->getDetails() as $key => $value)
							{
								echo($key . " : ");
								print_r($value);
								echo("\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");
				}
			}
			else
			{
				print_r($response);
			}
		}
	}
}

UpdateRecord::initialize();
$moduleAPIName = "Leads";
$recordId = "347706112184003";
UpdateRecord::updateRecord($moduleAPIName, $recordId);

?>

 
Delete a Record

              
<?php
namespace samples\record;

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\HeaderMap;
use com\zoho\crm\api\ParameterMap;
use com\zoho\crm\api\record\APIException;
use com\zoho\crm\api\record\ActionWrapper;
use com\zoho\crm\api\record\RecordOperations;
use com\zoho\crm\api\record\SuccessResponse;
use com\zoho\crm\api\record\DeleteRecordParam;
use com\zoho\crm\api\record\DeleteRecordHeader;
require_once "vendor/autoload.php";

class DeleteRecord
{
    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 deleteRecord(string $moduleAPIName, string $recordId)
	{
		$recordOperations = new RecordOperations();
		$paramInstance = new ParameterMap();
		$paramInstance->add(DeleteRecordParam::wfTrigger(), false);
		$headerInstance = new HeaderMap();
		// $headerInstance->add(DeleteRecordHeader::XEXTERNAL(), "Leads.External");
		$response = $recordOperations->deleteRecord($recordId,$moduleAPIName, $paramInstance, $headerInstance);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
			if($response->isExpected())
			{
				$actionHandler = $response->getObject();
				if($actionHandler instanceof ActionWrapper)
				{
					$actionWrapper = $actionHandler;
					$actionResponses = $actionWrapper->getData();
					foreach($actionResponses as $actionResponse)
					{
						if($actionResponse instanceof SuccessResponse)
						{
							$successResponse = $actionResponse;
							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($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");
				}
			}
			else
			{
				print_r($response);
			}
		}
	}
}

DeleteRecord::initialize();
$moduleAPIName = "Leads";
$recordId = "347706118042013";
DeleteRecord::deleteRecord($moduleAPIName, $recordId);
?>

 
Get Record Using External ID

              
<?php
namespace samples\record;

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\HeaderMap;
use com\zoho\crm\api\ParameterMap;
use com\zoho\crm\api\layouts\Layout;
use com\zoho\crm\api\record\APIException;
use com\zoho\crm\api\record\FileBodyWrapper;
use com\zoho\crm\api\record\FileDetails;
use com\zoho\crm\api\record\LineTax;
use com\zoho\crm\api\record\Participants;
use com\zoho\crm\api\record\PricingDetails;
use com\zoho\crm\api\record\RecordOperations;
use com\zoho\crm\api\record\RecurringActivity;
use com\zoho\crm\api\record\RemindAt;
use com\zoho\crm\api\record\ResponseWrapper;
use com\zoho\crm\api\tags\Tag;
use com\zoho\crm\api\record\GetRecordHeader;
use com\zoho\crm\api\record\GetRecordParam;
use com\zoho\crm\api\util\Choice;
use com\zoho\crm\api\record\Comment;
use com\zoho\crm\api\record\Consent;
use com\zoho\crm\api\attachments\Attachment;
use com\zoho\crm\api\record\ImageUpload;
use com\zoho\crm\api\users\User;
require_once "vendor/autoload.php";

class GetRecordUsingExternalId
{
    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 getRecordUsingExternalId(string $moduleAPIName, string $externalFieldValue, string $destinationFolder)
	{
		$recordOperations = new RecordOperations();
		$paramInstance = new ParameterMap();
		$paramInstance->add(GetRecordParam::approved(), "false");
		$paramInstance->add(GetRecordParam::converted(), "false");
		$fieldNames = array("Deal_Name", "Company");
		foreach($fieldNames as $fieldName)
		{
			$paramInstance->add(GetRecordParam::fields(), $fieldName);
        }
		$startdatetime = date_create("2020-06-27T15:10:00");
        $paramInstance->add(GetRecordParam::startDateTime(), $startdatetime);
		$enddatetime = date_create("2020-06-29T15:10:00");
		$paramInstance->add(GetRecordParam::endDateTime(), $enddatetime);
		$paramInstance->add(GetRecordParam::territoryId(), "34770613051357");
        $paramInstance->add(GetRecordParam::includeChild(), "true");
		$headerInstance = new HeaderMap();
		$ifmodifiedsince = date_create("2020-06-02T11:03:06+05:30")->setTimezone(new \DateTimeZone(date_default_timezone_get()));
		$headerInstance->add(GetRecordHeader::IfModifiedSince(), $ifmodifiedsince);
		$headerInstance->add(GetRecordHeader::XEXTERNAL(), "Leads.External");
		$response = $recordOperations->getRecordUsingExternalId($externalFieldValue, $moduleAPIName, $paramInstance, $headerInstance);
		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;
			}
			if($response->isExpected())
			{
				$responseHandler = $response->getObject();
				if($responseHandler instanceof ResponseWrapper)
				{
					$responseWrapper = $responseHandler;
					$records = $responseWrapper->getData();
					if($records != null)
					{
						$recordClass = 'com\zoho\crm\api\record\Record';
						foreach($records as $record)
						{
							echo("Record ID: " . $record->getId() . "\n");
							$createdBy = $record->getCreatedBy();
							if($createdBy != null)
							{
								echo("Record Created By User-ID: " . $createdBy->getId() . "\n");
								echo("Record Created By User-Name: " . $createdBy->getName() . "\n");
								echo("Record Created By User-Email: " . $createdBy->getEmail() . "\n");
							}
							echo("Record CreatedTime: "); print_r($record->getCreatedTime()); echo("\n");
							$modifiedBy = $record->getModifiedBy();
							if($modifiedBy != null)
							{
								echo("Record Modified By User-ID: " . $modifiedBy->getId() . "\n");
								echo("Record Modified By User-Name: " . $modifiedBy->getName() . "\n");
								echo("Record Modified By User-Email: " . $modifiedBy->getEmail() . "\n");
							}
							echo("Record ModifiedTime: "); print_r($record->getModifiedTime()); echo("\n");
							$tags = $record->getTag();
							if($tags != null)
							{
								foreach($tags as $tag)
								{
									echo("Record Tag Name: " . $tag->getName() . "\n");
									echo("Record Tag ID: " . $tag->getId() . "\n");
								}
							}
							//To get particular field value
							echo("Record Field Value: " . $record->getKeyValue("Last_Name") . "\n");// FieldApiName
							echo("Record KeyValues : \n" );
							foreach($record->getKeyValues() as $keyName => $value)
							{
								if($value != null)
								{
									if((is_array($value) && sizeof($value) > 0) && isset($value[0]))
									{
										if($value[0] instanceof FileDetails)
										{
											$fileDetails = $value;
											foreach($fileDetails as $fileDetail)
											{
												echo("Record FileDetails Extn: " . $fileDetail->getExtn() . "\n");
												echo("Record FileDetails IsPreviewAvailable: " . $fileDetail->getIsPreviewAvailable() . "\n");
												echo("Record FileDetails DownloadUrl: " . $fileDetail->getDownloadUrl() . "\n");
												echo("Record FileDetails DeleteUrl: " . $fileDetail->getDeleteUrl() . "\n");
												echo("Record FileDetails EntityId: " . $fileDetail->getEntityId() . "\n");
												echo("Record FileDetails Mode: " . $fileDetail->getMode() . "\n");
												echo("Record FileDetails OriginalSizeByte: " . $fileDetail->getOriginalSizeByte() . "\n");
												echo("Record FileDetails PreviewUrl: " . $fileDetail->getPreviewUrl() . "\n");
												echo("Record FileDetails FileName: " . $fileDetail->getFileName() . "\n");
												echo("Record FileDetails FileId: " . $fileDetail->getFileId() . "\n");
												echo("Record FileDetails AttachmentId: " . $fileDetail->getAttachmentId() . "\n");
												echo("Record FileDetails FileSize: " . $fileDetail->getFileSize() . "\n");
												echo("Record FileDetails CreatorId: " . $fileDetail->getCreatorId() . "\n");
												echo("Record FileDetails LinkDocs: " . $fileDetail->getLinkDocs() . "\n");
											}
										}
										else if($value[0] instanceof Choice)
										{
											$choice = $value;
											foreach($choice as $choiceValue)
											{
												echo("Record " . $keyName . " : " . $choiceValue->getValue() . "\n");
											}
										}
										else if($value[0] instanceof Tag)
										{
											$tagList = $value;
											foreach($tagList as $tag)
											{
												echo("Record Tag Name: " . $tag->getName() . "\n");
												echo("Record Tag ID: " . $tag->getId() . "\n");
											}
										}
										else if($value[0] instanceof PricingDetails)
										{
											$pricingDetails = $value;
											foreach($pricingDetails as $pricingDetail)
											{
												echo("Record PricingDetails ToRange: " . $pricingDetail->getToRange(). "\n");
												echo("Record PricingDetails Discount: " . $pricingDetail->getDiscount(). "\n");
												echo("Record PricingDetails ID: " . $pricingDetail->getId() . "\n");
												echo("Record PricingDetails FromRange: " . $pricingDetail->getFromRange(). "\n");
											}
										}
										else if($value[0] instanceof Participants)
										{
											$participants = $value;
											foreach($participants as $participant)
											{
												echo("RelatedRecord Participants Name: " . $participant->getName() . "\n");
												echo("RelatedRecord Participants Invited: " . $participant->getInvited() . "\n");
												echo("RelatedRecord Participants ID: " . $participant->getId() . "\n");
												echo("RelatedRecord Participants Type: " . $participant->getType() . "\n");
												echo("RelatedRecord Participants Participant: " . $participant->getParticipant() . "\n");
												echo("RelatedRecord Participants Status: " . $participant->getStatus() . "\n");
											}
										}
										else if($value[0] instanceof $recordClass)
										{
											$recordList = $value;
											foreach($recordList as $record1)
											{
												foreach($record1->getKeyValues() as $key => $value1)
												{
													echo($key . " : " ); print_r($value1); echo("\n");
												}
											}
										}
										else if($value[0] instanceof LineTax)
										{
											$lineTaxes = $value;
											foreach($lineTaxes as $lineTax)
											{
												echo("Record ProductDetails LineTax Percentage: " . $lineTax->getPercentage(). "\n");
												echo("Record ProductDetails LineTax Name: " . $lineTax->getName() . "\n");
												echo("Record ProductDetails LineTax Id: " . $lineTax->getId() . "\n");
												echo("Record ProductDetails LineTax Value: " . $lineTax->getValue(). "\n");
											}
										}
										else if($value[0] instanceof Comment)
										{
											$comments = $value;
											foreach($comments as $comment)
											{
												echo("Record Comment CommentedBy: " . $comment->getCommentedBy() . "\n");
												echo("Record Comment CommentedTime: "); print_r($comment->getCommentedTime()); echo("\n");
												echo("Record Comment CommentContent: " . $comment->getCommentContent(). "\n");
												echo("Record Comment Id: " . $comment->getId() . "\n");
											}
										}
										else if($value[0] instanceof Attachment)
										{
											$attachments = $value;
											foreach ($attachments as $attachment)
											{
												$owner = $attachment->getOwner();
												if($owner != null)
												{
													echo("Record Attachment Owner User-Name: " . $owner->getName() . "\n");
													echo("Record Attachment Owner User-ID: " . $owner->getId() . "\n");
													echo("Record Attachment Owner User-Email: " . $owner->getEmail() . "\n");
												}
												echo("Record Attachment Modified Time: "); print_r($attachment->getModifiedTime()); echo("\n");
												echo("Record Attachment File Name: " . $attachment->getFileName() . "\n");
												echo("Record Attachment Created Time: " ); print_r($attachment->getCreatedTime()); echo("\n");
												echo("Record Attachment File Size: " . $attachment->getSize() . "\n");
												$parentId = $attachment->getParentId();
												if($parentId != null)
												{
													echo("Record Attachment parent record Name: " . $parentId->getKeyValue("name") . "\n");
													echo("Record Attachment parent record ID: " . $parentId->getId() . "\n");
												}
												echo("Record Attachment is Editable: " . $attachment->getEditable() . "\n");
												echo("Record Attachment File ID: " . $attachment->getFileId() . "\n");
												echo("Record Attachment File Type: " . $attachment->getType() . "\n");
												echo("Record Attachment seModule: " . $attachment->getSeModule() . "\n");
												$modifiedBy = $attachment->getModifiedBy();
												if($modifiedBy != null)
												{
													echo("Record Attachment Modified By User-Name: " . $modifiedBy->getName() . "\n");
													echo("Record Attachment Modified By User-ID: " . $modifiedBy->getId() . "\n");
													echo("Record Attachment Modified By User-Email: " . $modifiedBy->getEmail() . "\n");
												}
												echo("Record Attachment State: " . $attachment->getState() . "\n");
												echo("Record Attachment ID: " . $attachment->getId() . "\n");
												$createdBy = $attachment->getCreatedBy();
												if($createdBy != null)
												{
													echo("Record Attachment Created By User-Name: " . $createdBy->getName() . "\n");
													echo("Record Attachment Created By User-ID: " . $createdBy->getId() . "\n");
													echo("Record Attachment Created By User-Email: " . $createdBy->getEmail() . "\n");
												}
												echo("Record Attachment LinkUrl: " . $attachment->getLinkUrl() . "\n");
											}
										}
										else if($value[0] instanceof ImageUpload)
										{
											$imageUploads = $value;
											foreach($imageUploads as $imageUpload)
											{
												echo("Record " . $keyName . " Description: " . $imageUpload->getDescription() . "\n");
												echo("Record " . $keyName . " PreviewId: " . $imageUpload->getPreviewId() . "\n");
												echo("Record " . $keyName . " File_Name: " . $imageUpload->getFileName() . "\n");
												echo("Record " . $keyName . " State: "); print_r($imageUpload->getState()); echo("\n");
												echo("Record " . $keyName . " Size: " . $imageUpload->getSize() . "\n");
												echo("Record " . $keyName . " SequenceNumber: " . $imageUpload->getSequenceNumber() . "\n");
												echo("Record " . $keyName . " Id: " . $imageUpload->getId() . "\n");
												echo("Record " . $keyName . " FileId: " . $imageUpload->getFileId() . "\n");
											}
										}
										else
										{
											echo($keyName . " : "); print_r($value); echo("\n");
										}
									}
									else if($value instanceof Layout)
									{
										$layout = $value;
										if($layout != null)
										{
											echo("Record " . $keyName. " ID: " . $layout->getId() . "\n");
											echo("Record " . $keyName . " Name: " . $layout->getName() . "\n");
										}
									}
									else if($value instanceof User)
									{
										$user = $value;
										if($user != null)
										{
											echo("Record " . $keyName . " User-ID: " . $user->getId() . "\n");
											echo("Record " . $keyName . " User-Name: " . $user->getName() . "\n");
											echo("Record " . $keyName . " User-Email: " . $user->getEmail() . "\n");
										}
									}
									else if($value instanceof $recordClass)
									{
										$recordValue = $value;
										echo("Record " . $keyName . " ID: " . $recordValue->getId() . "\n");
										echo("Record " . $keyName . " Name: " . $recordValue->getKeyValue("name") . "\n");
									}
									else if($value instanceof Choice)
									{
										$choiceValue = $value;
										echo("Record " . $keyName . " : " . $choiceValue->getValue() . "\n");
									}
									else if($value instanceof RemindAt)
									{
										echo($keyName . ": " . $value->getAlarm() . "\n");
									}
									else if($value instanceof RecurringActivity)
									{
										echo($keyName . " : RRULE" . ": " . $value->getRrule() . "\n");
									}
									else if($value instanceof Consent)
									{
										$consent = $value;
										echo("Record Consent ID: " . $consent->getId());
										$owner = $consent->getOwner();
										if($owner != null)
										{
											echo("Record Consent Owner Name: " . $owner->getName());
											echo("Record Consent Owner ID: " . $owner->getId());
											echo("Record Consent Owner Email: " . $owner->getEmail());
										}
										$consentCreatedBy = $consent->getCreatedBy();
										if($consentCreatedBy != null)
										{
											echo("Record Consent CreatedBy Name: " . $consentCreatedBy->getName());
											echo("Record Consent CreatedBy ID: " . $consentCreatedBy->getId());
											echo("Record Consent CreatedBy Email: " . $consentCreatedBy->getEmail());
										}
										$consentModifiedBy = $consent->getModifiedBy();
										if($consentModifiedBy != null)
										{
											echo("Record Consent ModifiedBy Name: " . $consentModifiedBy->getName());
											echo("Record Consent ModifiedBy ID: " . $consentModifiedBy->getId());
											echo("Record Consent ModifiedBy Email: " . $consentModifiedBy->getEmail());
										}
										echo("Record Consent CreatedTime: " . $consent->getCreatedTime());
										echo("Record Consent ModifiedTime: " . $consent->getModifiedTime());
										echo("Record Consent ContactThroughEmail: " . $consent->getContactThroughEmail());
										echo("Record Consent ContactThroughSocial: " . $consent->getContactThroughSocial());
										echo("Record Consent ContactThroughSurvey: " . $consent->getContactThroughSurvey());
										echo("Record Consent ContactThroughPhone: " . $consent->getContactThroughPhone());
										echo("Record Consent MailSentTime: " . $consent->getMailSentTime());
										echo("Record Consent ConsentDate: " . $consent->getConsentDate());
										echo("Record Consent ConsentRemarks: " . $consent->getConsentRemarks());
										echo("Record Consent ConsentThrough: " . $consent->getConsentThrough());
										echo("Record Consent DataProcessingBasis: " . $consent->getDataProcessingBasis());
										//To get custom values
										echo("Record Consent Lawful Reason: " . $consent->getKeyValue("Lawful_Reason"));
									}
									else
									{
										echo($keyName . " : "); print_r($value); echo("\n");
									}
								}
								else
								{
									echo($keyName . " : "); print_r($value); echo("\n");
								}
							}
						}
					}
				}
				else if($responseHandler instanceof FileBodyWrapper)
				{
					$fileBodyWrapper = $responseHandler;
					$streamWrapper = $fileBodyWrapper->getFile();
					//Create a file instance with the absolute_file_path
					$fp = fopen($destinationFolder."/".$streamWrapper->getName(), "w");
					$stream = $streamWrapper->getStream();
					fputs($fp, $stream);
					fclose($fp);
				}
				else if($responseHandler instanceof APIException)
				{
					$exception = $responseHandler;
					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
			{
				print_r($response);
			}
		}
	}
}

GetRecordUsingExternalId::initialize();
$moduleAPIName = "Leads";
$externalFieldValue = "TestExternal";
$destinationFolder = "/Desktop/";
GetRecordUsingExternalId::getRecordUsingExternalId($moduleAPIName, $externalFieldValue, $destinationFolder);
?>

 
Update Record Using External ID

              
<?php
namespace samples\record;

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\HeaderMap;
use com\zoho\crm\api\record\APIException;
use com\zoho\crm\api\record\ActionWrapper;
use com\zoho\crm\api\record\BodyWrapper;
use com\zoho\crm\api\record\FileDetails;
use com\zoho\crm\api\record\LineItemProduct;
use com\zoho\crm\api\record\LineTax;
use com\zoho\crm\api\record\RecordOperations;
use com\zoho\crm\api\record\SuccessResponse;
use com\zoho\crm\api\tags\Tag;
use com\zoho\crm\api\record\{Leads, Deals, Sales_Orders, Contacts, Quotes, Purchase_Orders};
use com\zoho\crm\api\record\Consent;
use com\zoho\crm\api\users\User;
use com\zoho\crm\api\record\UpdateRecordHeader;
require_once "vendor/autoload.php";

class UpdateRecordUsingExternalId
{
    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 updateRecordUsingExternalId(string $moduleAPIName, string $externalFieldValue)
	{
		$recordOperations = new RecordOperations();
		$request = new BodyWrapper();
        $records = array();
        $recordClass = 'com\zoho\crm\api\record\Record';
		$record1 = new $recordClass();
		/*
		 * Call addFieldValue method that takes two arguments
		 * 1 -> Call Field "." and choose the module from the displayed list and press "." and choose the field name from the displayed list.
		 * 2 -> Value
		*/
		$record1->addFieldValue(Leads::City(), "City");
		$record1->addFieldValue(Leads::LastName(), "Last Name");
		$record1->addFieldValue(Leads::FirstName(), "First Name");
		$record1->addFieldValue(Leads::Company(), "KKRNP");
		// $accounts = new $recordClass();
		// $accounts->addKeyValue("id", "34770615848009");
		// $record1->addFieldValue(Contacts::AccountName(), $accounts);
		/*
		 * Call addKeyValue method that takes two arguments
		 * 1 -> A string that is the Field's API Name
		 * 2 -> Value
		 */
		$record1->addKeyValue("Custom_field", "Value");
		$record1->addKeyValue("Custom_field_2", "value");
		$record1->addKeyValue("Date_1", new \DateTime('2020-03-08'));
		$record1->addKeyValue("Date_Time_2", date_create("2021-06-02T11:03:06+05:30")->setTimezone(new \DateTimeZone(date_default_timezone_get())));
		$fileDetails = array();
		$fileDetail1 = new FileDetails();
		$fileDetail1->setAttachmentId("347005");
		$fileDetail1->setDelete("null");
		array_push($fileDetails, $fileDetail1);
		$fileDetail2 = new FileDetails();
		$fileDetail2->setFileId("ae9c7cefa418aec1d6a5cc2d9ab35c32244f4e660f3702f05463e2fd0a2d8c1c");
		array_push($fileDetails, $fileDetail2);
		$fileDetail3 = new FileDetails();
		$fileDetail3->setFileId("ae9c7cefa418aec1d6a5cc2d9ab35c326a3f4c7562925ac9afc0f7433dd2098c");
		array_push($fileDetails, $fileDetail3);
		$record1->addKeyValue("File_Upload", $fileDetails);
		$recordOwner = new User();
		$recordOwner->setEmail("abc@zoho.com");
        $record1->addKeyValue("Owner", $recordOwner);

		//Used when GDPR is enabled
		$dataConsent = new Consent();
		$dataConsent->setConsentRemarks("Approved.");
		$dataConsent->setConsentThrough("Email");
		$dataConsent->setContactThroughEmail(true);
		$dataConsent->setContactThroughSocial(false);
		$record1->addKeyValue("Data_Processing_Basis_Details", $dataConsent);
		$subformList = [];
		$subform = new $recordClass();
		$subform->addKeyValue("Subform FieldAPIName", "FieldValue");
		array_push($subformList, $subform);
		$record1->addKeyValue("Subform Name", $subformList);

		/** Following methods are being used only by Inventory modules */
		$dealName = new $recordClass();
		$dealName->addFieldValue(Deals::id(), "3477061012112003");
		$record1->addFieldValue(Sales_Orders::DealName(), $dealName);
		$contactName = new $recordClass();
		$contactName->addFieldValue(Contacts::id(), "3477061011853001");
		$record1->addFieldValue(Purchase_Orders::ContactName(), $contactName);
		$accountName = new $recordClass();
		$accountName->addKeyValue("name", "automatedAccount");
		$record1->addFieldValue(Quotes::AccountName(), $accountName);
		$record1->addKeyValue("Discount", 10.5);
		$inventoryLineItemList = [];
		$inventoryLineItem = new $recordClass();
		$lineItemProduct = new LineItemProduct();
		$lineItemProduct->setId("3477061012107031");
		$lineItemProduct->addKeyValue("Products_External", "AutomatedSDKExternal");
		$inventoryLineItem->addKeyValue("Description", "asd");
		$inventoryLineItem->addKeyValue("Discount", "5");
		$parentId = new $recordClass();
		$parentId->setId("35240337331017");
		// inventoryLineItem->addKeyValue("Parent_Id", 5);
		$inventoryLineItem->addKeyValue("Sequence_Number", "1");
		$lineitemProduct = new LineItemProduct();
		$lineitemProduct->setId("35240333659082");
		$inventoryLineItem->addKeyValue("Product_Name", $lineItemProduct);
		$inventoryLineItem->addKeyValue("Sequence_Number", "1");
		$inventoryLineItem->addKeyValue("Quantity",123.2);
		$inventoryLineItem->addKeyValue("Tax",123.2);
		array_push($inventoryLineItemList, $inventoryLineItem);
		$productLineTaxes = [];
		$productLineTax = new LineTax();
		$productLineTax->setName("MyT2ax1134");
		$productLineTax->setPercentage(20.0);
		array_push($productLineTaxes, $productLineTax);
		$inventoryLineItem->addKeyValue("Line_Tax", $productLineTaxes);
		array_push($inventoryLineItemList, $inventoryLineItem);
		$record1->addKeyValue("Quoted_Items", $inventoryLineItemList);
		$lineTaxes = [];
		$lineTax = new LineTax();
		$lineTax->setName("MyT2ax1134");
		$lineTax->setPercentage(20.0);
		array_push($lineTaxes, $lineTax);
		$record1->addKeyValue('$line_tax', $lineTaxes);
		/** End Inventory **/
		$tagList = [];
		$tag = new Tag();
		$tag->setName("Testtask1");
		array_push($tagList, $tag);
		$record1->setTag($tagList);
		//Add Record instance to the list
		array_push($records, $record1);
		$request->setData($records);
		$trigger = array("approval", "workflow", "blueprint");
		$request->setTrigger($trigger);
		$headerInstance = new HeaderMap();
		$headerInstance->add(UpdateRecordHeader::XEXTERNAL(), "Quotes.Quoted_Items.Product_Name.Products_External");
		$response = $recordOperations->updateRecordUsingExternalId($externalFieldValue, $moduleAPIName, $request, $headerInstance);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
			if($response->isExpected())
			{
				$actionHandler = $response->getObject();
				if($actionHandler instanceof ActionWrapper)
				{
					$actionWrapper = $actionHandler;
					$actionResponses = $actionWrapper->getData();
					foreach($actionResponses as $actionResponse)
					{
						if($actionResponse instanceof SuccessResponse)
						{
							$successResponse = $actionResponse;
							echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
							echo("Code: " . $successResponse->getCode()->getValue() . "\n");
							echo("Details: " );
							foreach($successResponse->getDetails() as $key => $value)
							{
								echo($key . " : ");
								print_r($value);
								echo("\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");
				}
			}
			else
			{
				print_r($response);
			}
		}
	}
}

UpdateRecordUsingExternalId::initialize();
$moduleAPIName = "Quotes";
$externalFieldValue = "TestExternal";
UpdateRecordUsingExternalId::updateRecordUsingExternalId($moduleAPIName, $externalFieldValue);
?>
Delete Record Using External ID

              
<?php
namespace samples\record;

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\HeaderMap;
use com\zoho\crm\api\ParameterMap;
use com\zoho\crm\api\record\APIException;
use com\zoho\crm\api\record\ActionWrapper;
use com\zoho\crm\api\record\RecordOperations;
use com\zoho\crm\api\record\SuccessResponse;
use com\zoho\crm\api\record\DeleteRecordParam;
use com\zoho\crm\api\record\DeleteRecordHeader;
require_once "vendor/autoload.php";

class DeleteRecordUsingExternalId
{
    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 deleteRecordUsingExternalId(string $moduleAPIName, string $externalFieldValue)
	{
		$recordOperations = new RecordOperations();
		$paramInstance = new ParameterMap();
		$paramInstance->add(DeleteRecordParam::wfTrigger(), false);
		$headerInstance = new HeaderMap();
		$headerInstance->add(DeleteRecordHeader::XEXTERNAL(), "Leads.External");
		$response = $recordOperations->deleteRecordUsingExternalId($externalFieldValue, $moduleAPIName, $paramInstance, $headerInstance);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
			if($response->isExpected())
			{
				$actionHandler = $response->getObject();
				if($actionHandler instanceof ActionWrapper)
				{
					$actionWrapper = $actionHandler;
					$actionResponses = $actionWrapper->getData();
					foreach($actionResponses as $actionResponse)
					{
						if($actionResponse instanceof SuccessResponse)
						{
							$successResponse = $actionResponse;
							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($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");
				}
			}
			else
			{
				print_r($response);
			}
		}
	}
}

DeleteRecordUsingExternalId::initialize();
$moduleAPIName = "Leads";
$externalFieldValue = "TestExternal";
DeleteRecordUsingExternalId::deleteRecordUsingExternalId($moduleAPIName, $externalFieldValue);
?>
 
Get All Records of a Module

              <?php
namespace samples\record;

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\HeaderMap;
use com\zoho\crm\api\ParameterMap;
use com\zoho\crm\api\layouts\Layout;
use com\zoho\crm\api\record\APIException;
use com\zoho\crm\api\record\FileDetails;
use com\zoho\crm\api\record\LineTax;
use com\zoho\crm\api\record\Participants;
use com\zoho\crm\api\record\PricingDetails;
use com\zoho\crm\api\record\RecordOperations;
use com\zoho\crm\api\record\RecurringActivity;
use com\zoho\crm\api\record\RemindAt;
use com\zoho\crm\api\record\ResponseWrapper;
use com\zoho\crm\api\tags\Tag;
use com\zoho\crm\api\record\GetRecordsHeader;
use com\zoho\crm\api\record\GetRecordsParam;
use com\zoho\crm\api\util\Choice;
use com\zoho\crm\api\record\Comment;
use com\zoho\crm\api\record\Consent;
use com\zoho\crm\api\attachments\Attachment;
use com\zoho\crm\api\record\ImageUpload;
use com\zoho\crm\api\users\User;
require_once "vendor/autoload.php";

class GetRecords
{
    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 getRecords(string $moduleAPIName)
	{
		$recordOperations = new RecordOperations();
		$paramInstance = new ParameterMap();
		$paramInstance->add(GetRecordsParam::approved(), "true");
		$paramInstance->add(GetRecordsParam::converted(), "1234");
		$paramInstance->add(GetRecordsParam::cvid(), "34770610089005");
		$ids = array("TestExternalLead111", "34770614352001");
		foreach($ids as $id)
		{
			$paramInstance->add(GetRecordsParam::ids(), $id);
		}
		$paramInstance->add(GetRecordsParam::uid(), "34770615181008");
		$fieldNames = array("Last_Name", "City");
		foreach($fieldNames as $fieldName)
		{
			$paramInstance->add(GetRecordsParam::fields(), "id");
		}
		$paramInstance->add(GetRecordsParam::sortBy(), "Email");
		$paramInstance->add(GetRecordsParam::sortOrder(), "desc");
		$paramInstance->add(GetRecordsParam::page(), 1);
		$paramInstance->add(GetRecordsParam::perPage(), 3);
		$startdatetime = date_create("2020-06-27T15:10:00+05:30")->setTimezone(new \DateTimeZone(date_default_timezone_get()));
		$paramInstance->add(GetRecordsParam::startDateTime(), $startdatetime);
		$enddatetime = date_create("2020-06-29T15:10:00+05:30")->setTimezone(new \DateTimeZone(date_default_timezone_get()));
		$paramInstance->add(GetRecordsParam::endDateTime(), $enddatetime);
		$paramInstance->add(GetRecordsParam::territoryId(), "34770613051357");
		$paramInstance->add(GetRecordsParam::includeChild(), "true");
		$headerInstance = new HeaderMap();
		$datetime = date_create("2021-02-26T15:28:34+05:30")->setTimezone(new \DateTimeZone(date_default_timezone_get()));
		$headerInstance->add(GetRecordsHeader::IfModifiedSince(), $datetime);
		// $headerInstance->add(GetRecordsHeader::XEXTERNAL(), "Leads.External");
		$response = $recordOperations->getRecords($moduleAPIName, $paramInstance, $headerInstance);
		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;
			}
			if($response->isExpected())
			{
				$responseHandler = $response->getObject();
				if($responseHandler instanceof ResponseWrapper)
				{
					$responseWrapper = $responseHandler;
					$records = $responseWrapper->getData();
					if($records != null)
					{
						$recordClass = 'com\zoho\crm\api\record\Record';
						foreach($records as $record)
						{
							echo("Record ID: " . $record->getId() . "\n");
							$createdBy = $record->getCreatedBy();
							if($createdBy != null)
							{
								echo("Record Created By User-ID: " . $createdBy->getId() . "\n");
								echo("Record Created By User-Name: " . $createdBy->getName() . "\n");
								echo("Record Created By User-Email: " . $createdBy->getEmail() . "\n");
							}
							echo("Record CreatedTime: "); print_r($record->getCreatedTime()); echo("\n");
							$modifiedBy = $record->getModifiedBy();
							if($modifiedBy != null)
							{
								echo("Record Modified By User-ID: " . $modifiedBy->getId() . "\n");
								echo("Record Modified By User-Name: " . $modifiedBy->getName() . "\n");
								echo("Record Modified By User-Email: " . $modifiedBy->getEmail() . "\n");
							}
							echo("Record ModifiedTime: "); print_r($record->getModifiedTime()); echo("\n");
							$tags = $record->getTag();
							if($tags != null)
							{
								foreach($tags as $tag)
								{
									echo("Record Tag Name: " . $tag->getName() . "\n");
									echo("Record Tag ID: " . $tag->getId() . "\n");
								}
							}
							//To get particular field value
							echo("Record Field Value: " . $record->getKeyValue("Last_Name") . "\n");// FieldApiName
							echo("Record KeyValues : \n" );
							foreach($record->getKeyValues() as $keyName => $value)
							{
								if($value != null)
								{
									if((is_array($value) && sizeof($value) > 0) && isset($value[0]))
									{
										if($value[0] instanceof FileDetails)
										{
											$fileDetails = $value;
											foreach($fileDetails as $fileDetail)
											{
												echo("Record FileDetails Extn: " . $fileDetail->getExtn() . "\n");
												echo("Record FileDetails IsPreviewAvailable: " . $fileDetail->getIsPreviewAvailable() . "\n");
												echo("Record FileDetails DownloadUrl: " . $fileDetail->getDownloadUrl() . "\n");
												echo("Record FileDetails DeleteUrl: " . $fileDetail->getDeleteUrl() . "\n");
												echo("Record FileDetails EntityId: " . $fileDetail->getEntityId() . "\n");
												echo("Record FileDetails Mode: " . $fileDetail->getMode() . "\n");
												echo("Record FileDetails OriginalSizeByte: " . $fileDetail->getOriginalSizeByte() . "\n");
												echo("Record FileDetails PreviewUrl: " . $fileDetail->getPreviewUrl() . "\n");
												echo("Record FileDetails FileName: " . $fileDetail->getFileName() . "\n");
												echo("Record FileDetails FileId: " . $fileDetail->getFileId() . "\n");
												echo("Record FileDetails AttachmentId: " . $fileDetail->getAttachmentId() . "\n");
												echo("Record FileDetails FileSize: " . $fileDetail->getFileSize() . "\n");
												echo("Record FileDetails CreatorId: " . $fileDetail->getCreatorId() . "\n");
												echo("Record FileDetails LinkDocs: " . $fileDetail->getLinkDocs() . "\n");
											}
										}
										else if($value[0] instanceof Choice)
										{
											$choice = $value;
											foreach($choice as $choiceValue)
											{
												echo("Record " . $keyName . " : " . $choiceValue->getValue() . "\n");
											}
										}
										else if($value[0] instanceof Tag)
										{
											$tagList = $value;
											foreach($tagList as $tag)
											{
												echo("Record Tag Name: " . $tag->getName() . "\n");
												echo("Record Tag ID: " . $tag->getId() . "\n");
											}
										}
										else if($value[0] instanceof PricingDetails)
										{
											$pricingDetails = $value;
											foreach($pricingDetails as $pricingDetail)
											{
												echo("Record PricingDetails ToRange: " . $pricingDetail->getToRange(). "\n");
												echo("Record PricingDetails Discount: " . $pricingDetail->getDiscount(). "\n");
												echo("Record PricingDetails ID: " . $pricingDetail->getId() . "\n");
												echo("Record PricingDetails FromRange: " . $pricingDetail->getFromRange(). "\n");
											}
										}
										else if($value[0] instanceof Participants)
										{
											$participants = $value;
											foreach($participants as $participant)
											{
												echo("RelatedRecord Participants Name: " . $participant->getName() . "\n");
												echo("RelatedRecord Participants Invited: " . $participant->getInvited() . "\n");
												echo("RelatedRecord Participants ID: " . $participant->getId() . "\n");
												echo("RelatedRecord Participants Type: " . $participant->getType() . "\n");
												echo("RelatedRecord Participants Participant: " . $participant->getParticipant() . "\n");
												echo("RelatedRecord Participants Status: " . $participant->getStatus() . "\n");
											}
										}
										else if($value[0] instanceof $recordClass)
										{
											$recordList = $value;
											foreach($recordList as $record1)
											{
												foreach($record1->getKeyValues() as $key => $value1)
												{
													echo($key . " : " ); print_r($value1); echo("\n");
												}
											}
										}
										else if($value[0] instanceof LineTax)
										{
											$lineTaxes = $value;
											foreach($lineTaxes as $lineTax)
											{
												echo("Record ProductDetails LineTax Percentage: " . $lineTax->getPercentage(). "\n");
												echo("Record ProductDetails LineTax Name: " . $lineTax->getName() . "\n");
												echo("Record ProductDetails LineTax Id: " . $lineTax->getId() . "\n");
												echo("Record ProductDetails LineTax Value: " . $lineTax->getValue(). "\n");
											}
										}
										else if($value[0] instanceof Comment)
										{
											$comments = $value;
											foreach($comments as $comment)
											{
												echo("Record Comment CommentedBy: " . $comment->getCommentedBy() . "\n");
												echo("Record Comment CommentedTime: "); print_r($comment->getCommentedTime()); echo("\n");
												echo("Record Comment CommentContent: " . $comment->getCommentContent(). "\n");
												echo("Record Comment Id: " . $comment->getId() . "\n");
											}
										}
										else if($value[0] instanceof Attachment)
										{
											$attachments = $value;
											foreach ($attachments as $attachment)
											{
												$owner = $attachment->getOwner();
												if($owner != null)
												{
													echo("Record Attachment Owner User-Name: " . $owner->getName() . "\n");
													echo("Record Attachment Owner User-ID: " . $owner->getId() . "\n");
													echo("Record Attachment Owner User-Email: " . $owner->getEmail() . "\n");
												}
												echo("Record Attachment Modified Time: "); print_r($attachment->getModifiedTime()); echo("\n");
												echo("Record Attachment File Name: " . $attachment->getFileName() . "\n");
												echo("Record Attachment Created Time: " ); print_r($attachment->getCreatedTime()); echo("\n");
												echo("Record Attachment File Size: " . $attachment->getSize() . "\n");
												$parentId = $attachment->getParentId();
												if($parentId != null)
												{
													echo("Record Attachment parent record Name: " . $parentId->getKeyValue("name") . "\n");
													echo("Record Attachment parent record ID: " . $parentId->getId() . "\n");
												}
												echo("Record Attachment is Editable: " . $attachment->getEditable() . "\n");
												echo("Record Attachment File ID: " . $attachment->getFileId() . "\n");
												echo("Record Attachment File Type: " . $attachment->getType() . "\n");
												echo("Record Attachment seModule: " . $attachment->getSeModule() . "\n");
												$modifiedBy = $attachment->getModifiedBy();
												if($modifiedBy != null)
												{
													echo("Record Attachment Modified By User-Name: " . $modifiedBy->getName() . "\n");
													echo("Record Attachment Modified By User-ID: " . $modifiedBy->getId() . "\n");
													echo("Record Attachment Modified By User-Email: " . $modifiedBy->getEmail() . "\n");
												}
												echo("Record Attachment State: " . $attachment->getState() . "\n");
												echo("Record Attachment ID: " . $attachment->getId() . "\n");
												$createdBy = $attachment->getCreatedBy();
												if($createdBy != null)
												{
													echo("Record Attachment Created By User-Name: " . $createdBy->getName() . "\n");
													echo("Record Attachment Created By User-ID: " . $createdBy->getId() . "\n");
													echo("Record Attachment Created By User-Email: " . $createdBy->getEmail() . "\n");
												}
												echo("Record Attachment LinkUrl: " . $attachment->getLinkUrl() . "\n");
											}
										}
										else if($value[0] instanceof ImageUpload)
										{
											$imageUploads = $value;
											foreach($imageUploads as $imageUpload)
											{
												echo("Record " . $keyName . " Description: " . $imageUpload->getDescription() . "\n");
												echo("Record " . $keyName . " PreviewId: " . $imageUpload->getPreviewId() . "\n");
												echo("Record " . $keyName . " File_Name: " . $imageUpload->getFileName() . "\n");
												echo("Record " . $keyName . " State: "); print_r($imageUpload->getState()); echo("\n");
												echo("Record " . $keyName . " Size: " . $imageUpload->getSize() . "\n");
												echo("Record " . $keyName . " SequenceNumber: " . $imageUpload->getSequenceNumber() . "\n");
												echo("Record " . $keyName . " Id: " . $imageUpload->getId() . "\n");
												echo("Record " . $keyName . " FileId: " . $imageUpload->getFileId() . "\n");
											}
										}
										else
										{
											echo($keyName . " : "); print_r($value); echo("\n");
										}
									}
									else if($value instanceof Layout)
									{
										$layout = $value;
										if($layout != null)
										{
											echo("Record " . $keyName. " ID: " . $layout->getId() . "\n");
											echo("Record " . $keyName . " Name: " . $layout->getName() . "\n");
										}
									}
									else if($value instanceof User)
									{
										$user = $value;
										if($user != null)
										{
											echo("Record " . $keyName . " User-ID: " . $user->getId() . "\n");
											echo("Record " . $keyName . " User-Name: " . $user->getName() . "\n");
											echo("Record " . $keyName . " User-Email: " . $user->getEmail() . "\n");
										}
									}
									else if($value instanceof $recordClass)
									{
										$recordValue = $value;
										echo("Record " . $keyName . " ID: " . $recordValue->getId() . "\n");
										echo("Record " . $keyName . " Name: " . $recordValue->getKeyValue("name") . "\n");
									}
									else if($value instanceof Choice)
									{
										$choiceValue = $value;
										echo("Record " . $keyName . " : " . $choiceValue->getValue() . "\n");
									}
									else if($value instanceof RemindAt)
									{
										echo($keyName . ": " . $value->getAlarm() . "\n");
									}
									else if($value instanceof RecurringActivity)
									{
										echo($keyName . " : RRULE" . ": " . $value->getRrule() . "\n");
									}
									else if($value instanceof Consent)
									{
										$consent = $value;
										echo("Record Consent ID: " . $consent->getId());
										$owner = $consent->getOwner();
										if($owner != null)
										{
											echo("Record Consent Owner Name: " . $owner->getName());
											echo("Record Consent Owner ID: " . $owner->getId());
											echo("Record Consent Owner Email: " . $owner->getEmail());
										}
										$consentCreatedBy = $consent->getCreatedBy();
										if($consentCreatedBy != null)
										{
											echo("Record Consent CreatedBy Name: " . $consentCreatedBy->getName());
											echo("Record Consent CreatedBy ID: " . $consentCreatedBy->getId());
											echo("Record Consent CreatedBy Email: " . $consentCreatedBy->getEmail());
										}
										$consentModifiedBy = $consent->getModifiedBy();
										if($consentModifiedBy != null)
										{
											echo("Record Consent ModifiedBy Name: " . $consentModifiedBy->getName());
											echo("Record Consent ModifiedBy ID: " . $consentModifiedBy->getId());
											echo("Record Consent ModifiedBy Email: " . $consentModifiedBy->getEmail());
										}
										echo("Record Consent CreatedTime: " . $consent->getCreatedTime());
										echo("Record Consent ModifiedTime: " . $consent->getModifiedTime());
										echo("Record Consent ContactThroughEmail: " . $consent->getContactThroughEmail());
										echo("Record Consent ContactThroughSocial: " . $consent->getContactThroughSocial());
										echo("Record Consent ContactThroughSurvey: " . $consent->getContactThroughSurvey());
										echo("Record Consent ContactThroughPhone: " . $consent->getContactThroughPhone());
										echo("Record Consent MailSentTime: " . $consent->getMailSentTime());
										echo("Record Consent ConsentDate: " . $consent->getConsentDate());
										echo("Record Consent ConsentRemarks: " . $consent->getConsentRemarks());
										echo("Record Consent ConsentThrough: " . $consent->getConsentThrough());
										echo("Record Consent DataProcessingBasis: " . $consent->getDataProcessingBasis());
										//To get custom values
										echo("Record Consent Lawful Reason: " . $consent->getKeyValue("Lawful_Reason"));
									}
									else
									{
										echo($keyName . " : "); print_r($value); echo("\n");
									}
								}
								else
								{
									echo($keyName . " : "); print_r($value); echo("\n");
								}
							}
						}
					}
					$info = $responseWrapper->getInfo();
					echo("Record Info PerPage : " . $info->getPerPage() . "\n");
					echo("Record Info Count : " . $info->getCount() . "\n");
					echo("Record Info Page : " . $info->getPage(). "\n");
					echo("Record Info MoreRecords : "); print_r($info->getMoreRecords()); echo("\n");
				}
				else if($responseHandler instanceof APIException)
				{
					$exception = $responseHandler;
					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
			{
				print_r($response);
			}
		}
	}
}

GetRecords::initialize();
$moduleAPIName = "Leads";
GetRecords::getRecords($moduleAPIName);
?>
Create Records

              <?php
namespace samples\record;

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\HeaderMap;
use com\zoho\crm\api\record\APIException;
use com\zoho\crm\api\record\ActionWrapper;
use com\zoho\crm\api\record\BodyWrapper;
use com\zoho\crm\api\record\FileDetails;
use com\zoho\crm\api\record\LineItemProduct;
use com\zoho\crm\api\record\LineTax;
use com\zoho\crm\api\record\Participants;
use com\zoho\crm\api\record\PricingDetails;
use com\zoho\crm\api\record\RecordOperations;
use com\zoho\crm\api\record\RecurringActivity;
use com\zoho\crm\api\record\RemindAt;
use com\zoho\crm\api\record\SuccessResponse;
use com\zoho\crm\api\tags\Tag;
use com\zoho\crm\api\record\{ApplyFeatureExecution, Cases, Solutions, Accounts, Campaigns, Calls, Leads, Tasks, Deals, Sales_Orders, Contacts, Quotes, Events, Price_Books, Purchase_Orders, Vendors};
use com\zoho\crm\api\util\Choice;
use com\zoho\crm\api\record\ImageUpload;
use com\zoho\crm\api\record\Tax;
use com\zoho\crm\api\users\User;
require_once "vendor/autoload.php";

class CreateRecords
{
    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 createRecords(string $moduleAPIName)
	{
		$recordOperations = new RecordOperations();
		$bodyWrapper = new BodyWrapper();
		$records = array();
		$recordClass = 'com\zoho\crm\api\record\Record';
		$record1 = new $recordClass();
		$apply_feature_execution = new ApplyFeatureExecution();
		$apply_feature_execution->setName("layout_rules");
		$apply_feature_list = array();
		array_push($apply_feature_list,$apply_feature_execution);
		$bodyWrapper->setApplyFeatureExecution($apply_feature_list);
		/*
		 * Call addFieldValue method that takes two arguments
		 * 1 -> Call Field "." and choose the module from the displayed list and press "." and choose the field name from the displayed list.
		 * 2 -> Value
		 */
		$record1->addFieldValue(Leads::City(), "City");
		$record1->addFieldValue(Leads::LastName(), "FROm PHP");
		$record1->addFieldValue(Leads::FirstName(), "First Name");
		$record1->addFieldValue(Leads::Company(), "KKRNP");
		$record1->addFieldValue(Vendors::VendorName(), "Vendor Name");
		$record1->addFieldValue(Deals::Stage(), new Choice("Clo"));
		$record1->addFieldValue(Deals::DealName(), "deal_name");
		$record1->addFieldValue(Deals::Description(), "deals description");
		$record1->addFieldValue(Deals::ClosingDate(), new \DateTime("2021-06-02"));
		$record1->addFieldValue(Deals::Amount(), 50.7);
		$record1->addFieldValue(Campaigns::CampaignName(), "Campaign_Name");
		$record1->addFieldValue(Solutions::SolutionTitle(), "Solution_Title");
		$accounts = new $recordClass();
		$accounts->addKeyValue("id", "34770615848009");
		$record1->addFieldValue(Accounts::AccountName(), $accounts);
		$record1->addFieldValue(Accounts::AccountName(), "Account_Name");
		$record1->addFieldValue(Cases::CaseOrigin(), new Choice("AutomatedSDK"));
		$record1->addFieldValue(Cases::Status(), new Choice("AutomatedSDK"));
		/*
		 * Call addKeyValue method that takes two arguments
		 * 1 -> A string that is the Field's API Name
		 * 2 -> Value
		 */
		$record1->addKeyValue("Custom_field", "Value");
		$record1->addKeyValue("Date_1", new \DateTime('2021-03-08'));
		$record1->addKeyValue("Date_Time_2", date_create("2020-06-02T11:03:06+05:30")->setTimezone(new \DateTimeZone(date_default_timezone_get())));
		$record1->addKeyValue("Subject", "From PHP");
		$record1->addKeyValue("External", "TestExternal123");
		$taxes = array();
		$tax = new Tax();
		$tax->setValue("MyTax1123 - 10.0 %");
		array_push($taxes, $tax);
		$record1->addKeyValue("Tax", $taxes);
		$record1->addKeyValue("Product_Name", "AutomatedSDK");
		$record1->addKeyValue("Products_External", "Products_External");
		$imageUpload = new ImageUpload();
		$imageUpload->setEncryptedId("ae9c7cefa418aec1d6a5cc2d9ab35c320c7da49c4222acd283e275ffade3f0ff");
		$record1->addKeyValue("Image_Upload", [$imageUpload]);
		$fileDetails = array();
		$fileDetail1 = new FileDetails();
		$fileDetail1->setFileId("ae9c7cefa418aec1d6a5cc2d9ab35c32b3ec27aa98b6161a4df6e2c0dc1f0f80");
		array_push($fileDetails, $fileDetail1);
		$fileDetail2 = new FileDetails();
		$fileDetail2->setFileId("ae9c7cefa418aec1d6a5cc2d9ab35c328db2d16efac6afe745678b577297a3b3");
		array_push($fileDetails, $fileDetail2);
		$fileDetail3 = new FileDetails();
		$fileDetail3->setFileId("ae9c7cefa418aec1d6a5cc2d9ab35c3207c8e1a4448a63b609f1ba7bd4aee6eb");
		array_push($fileDetails, $fileDetail3);
		$record1->addKeyValue("File_Upload", $fileDetails);

		$recordOwner = new User();
		$recordOwner->setEmail("abc@zoho.com");
        $record1->addKeyValue("Owner", $recordOwner);
		//Lookup
		$lookup = new $recordClass();
		$lookup->addKeyValue("id", "34770615848009");
		$record1->addKeyValue("lookup", $lookup);
		//MultiLookup
		$multiLookup = array();
		$lookup = new $recordClass();
		$lookup->addKeyValue("id", "34770615848009");
		array_push($multiLookup, $lookup);
		$record1->addKeyValue("multi-selectlookup", $multiLookup);

		/** Following methods are being used only by Inventory modules */
		$vendorName = new $recordClass();
		$vendorName->addFieldValue(Vendors::id(), "34770617247001");
		$record1->addFieldValue(Purchase_Orders::VendorName(), $vendorName);
		$dealName = new $recordClass();
		$dealName->addFieldValue(Deals::id(), "3477061012112003");
		$record1->addFieldValue(Sales_Orders::DealName(), $dealName);
		$contactName = new $recordClass();
		$contactName->addFieldValue(Contacts::id(), "3477061011383004");
		$record1->addFieldValue(Purchase_Orders::ContactName(), $contactName);
		$accountName = new $recordClass();
		$accountName->addKeyValue("name", "automatedAccount");
		$record1->addFieldValue(Quotes::AccountName(), $accountName);
		$record1->addKeyValue("Discount", 10.5);
		$inventoryLineItemList = array();
		$inventoryLineItem = new $recordClass();
		$lineItemProduct = new LineItemProduct();
		$lineItemProduct->setId("3477061012261");
		// $lineItemProduct->addKeyValue("Products_External", "Products_External");
		$inventoryLineItem->addKeyValue("Product_Name", $lineItemProduct);
		$inventoryLineItem->addKeyValue("Quantity", 1.5);
		$inventoryLineItem->addKeyValue("Description", "productDescription");
		$inventoryLineItem->addKeyValue("ListPrice", 10.0);
		$inventoryLineItem->addKeyValue("Discount", "5%");
		$productLineTaxes = array();
		$productLineTax = new LineTax();
		$productLineTax->setName("MyTax1123");
		$productLineTax->setPercentage(20.0);
		array_push($productLineTaxes, $productLineTax);
		$inventoryLineItem->addKeyValue("Line_Tax", $productLineTaxes);
		array_push($inventoryLineItemList, $inventoryLineItem);
		$record1->addKeyValue("Quoted_Items", $inventoryLineItemList);
		$record1->addKeyValue("Invoiced_Items", $inventoryLineItemList);
		$record1->addKeyValue("Purchase_Items", $inventoryLineItemList);
		$record1->addKeyValue("Ordered_Items", $inventoryLineItemList);
		$lineTaxes = array();
		$lineTax = new LineTax();
		$lineTax->setName("MyTax1123");
		$lineTax->setPercentage(20.0);
		array_push($lineTaxes,$lineTax);
		$record1->addKeyValue('$line_tax', $lineTaxes);
		/** End Inventory **/

		/** Following methods are being used only by Activity modules */
		// Tasks,Calls,Events
		$record1->addFieldValue(Tasks::Description(), "Test Task");
		$record1->addKeyValue("Currency",new Choice("INR"));
		$remindAt = new RemindAt();
		$remindAt->setAlarm("FREQ=DAILY;INTERVAL=10;UNTIL=2020-08-14;DTSTART=2020-07-03");
		$record1->addFieldValue(Tasks::RemindAt(), $remindAt);
		$whoId = new $recordClass();
		$whoId->setId("3477061011383004");
		$record1->addFieldValue(Tasks::WhoId(), $whoId);
		$record1->addFieldValue(Tasks::Status(),new Choice("Waiting for input"));
		$record1->addFieldValue(Tasks::DueDate(), new \DateTime('2021-03-08'));
		$record1->addFieldValue(Tasks::Priority(),new Choice("High"));
		$record1->addKeyValue('$se_module', "Accounts");
		$whatId = new $recordClass();
		$whatId->setId("3477061011383001");
		$record1->addFieldValue(Tasks::WhatId(), $whatId);
		/** Recurring Activity can be provided in any activity module*/
		$recurringActivity = new RecurringActivity();
		$recurringActivity->setRrule("FREQ=DAILY;INTERVAL=10;UNTIL=2020-08-14;DTSTART=2020-07-03");
		$record1->addFieldValue(Events::RecurringActivity(), $recurringActivity);
		
        // Events
		$record1->addFieldValue(Events::Description(), "Test Events");
		$startdatetime = date_create("2020-06-02T11:03:06+05:30")->setTimezone(new \DateTimeZone(date_default_timezone_get()));
		$record1->addFieldValue(Events::StartDateTime(), $startdatetime);
		$participants = array();
		$participant1 = new Participants();
		$participant1->setParticipant("abc@zoho.com");
		$participant1->setType("email");
		$participant1->setId("34770615902017");
		array_push($participants, $participant1);
		$participant2 = new Participants();
		$participant2->addKeyValue("participant", "347706155001");
		$participant2->addKeyValue("type", "lead");
		array_push($participants, $participant2);
		$record1->addFieldValue(Events::Participants(), $participants);
		$record1->addKeyValue('$send_notification', true);
		$record1->addFieldValue(Events::EventTitle(), "From PHP");
		$enddatetime = date_create("2020-07-02T11:03:06+05:30")->setTimezone(new \DateTimeZone(date_default_timezone_get()));
		$record1->addFieldValue(Events::EndDateTime(), $enddatetime);
		$remindAt = date_create("2020-06-02T11:03:06+05:30")->setTimezone(new \DateTimeZone(date_default_timezone_get()));
		$record1->addFieldValue(Events::RemindAt(), $remindAt);
		$record1->addFieldValue(Events::CheckInStatus(), "PLANNED");
		$remindAt = new RemindAt();
		$remindAt->setAlarm("FREQ=NONE;ACTION=EMAILANDPOPUP;TRIGGER=DATE-TIME:2020-07-23T12:30:00+05:30");
		$record1->addFieldValue(Tasks::RemindAt(), $remindAt);
		$record1->addKeyValue('$se_module', "Leads");
		$record1->addKeyValue('Remind_At', new \DateTime('2020-03-08'));
		$whatId = new $recordClass();
		$whatId->setId("3477061012255001");
		$record1->addFieldValue(Events::WhatId(), $whatId);
		$record1->addFieldValue(Tasks::WhatId(), $whatId);
		$record1->addFieldValue(Calls::CallType(), new Choice("Outbound"));
		$record1->addFieldValue(Calls::CallStartTime(), date_create("2020-07-02T11:03:06+05:30")->setTimezone(new \DateTimeZone(date_default_timezone_get())));
		/** End Activity **/
		
        /** Following methods are being used only by Price_Books modules */
		$pricingDetails = array();
		$pricingDetail1 = new PricingDetails();
		$pricingDetail1->setFromRange(1.0);
		$pricingDetail1->setToRange(5.0);
		$pricingDetail1->setDiscount(2.0);
		array_push($pricingDetails, $pricingDetail1);
		$pricingDetail2 = new PricingDetails();
		$pricingDetail2->addKeyValue("from_range", 6.0);
		$pricingDetail2->addKeyValue("to_range", 11.0);
		$pricingDetail2->addKeyValue("discount", 3.0);
		array_push($pricingDetails, $pricingDetail2);
		$record1->addFieldValue(Price_Books::PricingDetails(), $pricingDetails);
		$record1->addKeyValue("Email", "user1223@zoho.com");
		$record1->addFieldValue(Price_Books::Description(), "TEST");
		$record1->addFieldValue(Price_Books::PriceBookName(), "book_name");
		$record1->addFieldValue(Price_Books::PricingModel(), new Choice("Flat"));
        /** Price_Books */

		$tagList = array();
		$tag = new Tag();
		$tag->setName("Testtask");
		array_push($tagList, $tag);
		$record1->setTag($tagList);
		array_push($records, $record1);
		$bodyWrapper->setData($records);
		$trigger = array("approval", "workflow", "blueprint");
		$bodyWrapper->setTrigger($trigger);
		//bodyWrapper.setLarId("34770610087515");
		$headerInstance = new HeaderMap();
		// $headerInstance->add(CreateRecordsHeader::XEXTERNAL(), "Quotes.Quoted_Items.Product_Name.Products_External");
		// $headerInstance->add(CreateRecordsHeader::XEXTERNAL(), "Products.Products_External");
		$response = $recordOperations->createRecords($moduleAPIName, $bodyWrapper, $headerInstance);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
			if($response->isExpected())
			{
				$actionHandler = $response->getObject();
				if($actionHandler instanceof ActionWrapper)
				{
					$actionWrapper = $actionHandler;
					$actionResponses = $actionWrapper->getData();
					foreach($actionResponses as $actionResponse)
					{
						if($actionResponse instanceof SuccessResponse)
						{
							$successResponse = $actionResponse;
							echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
							echo("Code: " . $successResponse->getCode()->getValue() . "\n");
							echo("Details: " );
							foreach($successResponse->getDetails() as $key => $value)
							{
								echo($key . " : "); print_r($value); echo("\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");
				}
			}
			else
			{
				print_r($response);
			}
		}
	}
}

CreateRecords::initialize();
$moduleAPIName = "Leads";
CreateRecords::createRecords($moduleAPIName);
?>
Update Records

              

        <?php
namespace samples\record;

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\HeaderMap;
use com\zoho\crm\api\record\APIException;
use com\zoho\crm\api\record\ActionWrapper;
use com\zoho\crm\api\record\BodyWrapper;
use com\zoho\crm\api\record\LineItemProduct;
use com\zoho\crm\api\record\LineTax;
use com\zoho\crm\api\record\RecordOperations;
use com\zoho\crm\api\record\SuccessResponse;
use com\zoho\crm\api\record\{ApplyFeatureExecution, Leads, Deals, Sales_Orders, Contacts, Quotes, Purchase_Orders, Vendors};
use com\zoho\crm\api\users\User;
require_once "vendor/autoload.php";

class UpdateRecords
{
    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 updateRecords(string $moduleAPIName)
	{
		$recordOperations = new RecordOperations();
		$request = new BodyWrapper();
		$records = array();
		$recordClass = 'com\zoho\crm\api\record\Record';
		$record1 = new $recordClass();
		$record1->setId("3477061012266");
		$apply_feature_execution = new ApplyFeatureExecution();
		$apply_feature_execution->setName("layout_rules");
		$apply_feature_list = array();
		array_push($apply_feature_list,$apply_feature_execution);
		$request->setApplyFeatureExecution($apply_feature_list);
		$record1->addFieldValue(Leads::City(), "City");
		$record1->addFieldValue(Leads::LastName(), "Last Name");
		$record1->addFieldValue(Leads::FirstName(), "First Name");
		$record1->addFieldValue(Leads::Company(), "KKRNP");
		/*
		 * Call addKeyValue method that takes two arguments
		 * 1 -> A string that is the Field's API Name
		 * 2 -> Value
		 */
		$record1->addKeyValue("Custom_field", "Value");
		$record1->addKeyValue("Custom_field_2", "value");

		$recordOwner = new User();
		$recordOwner->setEmail("abc@zoho.com");
        $record1->addKeyValue("Owner", $recordOwner);

		/** Following methods are being used only by Inventory modules */
		$vendorName = new $recordClass();
		$vendorName->addFieldValue(Vendors::id(), "34770617247001");
		$record1->addFieldValue(Purchase_Orders::VendorName(), $vendorName);
		$dealName = new $recordClass();
		$dealName->addFieldValue(Deals::id(), "3477061012112003");
		$record1->addFieldValue(Sales_Orders::DealName(), $dealName);
		$contactName = new $recordClass();
		$contactName->addFieldValue(Contacts::id(), "3477061011383004");
		$record1->addFieldValue(Purchase_Orders::ContactName(), $contactName);
		$accountName = new $recordClass();
		$accountName->addKeyValue("name", "automatedAccount");
		$record1->addFieldValue(Quotes::AccountName(), $accountName);
		$record1->addKeyValue("Discount", 10.5);
		$inventoryLineItemList = array();
		$inventoryLineItem = new $recordClass();
		$lineItemProduct = new LineItemProduct();
		// $lineItemProduct->setId("3477061012261");
		$lineItemProduct->addKeyValue("Products_External", "Products_External");
		$inventoryLineItem->addKeyValue("Product_Name", $lineItemProduct);
		$inventoryLineItem->addKeyValue("Quantity", 1.5);
		$inventoryLineItem->addKeyValue("Description", "productDescription");
		$inventoryLineItem->addKeyValue("ListPrice", 10.0);
		$inventoryLineItem->addKeyValue("Discount", "5%");
		$productLineTaxes = array();
		$productLineTax = new LineTax();
		$productLineTax->setName("MyTax1123");
		$productLineTax->setPercentage(20.0);
		array_push($productLineTaxes, $productLineTax);
		$inventoryLineItem->addKeyValue("Line_Tax", $productLineTaxes);
		array_push($inventoryLineItemList, $inventoryLineItem);
		$record1->addKeyValue("Quoted_Items", $inventoryLineItemList);
		$record1->addKeyValue("Invoiced_Items", $inventoryLineItemList);
		$record1->addKeyValue("Purchase_Items", $inventoryLineItemList);
		$record1->addKeyValue("Ordered_Items", $inventoryLineItemList);
		$lineTaxes = array();
		$lineTax = new LineTax();
		$lineTax->setName("MyTax1123");
		$lineTax->setPercentage(20.0);
		array_push($lineTaxes,$lineTax);
		$record1->addKeyValue('$line_tax', $lineTaxes);
		/** End Inventory **/
		
		//Add Record instance to the list
		array_push($records, $record1);
		$record2 = new $recordClass();
		$record2->setId("34770619873001");
		/*
		 * Call addFieldValue method that takes two arguments
		 * 1 -> Call Field "." and choose the module from the displayed list and press "." and choose the field name from the displayed list.
		 * 2 -> Value
		 */
		$record2->addFieldValue(Leads::City(), "City");
		$record2->addFieldValue(Leads::LastName(), "Last Name");
		$record2->addFieldValue(Leads::FirstName(), "First Name");
		$record2->addFieldValue(Leads::Company(), "KKRNP");
		/*
		 * Call addKeyValue method that takes two arguments
		 * 1 -> A string that is the Field's API Name
		 * 2 -> Value
		 */
		$record2->addKeyValue("Custom_field", "Value");
		$record2->addKeyValue("Custom_field_2", "value");
		//Add Record instance to the list
		array_push($records, $record2);
		$request->setData($records);
		$trigger = array("approval", "workflow", "blueprint");
		$request->setTrigger($trigger);
		$headerInstance = new HeaderMap();
		// $headerInstance->add(CreateRecordsHeader::XEXTERNAL(), "Quotes.Quoted_Items.Product_Name.Products_External");
		$response = $recordOperations->updateRecords($moduleAPIName, $request, $headerInstance);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
			if($response->isExpected())
			{
				$actionHandler = $response->getObject();
				if($actionHandler instanceof ActionWrapper)
				{
					$actionWrapper = $actionHandler;
					$actionResponses = $actionWrapper->getData();
					foreach($actionResponses as $actionResponse)
					{
						if($actionResponse instanceof SuccessResponse)
						{
							$successResponse = $actionResponse;
							echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
							echo("Code: " . $successResponse->getCode()->getValue() . "\n");
							echo("Details: " );
							foreach($successResponse->getDetails() as $key => $value)
							{
								echo($key . " : ");
								print_r($value);
								echo("\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");
				}
			}
			else
			{
				print_r($response);
			}
		}
	}
}

UpdateRecords::initialize();
$moduleAPIName = "Leads";
UpdateRecords::updateRecords($moduleAPIName);
?>

 
Delete Records

              <?php
namespace samples\record;

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\HeaderMap;
use com\zoho\crm\api\ParameterMap;
use com\zoho\crm\api\record\APIException;
use com\zoho\crm\api\record\ActionWrapper;
use com\zoho\crm\api\record\RecordOperations;
use com\zoho\crm\api\record\SuccessResponse;
use com\zoho\crm\api\record\DeleteRecordsParam;
use com\zoho\crm\api\record\CreateRecordsHeader;
require_once "vendor/autoload.php";

class DeleteRecords
{
    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 deleteRecords(string $moduleAPIName, array $recordIds)
	{
		$recordOperations = new RecordOperations();
		$paramInstance = new ParameterMap();
		foreach($recordIds as $id)
		{
			$paramInstance->add(DeleteRecordsParam::ids(), $id);
		}
		$paramInstance->add(DeleteRecordsParam::wfTrigger(), true);
		$headerInstance = new HeaderMap();
		// $headerInstance->add(CreateRecordsHeader::XEXTERNAL(), "Leads.External");
		$response = $recordOperations->deleteRecords($moduleAPIName, $paramInstance, $headerInstance);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
			if($response->isExpected())
			{
				$actionHandler = $response->getObject();
				if($actionHandler instanceof ActionWrapper)
				{
					$actionWrapper = $actionHandler;
					$actionResponses = $actionWrapper->getData();
					foreach($actionResponses as $actionResponse)
					{
						if($actionResponse instanceof SuccessResponse)
						{
							$successResponse = $actionResponse;
							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($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");
				}
			}
			else
			{
				print_r($response);
			}
		}
	}
}

DeleteRecords::initialize();
$moduleAPIName = "Leads";
$recordIds = array("34770616606002","34770616603294");
DeleteRecords::deleteRecords($moduleAPIName, $recordIds);
?>
Upsert Records

              <?php
namespace samples\record;

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\HeaderMap;
use com\zoho\crm\api\record\APIException;
use com\zoho\crm\api\record\ActionWrapper;
use com\zoho\crm\api\record\BodyWrapper;
use com\zoho\crm\api\record\RecordOperations;
use com\zoho\crm\api\record\SuccessResponse;
use com\zoho\crm\api\record\{ApplyFeatureExecution, Field, Leads };
require_once "vendor/autoload.php";

class UpsertRecords
{
    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 upsertRecords(string $moduleAPIName)
	{
		$recordOperations = new RecordOperations();
		$request = new BodyWrapper();
		$records = array();
		$recordClass = 'com\zoho\crm\api\record\Record';
		$record1 = new $recordClass();
		$apply_feature_execution = new ApplyFeatureExecution();
		$apply_feature_execution->setName("layout_rules");
		$apply_feature_list = array();
		array_push($apply_feature_list,$apply_feature_execution);
		$request->setApplyFeatureExecution($apply_feature_list);

		/*
		 * Call addFieldValue method that takes two arguments
		 * 1 -> Call Field "." and choose the module from the displayed list and press "." and choose the field name from the displayed list.
		 * 2 -> Value
		 */
		$field = new Field("");
		$record1->addFieldValue(Leads::City(), "City");
		$record1->addFieldValue(Leads::LastName(), "Last Name");
		$record1->addFieldValue(Leads::FirstName(), "First Name");
		$record1->addFieldValue(Leads::Company(), "Company1");
		/*
		 * Call addKeyValue method that takes two arguments
		 * 1 -> A string that is the Field's API Name
		 * 2 -> Value
		 */
		$record1->addKeyValue("Custom_field", "Value");
		$record1->addKeyValue("Custom_field_2", "value");
		array_push($records, $record1);
		$record2 = new $recordClass();
		/*
		 * Call addFieldValue method that takes two arguments
		 * 1 -> Call Field "." and choose the module from the displayed list and press "." and choose the field name from the displayed list.
		 * 2 -> Value
		 */
		$record2->addFieldValue(Leads::City(), "City");
		$record2->addFieldValue(Leads::LastName(), "Last Name");
		$record2->addFieldValue(Leads::FirstName(), "First Name");
		$record2->addFieldValue(Leads::Company(), "Company12");
		/*
		 * Call addKeyValue method that takes two arguments
		 * 1 -> A string that is the Field's API Name
		 * 2 -> Value
		 */
		$record2->addKeyValue("Custom_field", "Value");
		$record2->addKeyValue("Custom_field_2", "value");
		$record2->addKeyValue("External", "External1");
		array_push($records, $record2);
		$duplicateCheckFields = array("City", "Last_Name", "First_Name");
		$request->setDuplicateCheckFields($duplicateCheckFields);
		$request->setData($records);
		$headerInstance = new HeaderMap();
		// $headerInstance->add(UpsertRecordsHeader::XEXTERNAL(), "Leads.External");
		$response = $recordOperations->upsertRecords($moduleAPIName, $request, $headerInstance);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
			if($response->isExpected())
			{
				$actionHandler = $response->getObject();
				if($actionHandler instanceof ActionWrapper)
				{
					$actionWrapper = $actionHandler;
					$actionResponses = $actionWrapper->getData();
					foreach($actionResponses as $actionResponse)
					{
						if($actionResponse instanceof SuccessResponse)
						{
							$successResponse = $actionResponse;
							echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
							echo("Code: " . $successResponse->getCode()->getValue() . "\n");
							echo("Details: " );
							foreach($successResponse->getDetails() as $key => $value)
							{
								echo($key . " : ");
								print_r($value);
								echo("\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");
				}
			}
			else
			{
				print_r($response);
			}
		}
	}
}

UpsertRecords::initialize();
$moduleAPIName = "Leads";
UpsertRecords::upsertRecords($moduleAPIName);
?>
Get Deleted Records

              <?php
namespace samples\record;

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\HeaderMap;
use com\zoho\crm\api\ParameterMap;
use com\zoho\crm\api\record\APIException;
use com\zoho\crm\api\record\DeletedRecordsWrapper;
use com\zoho\crm\api\record\RecordOperations;
use com\zoho\crm\api\record\GetDeletedRecordsHeader;
use com\zoho\crm\api\record\GetDeletedRecordsParam;
require_once "vendor/autoload.php";

class GetDeletedRecords
{
    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 getDeletedRecords(string $moduleAPIName)
	{
		$recordOperations = new RecordOperations();
		$paramInstance = new ParameterMap();
		$paramInstance->add(GetDeletedRecordsParam::type(), "recycle");//all, recycle, permanent
		$paramInstance->add(GetDeletedRecordsParam::page(), 1);
		$paramInstance->add(GetDeletedRecordsParam::perPage(), 2);
		$headerInstance = new HeaderMap();
		$ifModifiedSince = date_create("2020-06-02T11:03:06+05:30")->setTimezone(new \DateTimeZone(date_default_timezone_get()));
		$headerInstance->add(GetDeletedRecordsHeader::IfModifiedSince(), $ifModifiedSince);
		$response = $recordOperations->getDeletedRecords($moduleAPIName,$paramInstance, $headerInstance);
		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;
			}
			if($response->isExpected())
			{
				$deletedRecordsHandler = $response->getObject();
				if($deletedRecordsHandler instanceof DeletedRecordsWrapper)
				{
					$deletedRecordsWrapper = $deletedRecordsHandler;
					$deletedRecords = $deletedRecordsWrapper->getData();
					foreach($deletedRecords as $deletedRecord)
					{
						$deletedBy = $deletedRecord->getDeletedBy();
						if($deletedBy != null)
						{
							echo("DeletedRecord Deleted By User-Name: " . $deletedBy->getName() . "\n");
							echo("DeletedRecord Deleted By User-ID: " . $deletedBy->getId() . "\n");
						}
						echo("DeletedRecord ID: " . $deletedRecord->getId() . "\n");
						echo("DeletedRecord DisplayName: " . $deletedRecord->getDisplayName() . "\n");
						echo("DeletedRecord Type: " . $deletedRecord->getType() . "\n");
						$createdBy = $deletedRecord->getCreatedBy();
						if($createdBy != null)
						{
							echo("DeletedRecord Created By User-Name: " . $createdBy->getName() . "\n");
							echo("DeletedRecord Created By User-ID: " . $createdBy->getId() . "\n");
						}
						echo("DeletedRecord DeletedTime: ");
						print_r($deletedRecord->getDeletedTime());
						echo("\n");
					}
					$info = $deletedRecordsWrapper->getInfo();
					if($info != null)
					{
						if($info->getPerPage() != null)
						{
							echo("Deleted Record Info PerPage: " . $info->getPerPage() . "\n");
						}
						if($info->getCount() != null)
						{
							echo("Deleted Record Info Count: " . $info->getCount() . "\n");
						}
						if($info->getPage() != null)
						{
							echo("Deleted Record Info Page: " . $info->getPage() . "\n");
						}
						if($info->getMoreRecords() != null)
						{
							echo("Deleted Record Info MoreRecords: " . $info->getMoreRecords() . "\n");
						}
					}
				}
				else if($deletedRecordsHandler instanceof APIException)
				{
					$exception = $deletedRecordsHandler;
					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
			{
				print_r($response);
			}
		}
	}
}

GetDeletedRecords::initialize();
$moduleAPIName = "Leads";
GetDeletedRecords::getDeletedRecords($moduleAPIName);
?>
Search Records

              	
        <?php
	namespace samples\record;

	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\HeaderMap;
	use com\zoho\crm\api\ParameterMap;
	use com\zoho\crm\api\layouts\Layout;
	use com\zoho\crm\api\record\APIException;
	use com\zoho\crm\api\record\FileDetails;
	use com\zoho\crm\api\record\LineTax;
	use com\zoho\crm\api\record\Participants;
	use com\zoho\crm\api\record\PricingDetails;
	use com\zoho\crm\api\record\RecordOperations;
	use com\zoho\crm\api\record\RecurringActivity;
	use com\zoho\crm\api\record\RemindAt;
	use com\zoho\crm\api\record\ResponseWrapper;
	use com\zoho\crm\api\tags\Tag;
	use com\zoho\crm\api\record\SearchRecordsParam;
	use com\zoho\crm\api\util\Choice;
	use com\zoho\crm\api\record\Comment;
	use com\zoho\crm\api\record\Consent;
	use com\zoho\crm\api\attachments\Attachment;
	use com\zoho\crm\api\record\ImageUpload;
	use com\zoho\crm\api\users\User;
	use com\zoho\crm\api\record\UpdateRecordHeader;
	require_once "vendor/autoload.php";

	class SearchRecords
	{
	    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 searchRecords(string $moduleAPIName)
		{
			$recordOperations = new RecordOperations();
			$paramInstance = new ParameterMap();
			$paramInstance->add(SearchRecordsParam::criteria(), "((Last_Name:starts_with:Last Name) or (Company:starts_with:fasf\\(123\\) K))");
			// $paramInstance->add(SearchRecordsParam::criteria(), "(External:in:External1)");
			$paramInstance->add(SearchRecordsParam::email(), "username@gmail.com");
			$paramInstance->add(SearchRecordsParam::phone(), "234567890");
			$paramInstance->add(SearchRecordsParam::word(), "First Name Last Name");
			$paramInstance->add(SearchRecordsParam::converted(), "both");
			$paramInstance->add(SearchRecordsParam::approved(), "both");
			$paramInstance->add(SearchRecordsParam::page(), 1);
			$paramInstance->add(SearchRecordsParam::perPage(), 2);
			$headerInstance = new HeaderMap();
			$headerInstance->add(UpdateRecordHeader::XEXTERNAL(), "Leads.External");
			$response = $recordOperations->searchRecords($moduleAPIName, $paramInstance, $headerInstance);
			if($response->isExpected())
			{
				$responseHandler = $response->getObject();
				if($responseHandler instanceof ResponseWrapper)
				{
					$responseWrapper = $responseHandler;
					$records = $responseWrapper->getData();
					if($records != null)
					{
						$recordClass = 'com\zoho\crm\api\record\Record';
						foreach($records as $record)
						{
							echo("Record ID: " . $record->getId() . "\n");
							$createdBy = $record->getCreatedBy();
							if($createdBy != null)
							{
								echo("Record Created By User-ID: " . $createdBy->getId() . "\n");
								echo("Record Created By User-Name: " . $createdBy->getName() . "\n");
								echo("Record Created By User-Email: " . $createdBy->getEmail() . "\n");
							}
							echo("Record CreatedTime: "); print_r($record->getCreatedTime()); echo("\n");
							$modifiedBy = $record->getModifiedBy();
							if($modifiedBy != null)
							{
								echo("Record Modified By User-ID: " . $modifiedBy->getId() . "\n");
								echo("Record Modified By User-Name: " . $modifiedBy->getName() . "\n");
								echo("Record Modified By User-Email: " . $modifiedBy->getEmail() . "\n");
							}
							echo("Record ModifiedTime: "); print_r($record->getModifiedTime()); echo("\n");
							$tags = $record->getTag();
							if($tags != null)
							{
								foreach($tags as $tag)
								{
									echo("Record Tag Name: " . $tag->getName() . "\n");
									echo("Record Tag ID: " . $tag->getId() . "\n");
								}
							}
							//To get particular field value
							echo("Record Field Value: " . $record->getKeyValue("Last_Name") . "\n");// FieldApiName
							echo("Record KeyValues : \n" );
							foreach($record->getKeyValues() as $keyName => $value)
							{
								if($value != null)
								{
									if((is_array($value) && sizeof($value) > 0) && isset($value[0]))
									{
										if($value[0] instanceof FileDetails)
										{
											$fileDetails = $value;
											foreach($fileDetails as $fileDetail)
											{
												echo("Record FileDetails Extn: " . $fileDetail->getExtn() . "\n");
												echo("Record FileDetails IsPreviewAvailable: " . $fileDetail->getIsPreviewAvailable() . "\n");
												echo("Record FileDetails DownloadUrl: " . $fileDetail->getDownloadUrl() . "\n");
												echo("Record FileDetails DeleteUrl: " . $fileDetail->getDeleteUrl() . "\n");
												echo("Record FileDetails EntityId: " . $fileDetail->getEntityId() . "\n");
												echo("Record FileDetails Mode: " . $fileDetail->getMode() . "\n");
												echo("Record FileDetails OriginalSizeByte: " . $fileDetail->getOriginalSizeByte() . "\n");
												echo("Record FileDetails PreviewUrl: " . $fileDetail->getPreviewUrl() . "\n");
												echo("Record FileDetails FileName: " . $fileDetail->getFileName() . "\n");
												echo("Record FileDetails FileId: " . $fileDetail->getFileId() . "\n");
												echo("Record FileDetails AttachmentId: " . $fileDetail->getAttachmentId() . "\n");
												echo("Record FileDetails FileSize: " . $fileDetail->getFileSize() . "\n");
												echo("Record FileDetails CreatorId: " . $fileDetail->getCreatorId() . "\n");
												echo("Record FileDetails LinkDocs: " . $fileDetail->getLinkDocs() . "\n");
											}
										}
										else if($value[0] instanceof Choice)
										{
											$choice = $value;
											foreach($choice as $choiceValue)
											{
												echo("Record " . $keyName . " : " . $choiceValue->getValue() . "\n");
											}
										}
										else if($value[0] instanceof Tag)
										{
											$tagList = $value;
											foreach($tagList as $tag)
											{
												echo("Record Tag Name: " . $tag->getName() . "\n");
												echo("Record Tag ID: " . $tag->getId() . "\n");
											}
										}
										else if($value[0] instanceof PricingDetails)
										{
											$pricingDetails = $value;
											foreach($pricingDetails as $pricingDetail)
											{
												echo("Record PricingDetails ToRange: " . $pricingDetail->getToRange(). "\n");
												echo("Record PricingDetails Discount: " . $pricingDetail->getDiscount(). "\n");
												echo("Record PricingDetails ID: " . $pricingDetail->getId() . "\n");
												echo("Record PricingDetails FromRange: " . $pricingDetail->getFromRange(). "\n");
											}
										}
										else if($value[0] instanceof Participants)
										{
											$participants = $value;
											foreach($participants as $participant)
											{
												echo("RelatedRecord Participants Name: " . $participant->getName() . "\n");
												echo("RelatedRecord Participants Invited: " . $participant->getInvited() . "\n");
												echo("RelatedRecord Participants ID: " . $participant->getId() . "\n");
												echo("RelatedRecord Participants Type: " . $participant->getType() . "\n");
												echo("RelatedRecord Participants Participant: " . $participant->getParticipant() . "\n");
												echo("RelatedRecord Participants Status: " . $participant->getStatus() . "\n");
											}
										}
										else if($value[0] instanceof $recordClass)
										{
											$recordList = $value;
											foreach($recordList as $record1)
											{
												foreach($record1->getKeyValues() as $key => $value1)
												{
													echo($key . " : " ); print_r($value1); echo("\n");
												}
											}
										}
										else if($value[0] instanceof LineTax)
										{
											$lineTaxes = $value;
											foreach($lineTaxes as $lineTax)
											{
												echo("Record ProductDetails LineTax Percentage: " . $lineTax->getPercentage(). "\n");
												echo("Record ProductDetails LineTax Name: " . $lineTax->getName() . "\n");
												echo("Record ProductDetails LineTax Id: " . $lineTax->getId() . "\n");
												echo("Record ProductDetails LineTax Value: " . $lineTax->getValue(). "\n");
											}
										}
										else if($value[0] instanceof Comment)
										{
											$comments = $value;
											foreach($comments as $comment)
											{
												echo("Record Comment CommentedBy: " . $comment->getCommentedBy() . "\n");
												echo("Record Comment CommentedTime: "); print_r($comment->getCommentedTime()); echo("\n");
												echo("Record Comment CommentContent: " . $comment->getCommentContent(). "\n");
												echo("Record Comment Id: " . $comment->getId() . "\n");
											}
										}
										else if($value[0] instanceof Attachment)
										{
											$attachments = $value;
											foreach ($attachments as $attachment)
											{
												$owner = $attachment->getOwner();
												if($owner != null)
												{
													echo("Record Attachment Owner User-Name: " . $owner->getName() . "\n");
													echo("Record Attachment Owner User-ID: " . $owner->getId() . "\n");
													echo("Record Attachment Owner User-Email: " . $owner->getEmail() . "\n");
												}
												echo("Record Attachment Modified Time: "); print_r($attachment->getModifiedTime()); echo("\n");
												echo("Record Attachment File Name: " . $attachment->getFileName() . "\n");
												echo("Record Attachment Created Time: " ); print_r($attachment->getCreatedTime()); echo("\n");
												echo("Record Attachment File Size: " . $attachment->getSize() . "\n");
												$parentId = $attachment->getParentId();
												if($parentId != null)
												{
													echo("Record Attachment parent record Name: " . $parentId->getKeyValue("name") . "\n");
													echo("Record Attachment parent record ID: " . $parentId->getId() . "\n");
												}
												echo("Record Attachment is Editable: " . $attachment->getEditable() . "\n");
												echo("Record Attachment File ID: " . $attachment->getFileId() . "\n");
												echo("Record Attachment File Type: " . $attachment->getType() . "\n");
												echo("Record Attachment seModule: " . $attachment->getSeModule() . "\n");
												$modifiedBy = $attachment->getModifiedBy();
												if($modifiedBy != null)
												{
													echo("Record Attachment Modified By User-Name: " . $modifiedBy->getName() . "\n");
													echo("Record Attachment Modified By User-ID: " . $modifiedBy->getId() . "\n");
													echo("Record Attachment Modified By User-Email: " . $modifiedBy->getEmail() . "\n");
												}
												echo("Record Attachment State: " . $attachment->getState() . "\n");
												echo("Record Attachment ID: " . $attachment->getId() . "\n");
												$createdBy = $attachment->getCreatedBy();
												if($createdBy != null)
												{
													echo("Record Attachment Created By User-Name: " . $createdBy->getName() . "\n");
													echo("Record Attachment Created By User-ID: " . $createdBy->getId() . "\n");
													echo("Record Attachment Created By User-Email: " . $createdBy->getEmail() . "\n");
												}
												echo("Record Attachment LinkUrl: " . $attachment->getLinkUrl() . "\n");
											}
										}
										else if($value[0] instanceof ImageUpload)
										{
											$imageUploads = $value;
											foreach($imageUploads as $imageUpload)
											{
												echo("Record " . $keyName . " Description: " . $imageUpload->getDescription() . "\n");
												echo("Record " . $keyName . " PreviewId: " . $imageUpload->getPreviewId() . "\n");
												echo("Record " . $keyName . " File_Name: " . $imageUpload->getFileName() . "\n");
												echo("Record " . $keyName . " State: "); print_r($imageUpload->getState()); echo("\n");
												echo("Record " . $keyName . " Size: " . $imageUpload->getSize() . "\n");
												echo("Record " . $keyName . " SequenceNumber: " . $imageUpload->getSequenceNumber() . "\n");
												echo("Record " . $keyName . " Id: " . $imageUpload->getId() . "\n");
												echo("Record " . $keyName . " FileId: " . $imageUpload->getFileId() . "\n");
											}
										}
										else
										{
											echo($keyName . " : "); print_r($value); echo("\n");
										}
									}
									else if($value instanceof Layout)
									{
										$layout = $value;
										if($layout != null)
										{
											echo("Record " . $keyName. " ID: " . $layout->getId() . "\n");
											echo("Record " . $keyName . " Name: " . $layout->getName() . "\n");
										}
									}
									else if($value instanceof User)
									{
										$user = $value;
										if($user != null)
										{
											echo("Record " . $keyName . " User-ID: " . $user->getId() . "\n");
											echo("Record " . $keyName . " User-Name: " . $user->getName() . "\n");
											echo("Record " . $keyName . " User-Email: " . $user->getEmail() . "\n");
										}
									}
									else if($value instanceof $recordClass)
									{
										$recordValue = $value;
										echo("Record " . $keyName . " ID: " . $recordValue->getId() . "\n");
										echo("Record " . $keyName . " Name: " . $recordValue->getKeyValue("name") . "\n");
									}
									else if($value instanceof Choice)
									{
										$choiceValue = $value;
										echo("Record " . $keyName . " : " . $choiceValue->getValue() . "\n");
									}
									else if($value instanceof RemindAt)
									{
										echo($keyName . ": " . $value->getAlarm() . "\n");
									}
									else if($value instanceof RecurringActivity)
									{
										echo($keyName . " : RRULE" . ": " . $value->getRrule() . "\n");
									}
									else if($value instanceof Consent)
									{
										$consent = $value;
										echo("Record Consent ID: " . $consent->getId());
										$owner = $consent->getOwner();
										if($owner != null)
										{
											echo("Record Consent Owner Name: " . $owner->getName());
											echo("Record Consent Owner ID: " . $owner->getId());
											echo("Record Consent Owner Email: " . $owner->getEmail());
										}
										$consentCreatedBy = $consent->getCreatedBy();
										if($consentCreatedBy != null)
										{
											echo("Record Consent CreatedBy Name: " . $consentCreatedBy->getName());
											echo("Record Consent CreatedBy ID: " . $consentCreatedBy->getId());
											echo("Record Consent CreatedBy Email: " . $consentCreatedBy->getEmail());
										}
										$consentModifiedBy = $consent->getModifiedBy();
										if($consentModifiedBy != null)
										{
											echo("Record Consent ModifiedBy Name: " . $consentModifiedBy->getName());
											echo("Record Consent ModifiedBy ID: " . $consentModifiedBy->getId());
											echo("Record Consent ModifiedBy Email: " . $consentModifiedBy->getEmail());
										}
										echo("Record Consent CreatedTime: " . $consent->getCreatedTime());
										echo("Record Consent ModifiedTime: " . $consent->getModifiedTime());
										echo("Record Consent ContactThroughEmail: " . $consent->getContactThroughEmail());
										echo("Record Consent ContactThroughSocial: " . $consent->getContactThroughSocial());
										echo("Record Consent ContactThroughSurvey: " . $consent->getContactThroughSurvey());
										echo("Record Consent ContactThroughPhone: " . $consent->getContactThroughPhone());
										echo("Record Consent MailSentTime: " . $consent->getMailSentTime());
										echo("Record Consent ConsentDate: " . $consent->getConsentDate());
										echo("Record Consent ConsentRemarks: " . $consent->getConsentRemarks());
										echo("Record Consent ConsentThrough: " . $consent->getConsentThrough());
										echo("Record Consent DataProcessingBasis: " . $consent->getDataProcessingBasis());
										//To get custom values
										echo("Record Consent Lawful Reason: " . $consent->getKeyValue("Lawful_Reason"));
									}
									else
									{
										echo($keyName . " : "); print_r($value); echo("\n");
									}
								}
								else
								{
									echo($keyName . " : "); print_r($value); echo("\n");
								}
							}
						}
					}
				}
				else if($responseHandler instanceof APIException)
				{
					$exception = $responseHandler;
					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
			{
				print_r($response);
			}
		}
	}

	SearchRecords::initialize();
	$moduleAPIName = "Leads";
	SearchRecords::searchRecords($moduleAPIName);
    ?>
    
Convert a Lead

              <?php
namespace samples\record;

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\record\APIException;
use com\zoho\crm\api\record\ConvertActionWrapper;
use com\zoho\crm\api\record\ConvertBodyWrapper;
use com\zoho\crm\api\record\LeadConverter;
use com\zoho\crm\api\record\RecordOperations;
use com\zoho\crm\api\record\SuccessfulConvert;
use com\zoho\crm\api\record\{ Deals };
use com\zoho\crm\api\util\Choice;
use com\zoho\crm\api\record\CarryOverTags;
require_once "vendor/autoload.php";

class ConvertLead
{
    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 convertLead(string $recordId)
	{
		$recordOperations = new RecordOperations();
		$request = new ConvertBodyWrapper();
		$data = array();
		$record1 = new LeadConverter();
		// $record1->setOverwrite(true);
		// $record1->setNotifyLeadOwner(true);
		// $record1->setNotifyNewEntityOwner(true);
		// $record1->setAccounts("34770615848125");
		// $record1->setContacts("34770610358009");
		// $record1->setAssignTo("34770610173021");
		$recordClass = 'com\zoho\crm\api\record\Record';
		$deals = new $recordClass();
		/*
		 * Call addFieldValue method that takes two arguments
		 * 1 -> Call Field "." and choose the module from the displayed list and press "." and choose the field name from the displayed list.
		 * 2 -> Value
		 */
		$deals->addFieldValue(Deals::DealName(), "deal_name");
		$deals->addFieldValue(Deals::Description(), "deals description");
		$deals->addFieldValue(Deals::ClosingDate(), new \DateTime("2021-06-02"));
		$deals->addFieldValue(Deals::Stage(), new Choice("Closed Won"));
		$deals->addFieldValue(Deals::Amount(), 50.7);
		$deals->addKeyValue("Pipeline", new Choice("Qualification"));
		/*
		 * Call addKeyValue method that takes two arguments
		 * 1 -> A string that is the Field's API Name
		 * 2 -> Value
		 */
		$deals->addKeyValue("Custom_field", "Value");
		$deals->addKeyValue("Custom_field_2", "value");
		$record1->setDeals($deals);
		$carryOverTags = new CarryOverTags();
		$carryOverTags->setAccounts(["Test"]);
		$carryOverTags->setContacts(["Test"]);
		$carryOverTags->setDeals(["Test"]);
		$record1->setCarryOverTags($carryOverTags);
		array_push($data, $record1);
		$request->setData($data);
		$response = $recordOperations->convertLead($recordId,$request );
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
			if($response->isExpected())
			{
				$convertActionHandler = $response->getObject();
				if($convertActionHandler instanceof ConvertActionWrapper)
				{
					$convertActionWrapper = $convertActionHandler;
					$convertActionResponses = $convertActionWrapper->getData();
					foreach($convertActionResponses as $convertActionResponse)
					{
						if($convertActionResponse instanceof SuccessfulConvert)
						{
							$successfulConvert = $convertActionResponse;
							echo("LeadConvert Accounts ID: " . $successfulConvert->getAccounts() . "\n");
							echo("LeadConvert Contacts ID: " . $successfulConvert->getContacts() . "\n");
							echo("LeadConvert Deals ID: " . $successfulConvert->getDeals() . "\n");
						}
						else if($convertActionResponse instanceof APIException)
						{
							$exception = $convertActionResponse;
							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");
						}
					}
				}
				else if($convertActionHandler instanceof APIException)
				{
					$exception = $convertActionHandler;
					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");
				}
			}
			else
			{
				print_r($response);
			}
		}
	}
}

ConvertLead::initialize();
$recordId = "347706118046059";
ConvertLead::convertLead($recordId);
?>
Get a Record's Photo

              
<?php
namespace samples\record;

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\record\APIException;
use com\zoho\crm\api\record\FileBodyWrapper;
use com\zoho\crm\api\record\RecordOperations;
require_once "vendor/autoload.php";

class GetPhoto
{
    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 getPhoto(string $moduleAPIName, string $recordId, string $destinationFolder)
	{
		$recordOperations = new RecordOperations();
		$response = $recordOperations->getPhoto($recordId,$moduleAPIName );
		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;
			}
			if($response->isExpected())
			{
				$downloadHandler = $response->getObject();
				if($downloadHandler instanceof FileBodyWrapper)
				{
					$fileBodyWrapper = $downloadHandler;
					$streamWrapper = $fileBodyWrapper->getFile();
					$fp = fopen($destinationFolder."/".$streamWrapper->getName(), "w");
					$stream = $streamWrapper->getStream();
					fputs($fp, $stream);
					fclose($fp);
				}
				else if($downloadHandler instanceof APIException)
				{
					$exception = $downloadHandler;
					echo("Status: " . $exception->getStatus()->getValue() . "\n");
					echo("Code: " . $exception->getCode()->getValue() . "\n");
					if($exception->getDetails() != null)
					{
						echo("Details: \n");
						foreach ($exception->getDetails() as $keyName => $keyValue)
						{
							echo($keyName . ": " . $keyValue . "\n");
						}
					}
					echo("Message: " . $exception->getMessage()->getValue() . "\n");
				}
			}
			else
			{
				print_r($response);
			}
		}
	}
}

GetPhoto::initialize();
$moduleAPIName = "Leads";
$recordId = "347706118046059";
$destinationFolder = "/Documents/";
GetPhoto::getPhoto($moduleAPIName, $recordId, $destinationFolder);
?>
Upload a Photo to a Record

              
<?php
namespace samples\record;

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\record\APIException;
use com\zoho\crm\api\record\FileBodyWrapper;
use com\zoho\crm\api\record\RecordOperations;
use com\zoho\crm\api\record\SuccessResponse;
use com\zoho\crm\api\util\StreamWrapper;
require_once "vendor/autoload.php";

class UploadPhoto
{
    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 uploadPhoto(string $moduleAPIName, string $recordId, string $absoluteFilePath)
	{
		$recordOperations = new RecordOperations();
		$fileBodyWrapper = new FileBodyWrapper();
		$streamWrapper = new StreamWrapper(null, null, $absoluteFilePath);
		$fileBodyWrapper->setFile($streamWrapper);
		$response = $recordOperations->uploadPhoto($recordId, $moduleAPIName,$fileBodyWrapper);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
			if($response->isExpected())
			{
				$fileHandler = $response->getObject();
				if($fileHandler instanceof SuccessResponse)
				{
					$successResponse = $fileHandler;
					echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
					echo("Code: " . $successResponse->getCode()->getValue() . "\n");
					echo("Details: " );
					if($successResponse->getDetails() != null)
					{
						foreach ($successResponse->getDetails() as $keyName => $keyValue)
						{
							echo($keyName . ": " . $keyValue . "\n");
						}
					}
					echo("Message: " . $successResponse->getMessage()->getValue() . "\n");
				}
				else if($fileHandler instanceof APIException)
				{
					$exception = $fileHandler;
					echo("Status: " . $exception->getStatus()->getValue() . "\n");
					echo("Code: " . $exception->getCode()->getValue() . "\n");
					echo("Details: " );
					if($exception->getDetails() != null)
					{
						foreach ($exception->getDetails() as $keyName => $keyValue)
						{
							echo($keyName . ": " . $keyValue . "\n");
						}
					}
					echo("Message: " . $exception->getMessage()->getValue() . "\n");
				}
			}
			else
			{
				print_r($response);
			}
		}
	}
}

UploadPhoto::initialize();
$moduleAPIName = "Leads";
$recordId = "347706118046059";
$absoluteFilePath = "/Documents/download.png";
UploadPhoto::uploadPhoto($moduleAPIName, $recordId, $absoluteFilePath);
?>
Delete the Photo of a Record

              
<?php
namespace samples\record;

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\record\APIException;
use com\zoho\crm\api\record\RecordOperations;
use com\zoho\crm\api\record\SuccessResponse;
require_once "vendor/autoload.php";

class DeletePhoto
{
    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 deletePhoto(string $moduleAPIName, string $recordId)
	{
		$recordOperations = new RecordOperations();
		$response = $recordOperations->deletePhoto($recordId,$moduleAPIName);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
			if($response->isExpected())
			{
				$fileHandler = $response->getObject();
				if($fileHandler instanceof SuccessResponse)
				{
					$successResponse = $fileHandler;
					echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
					echo("Code: " . $successResponse->getCode()->getValue() . "\n");
					echo("Details: " );
					if($successResponse->getDetails() != null)
					{
						foreach ($successResponse->getDetails() as $keyName => $keyValue)
						{
							echo($keyName . ": " . $keyValue . "\n");
						}
					}
					echo("Message: " . $successResponse->getMessage()->getValue() . "\n");
				}
				else if($fileHandler instanceof APIException)
				{
					$exception = $fileHandler;
					echo("Status: " . $exception->getStatus()->getValue() . "\n");
					echo("Code: " . $exception->getCode()->getValue() . "\n");
					echo("Details: " );
					if($exception->getDetails() != null)
					{
						foreach ($exception->getDetails() as $keyName => $keyValue)
						{
							echo($keyName . ": " . $keyValue . "\n");
						}
					}
					echo("Message: " . $exception->getMessage()->getValue() . "\n");
				}
			}
			else
			{
				print_r($response);
			}
		}
	}
}

DeletePhoto::initialize();
$moduleAPIName = "Leads";
$recordId = "347706118046059";
DeletePhoto::deletePhoto($moduleAPIName, $recordId);
?>
Mass Update Records

              
<?php
namespace samples\record;

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\record\APIException;
use com\zoho\crm\api\record\MassUpdateActionWrapper;
use com\zoho\crm\api\record\MassUpdateBodyWrapper;
use com\zoho\crm\api\record\MassUpdateSuccessResponse;
use com\zoho\crm\api\record\RecordOperations;
require_once "vendor/autoload.php";

class MassUpdateRecords
{
    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 massUpdateRecords(string $moduleAPIName)
	{
		$recordOperations = new RecordOperations();
		$request = new MassUpdateBodyWrapper();
		$records = array();
		$recordClass = 'com\zoho\crm\api\record\Record';
		$record1 = new $recordClass();
		/*
		 * Call addKeyValue method that takes two arguments
		 * 1 -> A string that is the Field's API Name
		 * 2 -> Value
		 */
		$record1->addKeyValue("City", "Value");
		array_push($records, $record1);
		$request->setData($records);
		$request->setCvid("34770610087501");
		$ids = array("3477061012054037");
		$request->setIds($ids);
		// $territory = new Territory();
		// $territory->setId("34770613051357");
		// $territory->setIncludeChild(true);
		// $request->setTerritory($territory);
		$request->setOverWrite(true);
		$response = $recordOperations->massUpdateRecords($moduleAPIName, $request);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
			if($response->isExpected())
			{
				$massUpdateActionHandler = $response->getObject();
				if($massUpdateActionHandler instanceof MassUpdateActionWrapper)
				{
					$massUpdateActionWrapper = $massUpdateActionHandler;
					$massUpdateActionResponses = $massUpdateActionWrapper->getData();
					foreach($massUpdateActionResponses as $massUpdateActionResponse)
					{
						if($massUpdateActionResponse instanceof MassUpdateSuccessResponse)
						{
							$massUpdateSuccessResponse = $massUpdateActionResponse;
							echo("Status: " . $massUpdateSuccessResponse->getStatus()->getValue() . "\n");
							echo("Code: " . $massUpdateSuccessResponse->getCode()->getValue() . "\n");
							if($massUpdateSuccessResponse->getDetails() != null)
							{
								echo("Details: " );
								foreach ($massUpdateSuccessResponse->getDetails() as $keyName => $keyValue)
								{
									echo($keyName . ": ");
									print_r($keyValue);
									echo("\n");
								}
							}
							echo("Message: " . $massUpdateSuccessResponse->getMessage()->getValue() . "\n");
						}
						else if($massUpdateActionResponse instanceof APIException)
						{
							$exception = $massUpdateActionResponse;
							echo("Status: " . $exception->getStatus()->getValue() . "\n");
							echo("Code: " . $exception->getCode()->getValue() . "\n");
							echo("Details: " );
							if($exception->getDetails() != null)
							{
								foreach ($exception->getDetails() as $keyName => $keyValue)
								{
									echo($keyName . ": " . $keyValue . "\n");
								}
							}
							echo("Message: " . $exception->getMessage()->getValue() . "\n");
						}
					}
				}
				else if($massUpdateActionHandler instanceof APIException)
				{
					$exception = $massUpdateActionHandler;
					echo("Status: " . $exception->getStatus()->getValue() . "\n");
					echo("Code: " . $exception->getCode()->getValue() . "\n");
					if($exception->getDetails() != null)
					{
						echo("Details: " );
						foreach ($exception->getDetails() as $keyName => $keyValue)
						{
							echo($keyName . ": " . $keyValue . "\n");
						}
					}
					echo("Message: " . $exception->getMessage()->getValue() . "\n");
				}
			}
			else
			{
				print_r($response);
			}
		}
	}
}

MassUpdateRecords::initialize();
$moduleAPIName = "Leads";
MassUpdateRecords::massUpdateRecords($moduleAPIName);
?>
Get the Status of Mass Update

              
<?php
namespace samples\record;

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\record\APIException;
use com\zoho\crm\api\record\MassUpdate;
use com\zoho\crm\api\record\MassUpdateResponseWrapper;
use com\zoho\crm\api\record\RecordOperations;
use com\zoho\crm\api\record\GetMassUpdateStatusParam;
require_once "vendor/autoload.php";

class GetMassUpdateStatus
{
    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 getMassUpdateStatus(string $moduleAPIName, string $jobId)
	{
		$recordOperations = new RecordOperations();
		$paramInstance = new ParameterMap();
		$paramInstance->add(GetMassUpdateStatusParam::jobId(), $jobId);
		$response = $recordOperations->getMassUpdateStatus($moduleAPIName,$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;
			}
			if($response->isExpected())
			{
				$massUpdateResponseHandler = $response->getObject();
				if($massUpdateResponseHandler instanceof MassUpdateResponseWrapper)
				{
					$massUpdateResponseWrapper = $massUpdateResponseHandler;
					$massUpdateResponses = $massUpdateResponseWrapper->getData();
					foreach($massUpdateResponses as $massUpdateResponse)
					{
						if($massUpdateResponse instanceof MassUpdate)
						{
							$massUpdate = $massUpdateResponse;
							echo("MassUpdate Status: " . $massUpdate->getStatus()->getValue() . "\n");
							echo("MassUpdate FailedCount: " . $massUpdate->getFailedCount() . "\n");
							echo("MassUpdate UpdatedCount: " . $massUpdate->getUpdatedCount() . "\n");
							echo("MassUpdate NotUpdatedCount: " . $massUpdate->getNotUpdatedCount() . "\n");
							echo("MassUpdate TotalCount: " . $massUpdate->getTotalCount() . "\n");
						}
						else if($massUpdateResponse instanceof APIException)
						{
							$exception = $massUpdateResponse;
							echo("Status: " . $exception->getStatus()->getValue() . "\n");
							echo("Code: " . $exception->getCode()->getValue() . "\n");
							if($exception->getDetails() != null)
							{
								echo("Details: " );
								foreach ($exception->getDetails() as $keyName => $keyValue)
								{
									echo($keyName . ": " . $keyValue . "\n");
								}
							}
							echo("Message: " . $exception->getMessage()->getValue() . "\n");
						}
					}
				}
				else if($massUpdateResponseHandler instanceof APIException)
				{
					$exception = $massUpdateResponseHandler;
					echo("Status: " . $exception->getStatus()->getValue() . "\n");
					echo("Code: " . $exception->getCode()->getValue() . "\n");
					echo("Details: " );
					if($exception->getDetails() != null)
					{
						echo("Details: " );
						foreach ($exception->getDetails() as $keyName => $keyValue)
						{
							echo($keyName . ": " . $keyValue . "\n");
						}
					}
					echo("Message: " . $exception->getMessage()->getValue() . "\n");
				}
			}
			else
			{
				print_r($response);
			}
		}
	}
}

GetMassUpdateStatus::initialize();
$moduleAPIName = "Leads";
$jobId = "34770619879007";
GetMassUpdateStatus::getMassUpdateStatus($moduleAPIName, $jobId);
?>
Get Record Count

              
<?php
namespace samples\record;

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\record\APIException;
use com\zoho\crm\api\record\RecordOperations;
use com\zoho\crm\api\record\RecordCountParam;
use com\zoho\crm\api\record\CountWrapper;
require_once "vendor/autoload.php";

class GetRecordCount
{
    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 getRecordCount()
	{
		$recordOperations = new RecordOperations();
		$moduleAPIName = "Leads";
		$paramInstance = new ParameterMap();
		$paramInstance->add(RecordCountParam::phone(), "(990) -0");
		$response = $recordOperations->recordCount($moduleAPIName, $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;
			}
			if($response->isExpected())
			{
				$countHandler = $response->getObject();
				if($countHandler instanceof CountWrapper)
				{
					$countWrapper = $countHandler;
					echo("Record Count: " . $countWrapper->getCount()); echo("\n");
				}
				else if($countHandler instanceof APIException)
				{
					$exception = $countHandler;
					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
			{
				
				print_r($response);
			}
		}
	}
}

GetRecordCount::initialize();
GetRecordCount::getRecordCount();
?>
Assign Territories to Multiple Records

              
<?php
namespace samples\record;

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\record\APIException;
use com\zoho\crm\api\record\ActionWrapper;
use com\zoho\crm\api\record\BodyWrapper;
use com\zoho\crm\api\record\RecordOperations;
use com\zoho\crm\api\record\SuccessResponse;
use com\zoho\crm\api\record\Territory;
require_once "vendor/autoload.php";

class AssignTerritoriesToMultipleRecords
{
    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 assignTerritoriesToMultipleRecords($moduleAPIName)
	{
		$recordOperations = new RecordOperations();
		$request = new BodyWrapper();
		$records = [];
		$recordClass = 'com\zoho\crm\api\record\Record';
		$record1 = new $recordClass();
		$record1->setId("3477061012107002");
		/*
		 * Call addKeyValue method that takes two arguments
		 * 1 -> A string that is the Field's API Name
		 * 2 -> Value
		 */
		$territory = new Territory();
		$territory->setId("34770613051397");
		$record1->addKeyValue("Territories", [$territory]);
		array_push($records, $record1);
		$request->setData($records);
		$response = $recordOperations->assignTerritoriesToMultipleRecords($moduleAPIName, $request);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
			if($response->isExpected())
			{
				$actionHandler = $response->getObject();
				if($actionHandler instanceof ActionWrapper)
				{
					$actionWrapper = $actionHandler;
					$actionResponses = $actionWrapper->getData();
					foreach($actionResponses as $actionResponse)
					{
						if($actionResponse instanceof SuccessResponse)
						{
							$successResponse = $actionResponse;
							echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
							echo("Code: " . $successResponse->getCode()->getValue() . "\n");
							echo("Details: " );
							foreach($successResponse->getDetails() as $key => $value)
							{
								echo($key . " : ");
								print_r($value);
								echo("\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");
				}
			}
			else
			{
				print_r($response);
			}
		}
	}
}

AssignTerritoriesToMultipleRecords::initialize();
$moduleAPIName = "Leads";
AssignTerritoriesToMultipleRecords::assignTerritoriesToMultipleRecords($moduleAPIName);
?>
Assign Territory to Record

              
<?php
namespace samples\record;

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\record\APIException;
use com\zoho\crm\api\record\ActionWrapper;
use com\zoho\crm\api\record\BodyWrapper;
use com\zoho\crm\api\record\RecordOperations;
use com\zoho\crm\api\record\SuccessResponse;
use com\zoho\crm\api\record\Territory;
require_once "vendor/autoload.php";

class AssignTerritoryToRecord
{
    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 assignTerritoryToRecord($moduleAPIName, $id)
	{
		$recordOperations = new RecordOperations();
		$request = new BodyWrapper();
		$records = array();
		$recordClass = 'com\zoho\crm\api\record\Record';
		$record1 = new $recordClass();
		/*
		 * Call addKeyValue method that takes two arguments
		 * 1 -> A string that is the Field's API Name
		 * 2 -> Value
		 */
		$territory = new Territory();
		$territory->setId("34770613051397");
		$record1->addKeyValue("Territories", [$territory]);
		array_push($records, $record1);
		$request->setData($records);
		$response = $recordOperations->assignTerritoryToRecord($moduleAPIName, $id, $request);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
			if($response->isExpected())
			{
				$actionHandler = $response->getObject();
				if($actionHandler instanceof ActionWrapper)
				{
					$actionWrapper = $actionHandler;
					$actionResponses = $actionWrapper->getData();
					foreach($actionResponses as $actionResponse)
					{
						if($actionResponse instanceof SuccessResponse)
						{
							$successResponse = $actionResponse;
							echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
							echo("Code: " . $successResponse->getCode()->getValue() . "\n");
							echo("Details: " );
							foreach($successResponse->getDetails() as $key => $value)
							{
								echo($key . " : ");
								print_r($value);
								echo("\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");
				}
			}
			else
			{
				print_r($response);
			}
		}
	}
}

AssignTerritoryToRecord::initialize();
$moduleAPIName = "Leads";
$recordId = "347706112184003";
AssignTerritoryToRecord::assignTerritoryToRecord($moduleAPIName, $recordId);
?>
Remove Territories from Multile Records

              
<?php
namespace samples\record;

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\record\APIException;
use com\zoho\crm\api\record\ActionWrapper;
use com\zoho\crm\api\record\BodyWrapper;
use com\zoho\crm\api\record\RecordOperations;
use com\zoho\crm\api\record\SuccessResponse;
use com\zoho\crm\api\record\Territory;
require_once "vendor/autoload.php";

class RemoveTerritoriesFromMultipleRecords
{
    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 removeTerritoriesFromMultipleRecords($moduleAPIName)
	{
		$recordOperations = new RecordOperations();	
		$request = new BodyWrapper();
		$records = array();
		$recordClass = 'com\zoho\crm\api\record\Record';
		$record1 = new $recordClass();
		$record1->setId("3477061012107002");
		/*
		 * Call addKeyValue method that takes two arguments
		 * 1 -> A string that is the Field's API Name
		 * 2 -> Value
		 */
		$territory = new Territory();
		$territory->setId("34770613051397");
		$record1->addKeyValue("Territories", [$territory]);
		array_push($records, $record1);
		$request->setData($records);
		$response = $recordOperations->removeTerritoriesFromMultipleRecords($moduleAPIName, $request);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
			if($response->isExpected())
			{
				$actionHandler = $response->getObject();
				if($actionHandler instanceof ActionWrapper)
				{
					$actionWrapper = $actionHandler;
					$actionResponses = $actionWrapper->getData();
					foreach($actionResponses as $actionResponse)
					{
						if($actionResponse instanceof SuccessResponse)
						{
							$successResponse = $actionResponse;
							echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
							echo("Code: " . $successResponse->getCode()->getValue() . "\n");
							echo("Details: " );
							foreach($successResponse->getDetails() as $key => $value)
							{
								echo($key . " : ");
								print_r($value);
								echo("\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");
				}
			}
			else
			{
				print_r($response);
			}
		}
	}
}

RemoveTerritoriesFromMultipleRecords::initialize();
$moduleAPIName = "Leads";
RemoveTerritoriesFromMultipleRecords::removeTerritoriesFromMultipleRecords($moduleAPIName);
?>
Remove Territories from Record

              
<?php
namespace samples\record;

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\record\APIException;
use com\zoho\crm\api\record\ActionWrapper;
use com\zoho\crm\api\record\BodyWrapper;
use com\zoho\crm\api\record\RecordOperations;
use com\zoho\crm\api\record\SuccessResponse;
use com\zoho\crm\api\record\Territory;
require_once "vendor/autoload.php";

class RemoveTerritoriesFromRecord
{
	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 removeTerritoriesFromRecord($moduleAPIName, $id)
	{
		$recordOperations = new RecordOperations();	
		$request = new BodyWrapper();
		$records = array();
		$recordClass = 'com\zoho\crm\api\record\Record';
		$record1 = new $recordClass();
		/*
		 * Call addKeyValue method that takes two arguments
		 * 1 -> A string that is the Field's API Name
		 * 2 -> Value
		 */
		$territory = new Territory();
		$territory->setId("34770613051397");
		$record1->addKeyValue("Territories", [$territory]);
		array_push($records, $record1);
		$request->setData($records);
		$response = $recordOperations->removeTerritoriesFromRecord($moduleAPIName, $id, $request);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
			if($response->isExpected())
			{
				$actionHandler = $response->getObject();
				if($actionHandler instanceof ActionWrapper)
				{
					$actionWrapper = $actionHandler;
					$actionResponses = $actionWrapper->getData();
					foreach($actionResponses as $actionResponse)
					{
						if($actionResponse instanceof SuccessResponse)
						{
							$successResponse = $actionResponse;
							echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
							echo("Code: " . $successResponse->getCode()->getValue() . "\n");
							echo("Details: " );
							foreach($successResponse->getDetails() as $key => $value)
							{
								echo($key . " : ");
								print_r($value);
								echo("\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");
				}
			}
			else
			{
				print_r($response);
			}
		}
	}
}

RemoveTerritoriesFromRecord::initialize();
$moduleAPIName = "Leads";
$recordId = "347706112184003";
RemoveTerritoriesFromRecord::removeTerritoriesFromRecord($moduleAPIName, $recordId);
?>