Request Details

Request URL

{api-domain}/crm/{version}/{module_api_name}/actions/add_tags?ids={record_id1},{record_id2}&tag_names={tag1},{tag2}

To add tags to specific records:
https://www.zohoapis.com/crm/v2.1/{module_api_name}/{record_id}/actions/add_tags?tag_names={tag1},{tag2}

Supported modules

Leads, Accounts, Contacts, Deals, Campaigns, Tasks, Cases, Events, Calls, Solutions, Products, Vendors, Price Books, Quotes, Sales Orders, Purchase Orders, Invoices, Custom, and Activities

Header

Authorization: Zoho-oauthtoken d92d4xxxxxxxxxxxxx15f52

Scope

scope=ZohoCRM.modules.ALL
(or)
scope=ZohoCRM.modules.{module_name}.{operation_type}

Possible module names

leads, accounts, contacts, deals, campaigns, tasks, cases, events, calls, solutions, products, vendors, pricebooks, quotes, salesorders, purchaseorders, invoices, and custom

Possible operation types

ALL - Full access to the record
WRITE - Edit records in the module
CREATE - Create records in the module

Parameters

  • tag_namesstring, optional

    Specify the names of the tags to be added.

  • over_writeboolean, optional

    Specify if the existing tags are to be overwritten. Default value is false.

  • idsstring, mandatory when adding tags to multiple records

    Specify the unique ID of the record.

Sample Request to Add Multiple Tags to Multiple Records

Copiedcurl "https://www.zohoapis.com/crm/v2.1/Contacts/actions/add_tags?ids=3652397000003971077,3652397000003971108&tag_names=Pharma,Agricultural&over_write=true"
-X POST
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
4.0.04.x
Copied//Get instance of TagsOperations Class
$tagsOperations = new TagsOperations();
//Get instance of ParameterMap Class
$paramInstance = new ParameterMap();
foreach($tagNames as $tagName)
{
  $paramInstance->add(AddTagsToRecordParam::tagNames(), $tagName);
}
$paramInstance->add(AddTagsToRecordParam::overWrite(), "false");
//Call addTagsToRecord method that takes paramInstance, moduleAPIName and recordId as parameter
$response = $tagsOperations->addTagsToRecord($recordId, $moduleAPIName,$paramInstance);


//Get instance of TagsOperations Class
$tagsOperations = new TagsOperations();
//Get instance of ParameterMap Class
$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");
//Call addTagsToMultipleRecords method that takes paramInstance, moduleAPIName as parameter
$response = $tagsOperations->addTagsToMultipleRecords($moduleAPIName,$paramInstance); 
Copied<?php

class AddTagsToRecord
{
    public function execute(){
        $curl_pointer = curl_init();
        
        $curl_options = array();
        $url = "https://www.zohoapis.com/crm/v2.1/Leads/actions/add_tags?";
        $parameters = array();
        $parameters["ids"]="3524033000005495065";
        $parameters["tag_names"]="Leads";
        $parameters["over_write"]="true";
        
        foreach ($parameters as $key=>$value){
            $url =$url.$key."=".$value."&";
        }
        $curl_options[CURLOPT_URL] =$url;
        $curl_options[CURLOPT_RETURNTRANSFER] = true;
        $curl_options[CURLOPT_HEADER] = 1;
        $curl_options[CURLOPT_CUSTOMREQUEST] = "POST";
      
        $headersArray = array();
        
        $headersArray[] = "Authorization". ":" . "Zoho-oauthtoken " . "1000.30f3a589XXXXXXXXXXXXXXXXXXX4077.dc5XXXXXXXXXXXXXXXXXXXee9e7c171c";
        
        $curl_options[CURLOPT_HTTPHEADER]=$headersArray;
        
        curl_setopt_array($curl_pointer, $curl_options);
        
        $result = curl_exec($curl_pointer);
        $responseInfo = curl_getinfo($curl_pointer);
        curl_close($curl_pointer);
        list ($headers, $content) = explode("\r\n\r\n", $result, 2);
        if(strpos($headers," 100 Continue")!==false){
            list( $headers, $content) = explode( "\r\n\r\n", $content , 2);
        }
        $headerArray = (explode("\r\n", $headers, 50));
        $headerMap = array();
        foreach ($headerArray as $key) {
            if (strpos($key, ":") != false) {
                $firstHalf = substr($key, 0, strpos($key, ":"));
                $secondHalf = substr($key, strpos($key, ":") + 1);
                $headerMap[$firstHalf] = trim($secondHalf);
            }
        }
        $jsonResponse = json_decode($content, true);
        if ($jsonResponse == null && $responseInfo['http_code'] != 204) {
            list ($headers, $content) = explode("\r\n\r\n", $content, 2);
            $jsonResponse = json_decode($content, true);
        }
        var_dump($headerMap);
        var_dump($jsonResponse);
        var_dump($responseInfo['http_code']);
        
    }
    
}
(new AddTagsToRecord())->execute();
2.1.0
Copied# Get instance of TagsOperations Class
to = Tags::TagsOperations.new
# Get instance of ParameterMap Class
pm = ParameterMap.new
# Possible parameters of Add Tags to record operation
tag_names.each do |tag_name|
  pm.add(Tags::TagsOperations::AddTagsToRecordParam.tag_names, tag_name)
end
# pm.add(Tags::TagsOperations::AddTagsToRecordParam.over_write,"false")
# Call add_tags_to_record method that takes ParameterMap instance, module_api_name and record_id as parameter
response = to.add_tags_to_record(record_id, module_api_name, pm)


