PHP SDK Samples - Notification Operations
<?php
namespace samples\notification;
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\notification\APIException;
use com\zoho\crm\api\notification\ActionWrapper;
use com\zoho\crm\api\notification\BodyWrapper;
use com\zoho\crm\api\notification\NotificationOperations;
use com\zoho\crm\api\notification\SuccessResponse;
require_once "vendor/autoload.php";
class EnableNotifications
{
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 enableNotifications()
{
$notificationOperations = new NotificationOperations();
$bodyWrapper = new BodyWrapper();
$notifications = array();
$notificationClass = 'com\zoho\crm\api\notification\Notification';
$notification = new $notificationClass();
$notification->setChannelId("1006800211");
$events = array();
array_push($events, "Deals.all");
$notification->setEvents($events);
$notification->setChannelExpiry(date_create("2019-05-07T15:32:24")->setTimezone(new \DateTimeZone(date_default_timezone_get())));
$notification->setToken("TOKEN_FOR_VERIFICATION_OF_10068002");
$notification->setNotifyUrl("https://www.zohoapis.com");
array_push($notifications, $notification);
$notification2 = new $notificationClass();
$notification2->setChannelId("1006800211");
$events2 = array();
array_push($events2, "Accounts.all");
$notification2->setEvents($events2);
$dateTime = date_create("2019-05-07T15:32:24")->setTimezone(new \DateTimeZone(date_default_timezone_get()));
$notification2->setChannelExpiry($dateTime);
$notification2->setToken("TOKEN_FOR_VERIFICATION_OF_10068002");
$notification2->setNotifyUrl("https://www.zohoapis.com");
array_push($notifications, $notification2);
$bodyWrapper->setWatch($notifications);
$response = $notificationOperations->enableNotifications($bodyWrapper);
if($response != null)
{
echo("Status Code: " . $response->getStatusCode());
if($response->isExpected())
{
$actionHandler = $response->getObject();
if($actionHandler instanceof ActionWrapper)
{
$actionWrapper = $actionHandler;
$actionResponses = $actionWrapper->getWatch();
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 $keyName => $value)
{
if((is_array($value) && sizeof($value) > 0) && isset($value[0]))
{
if($value[0] instanceof $notificationClass)
{
$eventList = $value;
foreach($eventList as $event)
{
echo("Notification ChannelExpiry: "); print_r($event->getChannelExpiry());
echo("Notification ResourceUri: " . $event->getResourceUri() . "\n");
echo("Notification ResourceId: " . $event->getResourceId() . "\n");
echo("Notification ResourceName: " . $event->getResourceName() . "\n");
echo("Notification ChannelId: " . $event->getChannelId() . "\n");
}
}
}
else
{
echo($keyName . ": "); print_r($value);
}
}
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");
echo("Details: " );
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);
}
}
}
}
EnableNotifications::initialize();
EnableNotifications::enableNotifications();
?>
<?php
namespace samples\notification;
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\notification\APIException;
use com\zoho\crm\api\notification\NotificationOperations;
use com\zoho\crm\api\notification\GetNotificationDetailsParam;
use com\zoho\crm\api\notification\ResponseWrapper;
require_once "vendor/autoload.php";
class GetNotificationDetails
{
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 getNotificationDetails()
{
$notificationOperations = new NotificationOperations();
$paramInstance = new ParameterMap();
$paramInstance->add(GetNotificationDetailsParam::channelId(), "1006800211");
$paramInstance->add(GetNotificationDetailsParam::module(), "Accounts");
$paramInstance->add(GetNotificationDetailsParam::page(), 1);
$paramInstance->add(GetNotificationDetailsParam::perPage(), 2);
$response = $notificationOperations->getNotificationDetails($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())
{
$responseHandler = $response->getObject();
if($responseHandler instanceof ResponseWrapper)
{
$responseWrapper = $responseHandler;
$notifications = $responseWrapper->getWatch();
foreach($notifications as $notification)
{
echo("Notification NotifyOnRelatedAction: " . $notification->getNotifyOnRelatedAction() . "\n");
echo("Notification ChannelExpiry: "); print_r($notification->getChannelExpiry());
echo("Notification ResourceUri: " . $notification->getResourceUri() . "\n");
echo("Notification ResourceId: " . $notification->getResourceId() . "\n");
echo("Notification NotifyUrl: " . $notification->getNotifyUrl() . "\n");
echo("Notification ResourceName: " . $notification->getResourceName() . "\n");
echo("Notification ChannelId: " . $notification->getChannelId() . "\n");
$fields = $notification->getEvents();
if($fields != null)
{
foreach($fields as $fieldName)
{
echo("Notification Events: " . $fieldName . "\n");
}
}
echo("Notification Token: " . $notification->getToken() . "\n");
}
$info = $responseWrapper->getInfo();
if($info != null)
{
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");
if($exception->getDetails() != null)
{
echo("Details: \n");
foreach ($exception->getDetails() as $keyName => $keyValue)
{
echo($keyName . ": " . $keyValue . "\n");
}
}
echo("Message: " . $exception->getMessage()->getValue() . "\n");
}
}
else if($response->getStatusCode() != 204 )
{
print_r($response);
}
}
}
}
GetNotificationDetails::initialize();
GetNotificationDetails::getNotificationDetails();
?>
<?php
namespace samples\notification;
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\notification\APIException;
use com\zoho\crm\api\notification\ActionWrapper;
use com\zoho\crm\api\notification\BodyWrapper;
use com\zoho\crm\api\notification\NotificationOperations;
use com\zoho\crm\api\notification\SuccessResponse;
require_once "vendor/autoload.php";
class UpdateNotifications
{
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 updateNotifications()
{
$notificationOperations = new NotificationOperations();
$bodyWrapper = new BodyWrapper();
$notificationList = array();
$notificationClass = 'com\zoho\crm\api\notification\Notification';
$notification = new $notificationClass();
$notification->setChannelId("1006800211");
$events = array();
array_push($events, "Accounts.all");
$notification->setEvents($events);
$notification->setChannelExpiry(date_create("2021-02-26T15:28:34+05:30")->setTimezone(new \DateTimeZone(date_default_timezone_get())));
$notification->setToken("TOKEN_FOR_VERIFICATION_OF_10068002");
$notification->setNotifyUrl("https://www.zohoapis.com");
array_push($notificationList, $notification);
$bodyWrapper->setWatch($notificationList);
$response = $notificationOperations->updateNotifications($bodyWrapper);
if($response != null)
{
echo("Status Code: " . $response->getStatusCode());
if($response->isExpected())
{
$actionHandler = $response->getObject();
if($actionHandler instanceof ActionWrapper)
{
$actionWrapper = $actionHandler;
$actionResponses = $actionWrapper->getWatch();
foreach($actionResponses as $actionResponse)
{
if($actionResponse instanceof SuccessResponse)
{
$successResponse = $actionResponse;
echo("Status: " . $successResponse->getStatus()->getValue());
echo("Code: " . $successResponse->getCode()->getValue());
echo("Details: " );
foreach($successResponse->getDetails() as $keyName => $value)
{
if((is_array($value) && sizeof($value) > 0) && isset($value[0]))
{
if($value[0] instanceof $notificationClass)
{
$eventList = $value;
foreach($eventList as $event)
{
echo("Notification ChannelExpiry: "); print_r($event->getChannelExpiry());
echo("Notification ResourceUri: " . $event->getResourceUri() . "\n");
echo("Notification ResourceId: " . $event->getResourceId() . "\n");
echo("Notification ResourceName: " . $event->getResourceName() . "\n");
echo("Notification ChannelId: " . $event->getChannelId() . "\n");
}
}
}
else
{
echo($keyName . ": "); print_r($value);
}
}
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)
{
echo("Details: \n");
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");
echo("Details: " );
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);
}
}
}
}
UpdateNotifications::initialize();
UpdateNotifications::updateNotifications();
?>
<?php
namespace samples\notification;
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\notification\APIException;
use com\zoho\crm\api\notification\ActionWrapper;
use com\zoho\crm\api\notification\NotificationOperations;
use com\zoho\crm\api\notification\DisableNotificationsParam;
use com\zoho\crm\api\notification\SuccessResponse;
require_once "vendor/autoload.php";
class DisableNotifications
{
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 disableNotifications(array $channelIds)
{
$notificationOperations = new NotificationOperations();
$paramInstance = new ParameterMap();
foreach($channelIds as $id)
{
$paramInstance->add(DisableNotificationsParam::channelIds(), $id);
}
$response = $notificationOperations->disableNotifications($paramInstance);
if($response != null)
{
echo("Status Code: " . $response->getStatusCode());
if($response->isExpected())
{
$actionHandler = $response->getObject();
if($actionHandler instanceof ActionWrapper)
{
$actionWrapper = $actionHandler;
$actionResponses = $actionWrapper->getWatch();
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)
{
echo("Details: \n");
foreach($successResponse->getDetails() as $keyName => $value)
{
if((is_array($value) && sizeof($value) > 0) && isset($value[0]))
{
$notificationClass = 'com\zoho\crm\api\notification\Notification';
if($value[0] instanceof $notificationClass)
{
$eventList = $value;
foreach($eventList as $event)
{
echo("Notification ChannelExpiry: "); print_r($event->getChannelExpiry());
echo("Notification ResourceUri: " . $event->getResourceUri() . "\n");
echo("Notification ResourceId: " . $event->getResourceId() . "\n");
echo("Notification ResourceName: " . $event->getResourceName() . "\n");
echo("Notification ChannelId: " . $event->getChannelId() . "\n");
}
}
}
else
{
echo($keyName . ": "); print_r($value);
}
}
}
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)
{
echo("Details: \n");
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");
echo("Details: " );
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);
}
}
}
}
DisableNotifications::initialize();
$channelIds = array("1006800211");
DisableNotifications::disableNotifications($channelIds);
?>
<?php
namespace samples\notification;
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\notification\APIException;
use com\zoho\crm\api\notification\ActionWrapper;
use com\zoho\crm\api\notification\BodyWrapper;
use com\zoho\crm\api\notification\NotificationOperations;
use com\zoho\crm\api\notification\SuccessResponse;
require_once "vendor/autoload.php";
class DisableNotification
{
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 disableNotification()
{
$notificationOperations = new NotificationOperations();
$bodyWrapper = new BodyWrapper();
$notificationList = array();
$notificationClass = 'com\zoho\crm\api\notification\Notification';
$notification = new $notificationClass();
$notification->setChannelId("1006800211");
$events = array();
array_push($events, "Deals.edit");
$notification->setEvents($events);
$notification->setDeleteevents(true);
array_push($notificationList, $notification);
$bodyWrapper->setWatch($notificationList);
$response = $notificationOperations->disableNotification($bodyWrapper);
if($response != null)
{
echo("Status Code: " . $response->getStatusCode() . "\n");
if($response->isExpected())
{
$actionHandler = $response->getObject();
if($actionHandler instanceof ActionWrapper)
{
$actionWrapper = $actionHandler;
$actionResponses = $actionWrapper->getWatch();
foreach($actionResponses as $actionResponse)
{
if($actionResponse instanceof SuccessResponse)
{
$successResponse = $actionResponse;
echo("Status: " . $successResponse->getStatus()->getValue() . "\n");
echo("Code: " . $successResponse->getCode()->getValue() . "\n");
if($successResponse->getDetails() != null)
{
echo("Details: \n");
foreach($successResponse->getDetails() as $keyName => $value)
{
if((is_array($value) && sizeof($value) > 0) && isset($value[0]))
{
if($value[0] instanceof $notificationClass)
{
$eventList = $value;
foreach($eventList as $event)
{
echo("Notification ChannelExpiry: "); print_r($event->getChannelExpiry());
echo("Notification ResourceUri: " . $event->getResourceUri() . "\n");
echo("Notification ResourceId: " . $event->getResourceId() . "\n");
echo("Notification ResourceName: " . $event->getResourceName() . "\n");
echo("Notification ChannelId: " . $event->getChannelId() . "\n");
}
}
}
else
{
echo($keyName . ": "); print_r($value);
}
}
}
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");
if($exception->getDetails() != null)
{
echo("Details: \n");
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");
}
}
else
{
print_r($response);
}
}
}
}
DisableNotification::initialize();
DisableNotification::disableNotification();
?>