PHP SDK Samples - Tags Operations

Get Tags
              
              
<?php
namespace samples\tags;

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\tags\APIException;
use com\zoho\crm\api\tags\ResponseWrapper;
use com\zoho\crm\api\tags\TagsOperations;
use com\zoho\crm\api\tags\GetTagsParam;
require_once "vendor/autoload.php";

class GetTags
{
    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 getTags(string $moduleAPIName)
	{
		$tagsOperations = new TagsOperations();
		$paramInstance = new ParameterMap();
		$paramInstance->add(GetTagsParam::module(), $moduleAPIName);
		// $paramInstance->add(GetTagsParam::myTags(), ""); //Displays the names of the tags created by the current user.
		$response = $tagsOperations->getTags($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;
            }
            $responseHandler = $response->getObject();
            if($responseHandler instanceof ResponseWrapper)
            {
                $responseWrapper = $responseHandler;
                $tags = $responseWrapper->getTags();
                if($tags != null)
                {
                    foreach($tags as $tag)
                    {
                        echo("Tag CreatedTime: "); print_r($tag->getCreatedTime()); echo("\n");
                        echo("Tag ModifiedTime: "); print_r($tag->getModifiedTime()); echo("\n");
                        echo("Tag Name: " . $tag->getName() . "\n");
                        $modifiedBy = $tag->getModifiedBy();
                        if($modifiedBy != null)
                        {
                            echo("Tag Modified By User-ID: " . $modifiedBy->getId() . "\n");
                            echo("Tag Modified By User-Name: " . $modifiedBy->getName() . "\n");
                        }
                        echo("Tag ID: " . $tag->getId() . "\n");
                        $createdBy = $tag->getCreatedBy();
                        if($createdBy != null)
                        {
                            echo("Tag Created By User-ID: " . $createdBy->getId() . "\n");
                            echo("Tag Created By User-Name: " . $createdBy->getName() . "\n");
                        }
                    }
                }
                $info = $responseWrapper->getInfo();
                if($info != null)
                {
                    echo("Tag Info Count: " . $info->getCount() . "\n");
                    echo("Tag Info AllowedCount: " . $info->getAllowedCount() . "\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");
            }
		}
	}
}

GetTags::initialize();
$moduleAPIName = "Leads";
GetTags::getTags($moduleAPIName);
?>
Create Tags
              
              
<?php
namespace samples\tags;

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\tags\APIException;
use com\zoho\crm\api\tags\ActionWrapper;
use com\zoho\crm\api\tags\BodyWrapper;
use com\zoho\crm\api\tags\SuccessResponse;
use com\zoho\crm\api\tags\TagsOperations;
use com\zoho\crm\api\tags\CreateTagsParam;
use com\zoho\crm\api\tags\Tag;
require_once "vendor/autoload.php";

class CreateTags
{
    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 createTags(string $moduleAPIName)
	{
		$tagsOperations = new TagsOperations();
		$request = new BodyWrapper();
		$paramInstance = new ParameterMap();
		$paramInstance->add(CreateTagsParam::module(), $moduleAPIName);
		$tagList = array();
		$tag1 = new Tag();
		$tag1->setName("tagName");
		array_push($tagList, $tag1);
		$request->setTags($tagList);
		$response = $tagsOperations->createTags($request, $paramInstance);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
            $actionHandler = $response->getObject();
            if($actionHandler instanceof ActionWrapper)
            {
                $actionWrapper = $actionHandler;
                $actionResponses = $actionWrapper->getTags();
                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: " );
                            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");
            }
		}
	}
}

CreateTags::initialize();
$moduleAPIName = "Leads";
CreateTags::createTags($moduleAPIName);
?>
Update Tags
              
              
<?php
namespace samples\tags;

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

