<?php
session_start();
require './sdk/vendor/autoload.php';
use zcrmsdk\oauth\ZohoOAuth;
use zcrmsdk\crm\crud\ZCRMInventoryLineItem;
use zcrmsdk\crm\crud\ZCRMJunctionRecord;
use zcrmsdk\crm\crud\ZCRMNote;
use zcrmsdk\crm\crud\ZCRMRecord;
use zcrmsdk\crm\crud\ZCRMTax;
use zcrmsdk\crm\setup\restclient\ZCRMRestClient;
use zcrmsdk\crm\setup\users\ZCRMUser;
class Api {
public function __construct(){
if(!isset($_SESSION['zoho'])){
$grantToken = '1000.3e49260f5f48be3c435ba1946abd3dab.873b0b6ad49b2c0152170805f56eef14';
$configuration = array('Content-Type: application/x-www-form-urlencoded');
$configuration['code'] = ''.$grantToken.'';
$configuration['client_id'] = 'OMITTED';
$configuration['client_secret'] = 'OMITTED';
$configuration['sandbox'] = true;
$configuration['db_port'] = '3306';
$configuration['db_username'] = 'root';
$configuration['db_password'] = '';
$configuration['currentUserEmail'] = 'OMITTED';
ZCRMRestClient::initialize($configuration);
$oAuthClient = ZohoOAuth::getClientInstance();
$oAuthTokens = $oAuthClient->generateAccessToken($grantToken);
$_SESSION['zoho'] = $oAuthTokens;
var_dump($_SESSION['zoho']);
exit;
var_dump($oAuthTokens);
header('Location: test.php');
exit;
}
}
public static function record(){
$record = ZCRMRestClient::getInstance()->getRecordInstance("{module_api_name}", NULL); // To get record instance
$record->setFieldValue("Subject", "test2312"); // This function use to set FieldApiName and value similar to all other FieldApis and Custom field
$record->setFieldValue("Account_Name", "{account_id}"); // Account Name can be given for a new account, account_id is not mandatory in that case
/**
* Following methods are being used only by Inventory modules *
*/
$lineItem = ZCRMInventoryLineItem::getInstance(null); // To get ZCRMInventoryLineItem instance
$lineItem->setDescription("Product_description"); // To set line item description
$lineItem->setDiscount(5); // To set line item discount
$lineItem->setListPrice(100); // To set line item list price
$taxInstance1 = ZCRMTax::getInstance("{tax_name}"); // To get ZCRMTax instance
$taxInstance1->setPercentage(2); // To set tax percentage
$taxInstance1->setValue(50); // To set tax value
$lineItem->addLineTax($taxInstance1); // To set line tax to line item
$taxInstance1 = ZCRMTax::getInstance("{tax_name}");
$taxInstance1->setPercentage(12);
$taxInstance1->setValue(50);
$lineItem->addLineTax($taxInstance1);
$lineItem->setProduct(ZCRMRecord::getInstance("{module_api_name}", "{record_id}")); // To set product to line item
$lineItem->setQuantity(100); // To set product quantity to this line item
$record->addLineItem($lineItem);
/**
* photo can be uploaded only for certain modules *
*/
// $record->uploadPhoto("/path/to/file");//to upload a photo of the record
$trigger=array();//triggers to include
$lar_id="lar_id";//lead assignment rule id
$responseIns = $record->create($trigger,$lar_id);//$trigger , $larid optional
echo "HTTP Status Code:" . $responseIns->getHttpStatusCode(); // To get http response code
echo "Status:" . $responseIns->getStatus(); // To get response status
echo "Message:" . $responseIns->getMessage(); // To get response message
echo "Code:" . $responseIns->getCode(); // To get status code
echo "Details:" . json_encode($responseIns->getDetails());
}
}
$api = new Api;
$_SERVER['user_email_id']= 'OMITTED';
$api->record();
?>