# Get instance of TagsOperations Class
to = Tags::TagsOperations.new
# Get instance of ParameterMap Class
pm = ParameterMap.new
# Possible parameters for Add Tags To Multiple Records operation
tag_names.each do |tag_name|
  pm.add(Tags::TagsOperations::AddTagsToMultipleRecordsParam.tag_names, tag_name)
end
record_ids.each do |record_id|
  pm.add(Tags::TagsOperations::AddTagsToMultipleRecordsParam.ids, record_id)
end
pm.add(Tags::TagsOperations::AddTagsToRecordParam.over_write, 'true')
# Call add_tags_to_multiple_records method that takes ParameterMap instance and module_api_name as parameter
response = to.add_tags_to_multiple_records(module_api_name,pm)
Copiedrequire 'net/http'
require 'json'

class AddTagsToRecord
    def execute
        parameters ={}
        parameters["ids"]="3524033000005495065";
        parameters["tag_names"]="Leads";
        parameters["over_write"]="true";
        query_string = parameters.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join('&')
        url ="https://www.zohoapis.com/crm/v2.1/Leads/actions/add_tags"
        url += '?' + query_string if !query_string.nil? && (query_string.strip != '')
        url = URI(url)
        req = Net::HTTP::Post.new(url.request_uri)
        http = Net::HTTP.new(url.host, url.port)
        http.use_ssl = true
        headers={}
        headers["Authorization"]="Zoho-oauthtoken 1000.dfa7XXXXXXXXXXXXXXXXXX84f9665840.c176aeXXXXXXXXXXXX13f3d37a84d"
        headers&.each { |key, value| req.add_field(key, value) }
       
        response=http.request(req)
        status_code = response.code.to_i
        headers = response.each_header.to_h
        print status_code
        print headers
        unless response.body.nil?
            print  response.body
        end
    end
end

AddTagsToRecord.new.execute
Copiedresponse = invokeurl
[
url :"https://www.zohoapis.com/crm/v2.1/Leads/actions/add_tags?ids=3652397000003971077,3652397000003971108&tag_names=Pharma,Agricultural&over_write=true"
	type :POST
	connection:"crm_oauth_connection"
];
info response;

Sample Response

Copied{
    "data": [
        {
            "code": "SUCCESS",
            "details": {
                "id": "3652397000003971077",
                "tags": [
                    {
                        "name": "Pharma",
                        "id": "3652397000000371014"
                    },
                    {
                        "name": "Agricultural",
                        "id": "3652397000000371015"
                    }
                ]
            },
            "message": "tags updated successfully",
            "status": "success"
        },
        {
            "code": "SUCCESS",
            "details": {
                "id": "3652397000003971108",
                "tags": [
                    {
                        "name": "Pharma",
                        "id": "3652397000000371014"
                    },
                    {
                        "name": "Agricultural",
                        "id": "3652397000000371015"
                    }
                ]
            },
            "message": "tags updated successfully",
            "status": "success"
        }
    ],
    "wf_scheduler": false,
    "success_count": "2",
    "locked_count": "0"
}

Possible Errors

  • INVALID_URL_PATTERNHTTP 404

    Please check if the URL trying to access is a correct one
    Resolution: The request URL specified is incorrect. Specify a valid request URL. Refer to request URL section above.

  • OAUTH_SCOPE_MISMATCHHTTP 401

    Unauthorized
    Resolution: Client does not have ZohoCRM.modules.{module_name}.WRITE scope. Create a new client with valid scope. Refer to scope section above.

  • NO_PERMISSIONHTTP 403

    Permission denied to update records
    Resolution: The user does not have permission to add tags to the records. Contact your system administrator.

  • INTERNAL_ERRORHTTP 500

    Internal Server Error
    Resolution: Unexpected and unhandled exception in Server. Contact support team.

  • INVALID_REQUEST_METHODHTTP 400

    The http request method type is not a valid one
    Resolution: You have specified an invalid HTTP method to access the API URL. Specify a valid request method. Refer to endpoints section above.

  • AUTHORIZATION_FAILEDHTTP 400

    User does not have sufficient privilege to add tags
    Resolution: The user does not have the permission to add tags to the records. Contact your system administrator.

  • INVALID_MODULEHTTP 400

    The module name given seems to be invalid
    Resolution: You have specified an invalid module name or there is no tab permission, or the module could have been removed from the available modules. Specify a valid module API name.

  • INVALID_MODULEHTTP 400

    The given module is not supported in API
    Resolution: The modules such as Documents and Projects are not supported in the current API. (This error will not be shown, once these modules are been supported). Specify a valid module API name.

  • PATTERN_NOT_MATCHEDHTTP 400

    Please check whether the input values are correct
    Resolution: The value specified for one of the parameters is incorrect. Refer to parameters section above and specify valid parameter values.

Sample Request to Add Tags to a Record

Copiedcurl "https://www.zohoapis.com/crm/v2.1/Leads/3652397000003971077/actions/add_tags?tag_names=Pharma,Chem"
-X POST
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
Copiedresponse = invokeurl
[
url :"https://www.zohoapis.com/crm/v2.1/Leads/3652397000003971077/actions/add_tags?tag_names=Pharma,Chem"
	type :POST
	connection:"crm_oauth_connection"
];
info response;

Sample Response

Copied{
    "data": [
        {
            "code": "SUCCESS",
            "details": {
                "id": "3652397000003971077",
                "tags": [
                    {
                        "name": "Pharma",
                        "id": "3652397000000371014"
                    },
                    {
                        "name": "Chem",
                        "id": "3652397000003983017"
                    }
                ]
            },
            "message": "tags updated successfully",
            "status": "success"
        }
    ]
}