class UpdateTags
{
    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 updateTags(string $moduleAPIName)
	{
		$tagsOperations = new TagsOperations();
		$request = new BodyWrapper();
		$paramInstance = new ParameterMap();
		$paramInstance->add(UpdateTagsParam::module(), $moduleAPIName);
        $tagList = array();
        $tagClass = 'com\zoho\crm\api\tags\Tag';
		$tag1 = new $tagClass();
		$tag1->setId("347706112284001");
		$tag1->setName("tagName12");
		array_push($tagList, $tag1);
		$request->setTags($tagList);
		$response = $tagsOperations->updateTags($request, $paramInstance);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
           $actionHandler = $response->getObject();
           if($actionHandler instanceof ActionWrapper)
           {
               $actionWrapper = $actionHandler;
               $actionResponses = $actionWrapper->getTags();
               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: " );
                           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");
           }
		}
	}
}

UpdateTags::initialize();
$moduleAPIName = "Leads";
UpdateTags::updateTags($moduleAPIName);
?>
Update Specific Tag
              
              
<?php
namespace samples\tags;

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

class UpdateTag
{
    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 updateTag(string $moduleAPIName, string $tagId)
	{
		$tagsOperations = new TagsOperations();
		$request = new BodyWrapper();
		$paramInstance = new ParameterMap();
		$paramInstance->add(UpdateTagParam::module(), $moduleAPIName);
		$tagList = array();
		$tagClass = 'com\zoho\crm\api\tags\Tag';
		$tag1 = new $tagClass();
		$tag1->setName("tagName13");
		array_push($tagList, $tag1);
		$request->setTags($tagList);
		$response = $tagsOperations->updateTag($tagId,$request, $paramInstance);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
           $actionHandler = $response->getObject();
           if($actionHandler instanceof ActionWrapper)
           {
               $actionWrapper = $actionHandler;
               $actionResponses = $actionWrapper->getTags();
               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: " );
                           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");
           }
		}
	}
}

UpdateTag::initialize();
$moduleAPIName = "Leads";
$tagId = "347706112193003";
UpdateTag::updateTag($moduleAPIName, $tagId);
?>
Delete a Tag
              
              
<?php
namespace samples\tags;

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

class DeleteTag
{
    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 deleteTag(string $tagId)
	{
		$tagsOperations = new TagsOperations();
		$response = $tagsOperations->deleteTag($tagId);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
           $actionHandler = $response->getObject();
           if($actionHandler instanceof ActionWrapper)
           {
               $actionWrapper = $actionHandler;
               $actionResponses = $actionWrapper->getTags();
               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: " );
                           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");
               if($exception->getDetails() != null)
               {
                    echo("Details: " );
                    foreach($exception->getDetails() as $key => $value)
                    {
                        echo($key . " : " . $value . "\n");
                    }
               }
               echo("Message: " . $exception->getMessage()->getValue() . "\n");
           }
		}
	}
}

DeleteTag::initialize();
$tagId = "347706112193003";
DeleteTag::deleteTag($tagId);
?>
Merge Tags
              
              
<?php
namespace samples\tags;

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\tags\APIException;
use com\zoho\crm\api\tags\ActionWrapper;
use com\zoho\crm\api\tags\ConflictWrapper;
use com\zoho\crm\api\tags\MergeWrapper;
use com\zoho\crm\api\tags\SuccessResponse;
use com\zoho\crm\api\tags\TagsOperations;
require_once "vendor/autoload.php";

class MergeTags
{
    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 mergeTags(string $tagId, string $conflictId)
	{
		$tagsOperations = new TagsOperations();
		$request = new MergeWrapper();
		$tags = array();
		$mergeTag = new ConflictWrapper();
		$mergeTag->setConflictId($conflictId);
		array_push($tags, $mergeTag);
		$request->setTags($tags);
		$response = $tagsOperations->mergeTags($tagId,$request);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
           $actionHandler = $response->getObject();
           if($actionHandler instanceof ActionWrapper)
           {
               $actionWrapper = $actionHandler;
               $actionResponses = $actionWrapper->getTags();
               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: " );
                           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");
           }
		}
	}
}

