Add Tags to Records
Purpose
To add tags to records.
Request Details
Request URL
https://www.zohoapis.com/bigin/v1/{module_api_name}/actions/add_tags?ids={entity_id1}&tag_names={tag1},{tag2}
To add tags to specific records:
https://www.zohoapis.com/bigin/v1/{module_api_name}/{record_id}/actions/add_tags?tag_names={tag1},{tag2}
Supported modules
Accounts, Contacts, Deals, Tasks, Events, Calls, Products and Activities
Header
Authorization: Zoho-oauthtoken d92d4xxxxxxxxxxxxx15f52
Scope
scope=ZohoBigin.modules.ALL
(or)
scope=ZohoBigin.modules.{module_name}.{operation_type}
Possible module names
accounts, contacts, deals, tasks, events, calls, products 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
Copiedcurl "https://www.zohoapis.com/bigin/v1/Contacts/actions/add_tags?ids=1234567890,123456789&tag_names=From Email,High Priority&over_write=true"
-X POST
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
CopiedString moduleAPIName = "Leads";
ArrayList<Long> recordIds = new ArrayList<Long>(Arrays.asList(3477061000005623115L, 3477061000006114067L));
ArrayList<String> tagNames = new ArrayList<String>(Arrays.asList("addtag1,addtag12"));
//Get instance of TagsOperations Class
TagsOperations tagsOperations = new TagsOperations();
//Get instance of ParameterMap Class
ParameterMap paramInstance = new ParameterMap();
for (String tagName: tagNames) {
paramInstance.add(AddTagsToMultipleRecordsParam.TAG_NAMES, tagName);
}
for (Long recordId: recordIds) {
paramInstance.add(AddTagsToMultipleRecordsParam.IDS, recordId);
}
paramInstance.add(AddTagsToMultipleRecordsParam.OVER_WRITE, "false");
//Call addTagsToMultipleRecords method that takes moduleAPIName, paramInstance as parameter
APIResponse < RecordActionHandler > response = tagsOperations.addTagsToMultipleRecords(moduleAPIName, paramInstance);
Copiedpackage com.zoho.crm.api.sample.restapi.tag;
import javax.net.ssl.SSLContext;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
public class AddTagstoRecords
{
private static void addTagstoRecords()
{
try
{
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
SSLContext sslContext = SSLContext.getDefault();
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
CloseableHttpClient httpclient = httpClientBuilder.setSSLSocketFactory(sslConnectionSocketFactory).build();
URIBuilder uriBuilder = new URIBuilder("https://www.zohoapis.com/crm/v2/Leads/actions/add_tags");
uriBuilder.addParameter("ids", "34770617753001,34770617736020");
uriBuilder.addParameter("tag_names", "Leads");
uriBuilder.addParameter("over_write", "true");
HttpUriRequest requestObj = new HttpPost(uriBuilder.build());
requestObj.addHeader("Authorization", "Zoho-oauthtoken 1000.xxxxxxx.xxxxxxx");
HttpResponse response = httpclient.execute(requestObj);
HttpEntity responseEntity = response.getEntity();
System.out.println("HTTP Status Code : " + response.getStatusLine().getStatusCode());
if(responseEntity != null)
{
Object responseObject = EntityUtils.toString(responseEntity);
String responseString = responseObject.toString();
System.out.println(responseString);
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
private static void addTagstoRecord()
{
try
{
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
SSLContext sslContext = SSLContext.getDefault();
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
CloseableHttpClient httpclient = httpClientBuilder.setSSLSocketFactory(sslConnectionSocketFactory).build();
URIBuilder uriBuilder = new URIBuilder("https://www.zohoapis.com/crm/v2/Leads/34770617753001/actions/add_tags");
uriBuilder.addParameter("tag_names", "Leads1");
uriBuilder.addParameter("over_write", "true");
HttpUriRequest requestObj = new HttpPost(uriBuilder.build());
requestObj.addHeader("Authorization", "Zoho-oauthtoken 1000.xxxxxxx.xxxxxxx");
HttpResponse response = httpclient.execute(requestObj);
HttpEntity responseEntity = response.getEntity();
System.out.println("HTTP Status Code : " + response.getStatusLine().getStatusCode());
if(responseEntity != null)
{
Object responseObject = EntityUtils.toString(responseEntity);
String responseString = responseObject.toString();
System.out.println(responseString);
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
public static void main(String[] args)
{
addTagstoRecords();
addTagstoRecord();
}
}
Copied//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/Leads/actions/add_tags?";
$parameters = array();
$parameters["ids"]="35240335495065";
$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.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf";
$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();
Copieddef add_tag_multiple_records(self):
try:
tag_names = ["4", "5"]
record_ids = ["3719520000000320001", "3719520000000318001"]
resp = ZCRMModule.get_instance("Leads").add_tags_to_multiple_records(tag_names, record_ids)
entity_responses = resp.bulk_entity_response
for entity_response in entity_responses:
print(entity_response.details)
print(entity_response.status)
print(entity_response.message)
print(entity_response.code)
print(entity_response.data.entity_id)
for tag in entity_response.data.tag_list:
print(tag.name)
except ZCRMException as ex:
print(ex.status_code)
print(ex.error_message)
print(ex.error_code)
print(ex.error_details)
print(ex.error_content)
CopiedZCRMModule moduleIns = ZCRMModule.GetInstance("Leads"); // module api name
List<string> tagNames = new List<string>{ "Name7", "Name8" };
List<long> recordIds = new List<long>{3372164000001494008,3372164000001295433};
BulkAPIResponse<ZCRMRecord> response = moduleIns.AddTagsToRecords(recordIds, tagNames); //recordIds list of record id, tagNames list of tag names
List<ZCRMRecord> records = response.BulkData; //records - list of ZCRMRecord instances
List<EntityResponse> entityResponses = response.BulkEntitiesResponse; // entityResponses - list of EntityResponse instance
Copiedresponse = invokeurl
[
url :"https://www.zohoapis.com/crm/v2/Leads/actions/add_tags?ids=692969000000968004,692969000000981055&tag_names=Chems,Agriculture"
type :POST
connection:"crm_oauth_connection"
];
info response;
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 ZohoBigin.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 Response
Copied{
"data": [
{
"code": "FAILURE",
"details": {
"id": "2445013000000402006"
},
"message": "tags not updated successfully",
"status": "error"
},
{
"code": "SUCCESS",
"details": {
"id": "2445013000000141005",
"tags": [
"From Email",
"High Priority"
]
},
"message": "tags updated successfully",
"status": "success"
}
],
"wf_scheduler": "false",
"success_count": "1"
}