How to link a tag to a specific entity

[tab:Actions]

Requirements

 

In order to link a tag to a specific entity, the following conditions must be complied:

  • A business user must be used, and it needs the appropriate permission (permission can be configured in THRON Passport) to tag users and content; therefore its credentials must be used (username and password must be used to perform login and obtain a valid token); a THRON application may be used to upload content, but only through SU (also known as “sudo” or “superuser”) web service which allows it to impersonate a business user (usually the owner of the application).

 

Tagging a THRON entity

Specific web service to be used in order to tag a THRON entity (content, user or contact) is insert, which can be found within the itag package of xintelligence. The URL of the web service is structured as follows:

 

//<clientId>-view.thron.com/api/xintelligence/resources/insert/<clientId>/<classificationId>/<tagId>

 

Where:

  • clientId: string, is the domain name used to access THRON, usually your company name.
  • classificationId: string, it is the ID of the class in which the tag is included. It can be retrieved with a listget request which can be found within the classification package of xintelligence.
  • tagId: string, it is the ID of the tag to be inserted. It can be retrieved with a list request which can be found within the itagdefinition of intelligence. You can provide either the imaged, the tagPrettyId or the externalId

Additional parameters to be included in the body of the request are:

  • id: string, the ID of the entity you want to tag; might be an xcontentId, a userId or a contactId.
  • entityType: string, it is the type of entity you want to tag. Might be "CONTENT", "USER" or "CONTACT".

 

If you wish to insert more than one tag at a time, you can use the bulkInsert web service, including an array of tagIds within the body of the request. Note that the tags must belong to the same class.

If instead you wish to insert a tag to a set of entities you can use the bulkInsertMultiTarget which allows you to link a specific tag to an array of entities of the same type (content, users or contacts; max 50 elements).

If you are interested in retrieving all the ids and the labels of a specific class you might want to have a look at this article.

 

Scripts for tagging multiple content

 

In the "Code samples" section of  this article you will find JAVA and PHP sample codes to perform multiple content tagging.

[/tab][tab:Code Samples] [dropdown:JAVA - MULTIPLE CONTENT TAGGING]


import com.thron.intelligence.services.model.itag.MITagBulkValue;
import com.thron.intelligence.services.model.itag.MResponseITagBulk;
import com.thron.intelligence.services.model.request.MITagbulkInsertReq;
import com.thron.intelligence.services.model.common.MTarget;
import com.thron.intelligence.model.MEEntityType;
import com.thron.intelligence.services.model.itag.MITagId;
import com.thron.intelligence.services.rest.JITagClient;
import org.codehaus.jackson.map.ObjectMapper;


import java.util.*;
/**
 * Created on 26/10/16.
 */
public class addITagContent {

 public static void main(String[] args) {

  /*SETUP FILE*/
  String clientId = "CLIENT THRON";
  String tokenID = "TOKENID";
  String classificationId = "CLASSIFICATION ID THRON";
  MEEntityType entityType = MEEntityType.CONTENT; //['CONTENT' or 'USER' or 'CONTACT']
  // list of contentID
  String[] arrayContentID = {
   "XCONTENT ID1",
   "XCONTENT ID2",
   "..."
  };
  String[] arrayITAGaddToContent = {
   "ITAG ID 1",
   "ITAG ID 2",
   "ITAG ID 3",
   "..."
  };

  // MAIN
  //init object for output
  ObjectMapper mapper = new ObjectMapper();
  //define request THRON
  JITagClient contentClient = new JITagClient("http://" + clientId + "-view.thron.com/api/xintelligence/resources");

  //execute request
  try {
   for (int x = 0; x < arrayContentID.length; x = x + 1) {
    // pause 1 second
    Thread.sleep(1000);
    //generate request param
    MITagbulkInsertReq newITagbulkInsert = new MITagbulkInsertReq();
    MITagBulkValue ITagBulkValue = new MITagBulkValue();
    MTarget targetC = new MTarget();
    //set value
    // content
    targetC.setEntityType(entityType);
    targetC.setId(arrayContentID[x]);
    // set itag
    //set param request
    List itagIds = new ArrayList();
    // set itag
    for (int t = 0; t < arrayITAGaddToContent.length; t = t + 1) {
     MITagId itagV = new MITagId();
     itagV.setId(arrayITAGaddToContent[t]);
     itagIds.add(itagV);
    }

    //itags
    ITagBulkValue.setTagIds(itagIds);
    //content
    ITagBulkValue.setTarget(targetC);
    newITagbulkInsert.setValue(ITagBulkValue);

    // System.out.println(mapper.writeValueAsString(newITagbulkInsert));
    // add itags to content to THRON from request
    MResponseITagBulk ris = contentClient.bulkInsert(tokenID, clientId, classificationId, newITagbulkInsert, null);
    //RESULT THRON OUTPUT
    System.out.println(mapper.writeValueAsString(ris));
   }

  } catch (Exception e) {
   //error THRON OUTPUT
   System.out.println(e);
  }



 }
}