MergeTags::initialize();
$tagId = "347706112193003";
$conflictId = "347706112193003";
MergeTags::mergeTags($tagId, $conflictId);
?>
Add Tags to a Record
              
              
<?php
namespace samples\tags;

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

class AddTagsToRecord
{
    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 addTagsToRecord(string $moduleAPIName, string $recordId, array $tagNames)
	{
		$tagsOperations = new TagsOperations();
		$paramInstance = new ParameterMap();
		foreach($tagNames as $tagName)
		{
			$paramInstance->add(AddTagsToRecordParam::tagNames(), $tagName);
		}
		$paramInstance->add(AddTagsToRecordParam::overWrite(), "false");
		$response = $tagsOperations->addTagsToRecord($recordId, $moduleAPIName,$paramInstance);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
            $recordActionHandler = $response->getObject();
            if($recordActionHandler instanceof RecordActionWrapper)
            {
                $recordActionWrapper = $recordActionHandler;
                $actionResponses = $recordActionWrapper->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: \n" );
                        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 . " : "); print_r($value); echo("\n");
                        }
                        echo("Message: " . $exception->getMessage()->getValue() . "\n");
                    }
                }
            }
            else if($recordActionHandler instanceof APIException)
            {
                $exception = $recordActionHandler;
                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");
            }
		}
	}
}

AddTagsToRecord::initialize();
$moduleAPIName = "Leads";
$recordId =  "34770615623115";
$tagNames = array("addtag1", "addtag12");
AddTagsToRecord::addTagsToRecord($moduleAPIName, $recordId, $tagNames);
?>
Remove Tags from a Record
              
              
<?php
namespace samples\tags;

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

class RemoveTagsFromRecord
{
    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 removeTagsFromRecord(string $moduleAPIName, string $recordId, array $tagNames)
	{
		$tagsOperations = new TagsOperations();
		$paramInstance = new ParameterMap();
		foreach($tagNames as $tagName)
		{
			$paramInstance->add(RemoveTagsFromRecordParam::tagNames(), $tagName);
		}
		$response = $tagsOperations->removeTagsFromRecord($recordId, $moduleAPIName,$paramInstance);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
            $recordActionHandler = $response->getObject();
            if($recordActionHandler instanceof RecordActionWrapper)
            {
                $recordActionWrapper = $recordActionHandler;
                $actionResponses = $recordActionWrapper-> 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($recordActionHandler instanceof APIException)
            {
                $exception = $recordActionHandler;
                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");
            }
		}
	}
}


RemoveTagsFromRecord::initialize();
$moduleAPIName = "Leads";
$recordId =  "34770615623115";
$tagNames = array("addtag1", "addtag12");
RemoveTagsFromRecord::removeTagsFromRecord($moduleAPIName, $recordId, $tagNames);
?>
Add Tags to Multiple Records
              
              
<?php
namespace samples\tags;

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

class AddTagsToMultipleRecords
{
    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 addTagsToMultipleRecords(string $moduleAPIName, array $recordIds, array $tagNames)
	{
		$tagsOperations = new TagsOperations();
		$paramInstance = new ParameterMap();
		foreach($tagNames as $tagName)
		{
			$paramInstance->add(AddTagsToMultipleRecordsParam::tagNames(), $tagName);
		}
		foreach($recordIds as $recordId)
		{
			$paramInstance->add(AddTagsToMultipleRecordsParam::ids(), $recordId);
		}
		$paramInstance->add(AddTagsToMultipleRecordsParam::overWrite(), "false");
		$response = $tagsOperations->addTagsToMultipleRecords($moduleAPIName,$paramInstance);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
            $recordActionHandler = $response->getObject();
            if($recordActionHandler instanceof RecordActionWrapper)
            {
                $recordActionWrapper = $recordActionHandler;
                $actionResponses = $recordActionWrapper->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");
                    }
                }
                if($recordActionWrapper->getLockedCount() != null)
                {
                    echo("Locked Count: " . $recordActionWrapper->getLockedCount() . "\n");
                }
                if($recordActionWrapper->getSuccessCount() != null)
                {
                    echo("Success Count: " . $recordActionWrapper->getSuccessCount() . "\n");
                }
                if($recordActionWrapper->getWfScheduler() != null)
                {
                    echo("WF Scheduler: " . $recordActionWrapper->getWfScheduler() . "\n");
                }
            }
            else if($recordActionHandler instanceof APIException)
            {
                $exception = $recordActionHandler;
                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");
            }
		}
	}
}

