PHP SDK Samples - Pipeline Operations
<?php
namespace samples\pipeline;
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\pipeline\PipelineOperations;
use com\zoho\crm\api\pipeline\APIException;
use com\zoho\crm\api\pipeline\ResponseWrapper;
require_once "vendor/autoload.php";
class GetPipelines
{
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 getPipelines($layoutId)
{
$pipelineOperations = new PipelineOperations($layoutId);
$response = $pipelineOperations->getPipelines();
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;
}
$responseHandler = $response->getObject();
if($responseHandler instanceof ResponseWrapper)
{
$responseWrapper = $responseHandler;
$pipelines = $responseWrapper->getPipeline();
foreach($pipelines as $pipeline)
{
echo("Pipeline DisplayValue: " . $pipeline->getDisplayValue() . "\n");
echo("Pipeline Default: "); print_r($pipeline->getDefault()); echo("\n");
$maps = $pipeline->getMaps();
if($maps != null)
{
foreach($maps as $map)
{
echo("Pipeline Maps DisplayValue: " . $map->getDisplayValue() . "\n");
echo("Pipeline Maps SequenceNumber: " . $map->getSequenceNumber() . "\n");
$forecastCategory = $map->getForecastCategory();
if($forecastCategory != null)
{
echo("Pipeline Maps ForecastCategory Name: " . $forecastCategory->getName() . "\n");
echo("Pipeline Maps ForecastCategory Id: " . $forecastCategory->getId() . "\n");
}
echo("Pipeline Maps ActualValue: " . $map->getActualValue() . "\n");
echo("Pipeline Maps Id: " . $map->getId() . "\n");
echo("Pipeline Maps ForecastType: " . $map->getForecastType() . "\n");
}
}
echo("Pipeline Maps ActualValue: " . $pipeline->getActualValue() . "\n");
echo("Pipeline Id: " . $pipeline->getId() . "\n");
}
}
else if($responseHandler instanceof APIException)
{
$exception = $responseHandler;
echo("Status: " . $exception->getStatus()->getValue());
echo("Code: " . $exception->getCode()->getValue());
echo("Details: " );
foreach($exception->getDetails() as $key => $value)
{
echo($key . ": " . $value);
}
echo("Message: " . $exception->getMessage()->getValue());
}
}
}
}
GetPipelines::initialize();
$layoutId = "34770610091023";
GetPipelines::getPipelines($layoutId);
?>
<?php
namespace samples\pipeline;
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\pipeline\PipelineOperations;
use com\zoho\crm\api\pipeline\TransferAndDeleteWrapper;
use com\zoho\crm\api\pipeline\Stage;
use com\zoho\crm\api\pipeline\TransferPipeLine;
use com\zoho\crm\api\pipeline\SuccessResponse;
use com\zoho\crm\api\pipeline\APIException;
use com\zoho\crm\api\pipeline\TransferActionWrapper;
require_once "vendor/autoload.php";
class TransferAndDelete
{
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 transferAndDelete($layoutId)
{
$pipelineOperations = new PipelineOperations($layoutId);
$transferAndDeleteWrapper = new TransferAndDeleteWrapper();
$transferPipeLine = new TransferPipeLine();
$pipelineClass = "com\\zoho\\crm\\api\\pipeline\\PipeLine";
$pipeline = new $pipelineClass();
$pipeline->setFrom("36523973712004");
$pipeline->setTo("36523973097007");
$transferPipeLine->setPipeline($pipeline);
$stage = new Stage();
$stage->setFrom("3652396817");
$stage->setTo("3652396819");
$transferPipeLine->setStages([$stage]);
$transferAndDeleteWrapper->setTransferPipeline([$transferPipeLine]);
$response = $pipelineOperations->transferAndDelete($transferAndDeleteWrapper);
if($response != null)
{
echo("Status code" . $response->getStatusCode() . "\n");
$actionHandler = $response->getObject();
if($actionHandler instanceof TransferActionWrapper)
{
$actionWrapper = $actionHandler;
$actionResponses = $actionWrapper->getTransferPipeline();
foreach ($actionResponses as $actionResponse)
{
if($actionResponse instanceof SuccessResponse)
{
$successResponse = $actionResponse;
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($actionResponse instanceof APIException)
{
$exception = $actionResponse;
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($actionHandler instanceof APIException)
{
$exception = $actionHandler;
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");
}
}
}
}
TransferAndDelete::initialize();
$layoutId = "34770610091023";
TransferAndDelete::transferAndDelete($layoutId);
?>
<?php
namespace samples\pipeline;
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\pipeline\PipelineOperations;
use com\zoho\crm\api\pipeline\PickListValue;
use com\zoho\crm\api\pipeline\ActionWrapper;
use com\zoho\crm\api\pipeline\SuccessResponse;
use com\zoho\crm\api\pipeline\APIException;
use com\zoho\crm\api\pipeline\PipeLine;
require_once "vendor/autoload.php";
class CreatePipelines
{
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 createPipelines($layoutId)
{
$pipelineOperations = new PipelineOperations($layoutId);
$pipeline = new PipeLine();
$pipeline->setDisplayValue("Adfas23fsad1332");
$pickList = new PickListValue();
$pickList->setId("34770616805");
$pickList->setSequenceNumber(1);
$pipeline->setMaps([$pickList]);
$bodyWrapper = "com\\zoho\\crm\\api\\pipeline\\BodyWrapper";
$body = new $bodyWrapper();
$body->setPipeline([$pipeline]);
$response = $pipelineOperations->createPipelines($body);
if($response != null)
{
echo("Status code" . $response->getStatusCode() . "\n");
$actionHandler = $response->getObject();
if($actionHandler instanceof ActionWrapper)
{
$actionWrapper = $actionHandler;
$actionResponses = $actionWrapper->getPipeline();
foreach ($actionResponses as $actionResponse)
{
if($actionResponse instanceof SuccessResponse)
{
$successResponse = $actionResponse;
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($actionResponse instanceof APIException)
{
$exception = $actionResponse;
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($actionHandler instanceof APIException)
{
$exception = $actionHandler;
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");
}
}
}
}
CreatePipelines::initialize();
$layoutId = "34770610091023";
CreatePipelines::createPipelines($layoutId);
?>
<?php
namespace samples\pipeline;
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\pipeline\PipelineOperations;
use com\zoho\crm\api\pipeline\APIException;
use com\zoho\crm\api\pipeline\ResponseWrapper;
require_once "vendor/autoload.php";
class GetPipeline
{
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 getPipeline($layoutId, $pipelineId)
{
$pipelineOperations = new PipelineOperations($layoutId);
$response = $pipelineOperations->getPipeline($pipelineId);
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;
}
$responseHandler = $response->getObject();
if($responseHandler instanceof ResponseWrapper)
{
$responseWrapper = $responseHandler;
$pipelines = $responseWrapper->getPipeline();
foreach($pipelines as $pipeline)
{
echo("Pipeline DisplayValue: " . $pipeline->getDisplayValue() . "\n");
echo("Pipeline Default: "); print_r($pipeline->getDefault()); echo("\n");
$maps = $pipeline->getMaps();
if($maps != null)
{
foreach($maps as $map)
{
echo("Pipeline Maps DisplayValue: " . $map->getDisplayValue() . "\n");
echo("PickListValue Sequence Number" . $map->getSequenceNumber());
echo("Pipeline Maps SequenceNumber: " . $map->getSequenceNumber() . "\n");
$forecastCategory = $map->getForecastCategory();
if($forecastCategory != null)
{
echo("Pipeline Maps ForecastCategory Name: " . $forecastCategory->getName() . "\n");
echo("Pipeline Maps ForecastCategory Id: " . $forecastCategory->getId() . "\n");
}
echo("Pipeline Maps ActualValue: " . $map->getActualValue() . "\n");
echo("Pipeline Maps Id: " . $map->getId() . "\n");
echo("Pipeline Maps ForecastType: " . $map->getForecastType() . "\n");
echo("PickListValue delete" . $map->getDelete());
}
}
echo("Pipeline Maps ActualValue: " . $pipeline->getActualValue() . "\n");
echo("Pipeline Id: " . $pipeline->getId() . "\n");
}
}
else if($responseHandler instanceof APIException)
{
$exception = $responseHandler;
echo("Status: " . $exception->getStatus()->getValue());
echo("Code: " . $exception->getCode()->getValue());
echo("Details: " );
foreach($exception->getDetails() as $key => $value)
{
echo($key . ": " . $value);
}
echo("Message: " . $exception->getMessage()->getValue());
}
}
}
}
GetPipeline::initialize();
$layoutId = "34770610091023";
$pipelineId = "34770619482001";
GetPipeline::getPipeline($layoutId, $pipelineId);
?>
<?php
namespace samples\pipeline;
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\pipeline\PipelineOperations;
use com\zoho\crm\api\pipeline\PickListValue;
use com\zoho\crm\api\pipeline\ActionWrapper;
use com\zoho\crm\api\pipeline\SuccessResponse;
use com\zoho\crm\api\pipeline\APIException;
require_once "vendor/autoload.php";
class UpdatePipeline
{
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 updatePipeline($layoutId, $pipelineId)
{
$pipelineOperations = new PipelineOperations($layoutId);
$pipelineClass = "com\\zoho\\crm\\api\\pipeline\\PipeLine";
$pipeline = new $pipelineClass();
$pipeline->setDisplayValue("Qualification");
$pickList = new PickListValue();
$pickList->setId("3477066801");
$pickList->setSequenceNumber(1);
$pipeline->setMaps([$pickList]);
$bodyWrapper = "com\\zoho\\crm\\api\\pipeline\\BodyWrapper";
$body = new $bodyWrapper();
$body->setPipeline([$pipeline]);
$response = $pipelineOperations->updatePipeline($pipelineId, $body);
if($response != null)
{
echo("Status code" . $response->getStatusCode() . "\n");
$actionHandler = $response->getObject();
if($actionHandler instanceof ActionWrapper)
{
$actionWrapper = $actionHandler;
$actionResponses = $actionWrapper->getPipeline();
foreach ($actionResponses as $actionResponse)
{
if($actionResponse instanceof SuccessResponse)
{
$successResponse = $actionResponse;
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($actionResponse instanceof APIException)
{
$exception = $actionResponse;
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($actionHandler instanceof APIException)
{
$exception = $actionHandler;
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");
}
}
}
}
UpdatePipeline::initialize();
$layoutId = "34770610091023";
$pipelineId = "34770619482001";
UpdatePipeline::updatePipeline($layoutId, $pipelineId);
?>