[/dropdown] [dropdown:PHP - MULTIPLE CONTENT TAGGING]


/**
 * #################################################################################### 
 * @author stefano.bisello
 * @copyright 2016
 * ####################################################################################
 *
 * INFO
 * Howto add itag to content
 * WebService THRON: https://developer.thron.com/#!/itag/bulkInsert
 *
 * ####################################################################################
 * config
 * ####################################################################################
 */
set_time_limit(3620);
// client
$client_idTHRON = 'CLIENT THRON';
// login credential
$tokenID='TOKENID';
// THRON  classificationId
$classificationId="THRON CLASSIFICATIONID";//EXAMPLE slfxxb
$arrayContentID=array("XCONTENT ID1","XCONTENT ID2","...");
$arrayITAGaddToContent=array("ITAG ID 1","ITAG ID 2","ITAG ID 3","...");
$entityType="CONTENT";  //['CONTENT' or 'USER' or 'CONTACT']

//insert content to THRON
function insertITagsToContentTHRON($client_id,$class_id,$tokend,$bodyRequest)
{
    
        // configure request webService THRON
        $url = "http://".$client_id."-view.thron.com/api/xintelligence/resources/itag/bulkInsert/".$client_id."/".$class_id;        
        //header  request webService THRON
        $header =  array(                
            "Content-Type: application/json",
            "X-TOKENID:" . $tokend
        );
         //request THRON
        $request = json_encode($bodyRequest);
        //configure curl
        $curl = curl_init($url);
        
        curl_setopt($curl, CURLOPT_HEADER, true);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $request);

        $curlRes = curl_exec($curl);
    
        $curlResInfo = curl_getinfo($curl);
        curl_close($curl);
        //parse response 
        $resHeadersString = substr($curlRes, 0, $curlResInfo['header_size']);
        $resBody = substr($curlRes, $curlResInfo['header_size']);
        $response = json_decode($resBody,true);
        print_r($url); 
        print_r($header); 
        print_r($resBody); 
        
    return $response;
}
//#########################################################################################
//main
//#########################################################################################
//array response insert
$risInsert=array();
//insert the content to THRON Platform
for($i=0;$i<count($arrayContentID);$i++)    
    {
    //generate body request    
    $bodyRequest=array( "value"=< array(
                                        "tagIds"=<array(),
                                        "target"=<array( 
                                                          "id"=< $arrayContentID[$i],
                                                          "entityType"=< $entityType                                        
                                                        )
                                        )
                    );
                                        
    //insert info itags                
    for($t=0;$t<count($arrayITAGaddToContent);$t++)
        {
         $bodyRequest["value"]["tagIds"][]=array("id"=<$arrayITAGaddToContent[$t]);                            
        }
                        
    //execute request
    $risInsert[]=insertITagsToContentTHRON($client_idTHRON,$classificationId,$tokenID,$bodyRequest);  
    }    
// output webservice

[/dropdown][/tab]

Was this article helpful?
0 out of 0 found this helpful

Have any question?

Open a ticket
Comments
  • Avatar
    Antonio Comelli

    We have updated this article by including JAVA and PHP sample scripts which can be used to perform multiple tagging of THRON content