AddTagsToMultipleRecords::initialize();
$moduleAPIName = "Leads";
$recordIds = array("34770615623115", "34770616454014");
$tagNames = array("addtag1", "addtag12");
AddTagsToMultipleRecords::addTagsToMultipleRecords($moduleAPIName, $recordIds, $tagNames);
?>
Remove Tags from Multiple Records
              
              
<?php
namespace samples\tags;

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

class RemoveTagsFromMultipleRecords
{
    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 removeTagsFromMultipleRecords(string $moduleAPIName, array $recordIds, array $tagNames)
	{
		$tagsOperations = new TagsOperations();
		$paramInstance = new ParameterMap();
		foreach($tagNames as $tagName)
		{
			$paramInstance->add(RemoveTagsFromMultipleRecordsParam::tagNames(), $tagName);
		}
		foreach($recordIds as $recordId)
		{
			$paramInstance->add(RemoveTagsFromMultipleRecordsParam::ids(), $recordId);
		}
		$response = $tagsOperations->removeTagsFromMultipleRecords($moduleAPIName, $paramInstance);
		if($response != null)
		{
			echo("Status Code: " . $response->getStatusCode() . "\n");
            $recordActionHandler = $response->getObject();
            if($recordActionHandler instanceof RecordActionWrapper)
            {
                $recordActionWrapper = $recordActionHandler;
                $actionResponses = $recordActionWrapper->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");
                    }
                }
                if($recordActionWrapper->getLockedCount() != null)
                {
                    echo("Locked Count: " . $recordActionWrapper->getLockedCount() . "\n");
                }
                if($recordActionWrapper->getSuccessCount() != null)
                {
                    echo("Success Count: " . $recordActionWrapper->getSuccessCount() . "\n");
                }
                if($recordActionWrapper->getWfScheduler() != null)
                {
                    echo("WF Scheduler: " . $recordActionWrapper->getWfScheduler() . "\n");
                }
            }
            else if($recordActionHandler instanceof APIException)
            {
                $exception = $recordActionHandler;
                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");
            }
		}
	}
}

RemoveTagsFromMultipleRecords::initialize();
$moduleAPIName = "Leads";
$recordIds = array("34770615623115", "34770616454014");
$tagNames = array("addtag1", "addtag12");
RemoveTagsFromMultipleRecords::removeTagsFromMultipleRecords($moduleAPIName, $recordIds, $tagNames);
?>
Get Record Count for a Tag
              
              
<?php
namespace samples\tags;

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

class GetRecordCountForTag
{
    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 getRecordCountForTag(string $moduleAPIName, string $tagId)
	{
		$tagsOperations = new TagsOperations();
		$paramInstance = new ParameterMap();
		$paramInstance->add(GetRecordCountForTagParam::module(), $moduleAPIName);
		//Call getRecordCountForTag method that takes paramInstance and tagId as parameter
		$response = $tagsOperations->getRecordCountForTag($tagId,$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;
            }
            $countHandler = $response->getObject();
            if($countHandler instanceof CountWrapper)
            {
                $countWrapper = $countHandler;
                echo("Tag Count: " . $countWrapper->getCount() . "\n");
            }
            else if($countHandler instanceof APIException)
            {
                $exception = $countHandler;
                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");
            }
		}
	}
}

GetRecordCountForTag::initialize();
$moduleAPIName = "Leads";
$tagId = "347706116961005";
GetRecordCountForTag::getRecordCountForTag($moduleAPIName, $tagId);
?>