How to manage public folders

[tab:Actions]

Requirements

In order to create, edit and delete public folders in THRON, the following conditions must be complied:

  • A business user must be used, and it needs the appropriate administrative permission to manage folders (permissions are set into Passport in THRON Dashboard); 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 create folders, 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)

 

Create public folders

The service used to create new public folders is createCategory which can be found within category package of xcontents. Thanks to the parameter upCatId you can choose whether if this new folder must be created as a sub-folder of another public folder (enter main folder ID in this case) or as a new main folder (leave empty in this case). Remember that if a folder is created as a sub-folder it will inherit the set of user and access rights of its main folder.

 

Manage public folders

In order to set basic folder’s metadata such as title and description in a different locale, you can use the service addCategory4Locale which can be found within category package of xcontents, remember that private folder can have only metadata in one special local code; if you wish to edit such metadata in a specific locale, you can do it anytime using the service updateCategory4Locale. In order to set a new pretty id for a specific folder (which is the name of the folder within the url address), you can use addCategoryPrettyId; please remember that pretty id is multilanguage, in order to change it you can use the service updateCategoryPrettyId. Through our APIs you can even move a folder (and all its subtrees) into a different node; to do so, you must use the service setParentId please remember that in order to do so you must have the write access both on the source folder and in the destination one.

 

Delete public folders

In order to remove a specific category, the following conditions must be fulfilled: you must have the write access on the folder and it must be empty (no linked content and no subfolders).

If these conditions are fulfilled you can use the service removeCategory which can be found in the category package of xcontents. Actually, if you set the Cascade parameter of the request to “true”, all the content within the folder will be un-linked and all its subfolders will become main folders.

[/tab] [tab:Code Samples] [dropdown:REST - CREATING A FOLDER]

The createCategory function, used to create a new public folder is located within xcontents, in the “category” package.

In order to use it you must have a valid platform token, obtainable by logging into platform.

In the body of the request, minimum information to be included are:

  • clientId: compiled using the service code name (usually the company name)

  • upCatId: filled with the cagtegoryId of the root category

  • catLocales: filled with name and locale for the new folder

The headers that should be used for the request, which must be in POST are:

  • Content-Type: application / json

  • X-TokenId: XXXXX (using the token obtained through the login)

 The url of the service is formatted according to the structure:

//[clientId]-view.thron.com/api/xcontents/resources/category/createCategory

Where [clientId] is the name of the service code as used for the body of the request.

You can test this functionality in our Developer Center, pasting this JSON, properly filled with required parameters:

{
    "client": {
        "clientId": ""
    },
    "upCatId": "",
    "catLocales": {
        "name": "",
        "locale": ""
    }
}

[/dropdown] [dropdown:REST - UPDATING A FOLDER]

The updateCategory4Locale function, used to update basic information of a specific folder in a specific language, is located within xcontents, in the “category” package.

In order to use it you must have a valid platform token, obtainable by logging into platform.

In the body of the request, minimum information to be included are:

  • clientId: compiled using the service code name (usually the company name)

  • CatId: filled with the cagtegoryId of the category you want to edit

  • property: filled with name, description and locale you want to edit

The headers that should be used for the request, which must be in POST are:

  • Content-Type: application / json

  • X-TokenId: XXXXX (using the token obtained through the login)

 The url of the service is formatted according to the structure:

//[clientId]-view.thron.com/api/xcontents/resources/category/updateCategory4Locale

Where [clientId] is the name of the service code as used for the body of the request.

You can test this functionality in our Developer Center, pasting this JSON, properly filled with required parameters:

{
    "client": {
        "clientId": ""
    },
    "catId": "",
    "property": {
        "name": "",
        "description": "",
        "locale": ""
    }
}

[/dropdown] [dropdown:REST - DELETING A FOLDER]

The removeCategory function, used to delete a specific folder, is located within xcontents, in the “category” package.

In order to use it you must have a valid platform token, obtainable by logging into platform.

The headers that should be used for the request, which must be in POST are:

  • Content-Type: application / json

  • X-TokenId: XXXXX (using the token obtained through the login)
  • clientId: compiled using the service code name (usually the company name)

  • CatId: filled with the cagtegoryId of the category you want to delete

Additional parameter "cascade" (boolean) can be set to "true" if you wish to delete its subcategories too.

Please remember that folders must be empty in order to be deleted.

 The url of the service is formatted according to the structure:

//[clientId]-view.thron.com/api/xcontents/resources/category/removeCategory

 

Where [clientId] is the name of the service code as used for the body of the request.

You can test this functionality in our Developer Center

[/dropdown] [dropdown:PHP - CREATING A FOLDER]

<?php
//#########################################
//CONFIG
//#########################################
//token 
$tokenTHRON        = 'TOKEN';
// client 
$client_idTHRON    = 'CLIENTID';
//  category parent id
$parentIdCat       = "";
// category name
$categoryNameTHRON = 'NAME CATEGORY';
//locale
$categoryLocale    = "LOCALE"; // IT or EN    


//#########################################
//MAIN
//#########################################    


$url     = "http://" . $client_idTHRON . "-view.thron.com/api/xcontents/resources/category/createCategory";
$header  = array(
    'X-TOKENID: ' . $tokenTHRON,
    "Content-Type: application/json"
);
//echo $url;    
$request = array(
    // an usually required attribute for web service calls
    "client" => array(
        "clientId" => $client_idTHRON
    ),
    // properties that categories in the reponse
    // must satisfy
    
    "catLocales" => array(
        "name" => $categoryNameTHRON,
        "locale" => $categoryLocale
    )
    
);
//if it is not empty
if ($parentIdCat != "")
    $request["upCatId"] = $parentIdCat;

$request = json_encode($request);
$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);
//var_dump($curlRes);
$curlResInfo = curl_getinfo($curl);
curl_close($curl);

$resHeadersString = substr($curlRes, 0, $curlResInfo['header_size']);
$resBody          = substr($curlRes, $curlResInfo['header_size']);

$response = json_decode($resBody);

//#########################################
//output
echo ("<br>CREATE CATEGORY<br>");
print_r($response);

?>

[/dropdown] [dropdown:PHP - UPDATING A FOLDER]

<?php
//#########################################
//CONFIG
//#########################################
//token 
$tokenTHRON        = 'TOKEN';
// client 
$client_idTHRON    = 'CLIENTID';
//  category  id
$idCatTHRON        = "CATEGORY ID";
// category name
$categoryNameTHRON = 'NAME CATEGORY ';
//locale
$categoryLocale    = "LOCALE"; // IT or EN    

//#########################################
//MAIN
//#########################################    


$url     = "http://" . $client_idTHRON . "-view.thron.com/api/xcontents/resources/category/updateCategory4Locale";
$header  = array(
    'X-TOKENID: ' . $tokenTHRON,
    "Content-Type: application/json"
);
//echo $url;    
$request = array(
    // an usually required attribute for web service calls
    "client" => array(
        "clientId" => $client_idTHRON
    ),
    // properties that categories in the reponse
    "catId" => $idCatTHRON,
    "property" => array(
        "name" => $categoryNameTHRON,
        "locale" => $categoryLocale
    )
    
);

//if it is not empty
if ($parentIdCat != "")
    $request["upCatId"] = $parentIdCat;

$request = json_encode($request);
$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);
//var_dump($curlRes);
$curlResInfo = curl_getinfo($curl);
curl_close($curl);

$resHeadersString = substr($curlRes, 0, $curlResInfo['header_size']);
$resBody          = substr($curlRes, $curlResInfo['header_size']);

$response = json_decode($resBody);

//#########################################
//output
echo ("<br>UPDATE CATEGORY <br>");
print_r($response);

?>

[/dropdown] [dropdown:PHP - DELETING A FOLDER]

<?php
//#########################################
//CONFIG
//#########################################
//token 
$tokenTHRON        = 'TOKEN';
// client 
$client_idTHRON    = 'CLIENTID';
//  category  id
$idCatTHRON        = "CATEGORY ID";
// category name
$categoryNameTHRON = 'NAME CATEGORY ';
//locale
$categoryLocale    = "LOCALE"; // IT or EN    
//cascade remove (Used to force the remove also in the subcategories)
$cascadeRemove     = false;


//#########################################
//MAIN
//#########################################    

/** 
REMOVE CATEGORY
**/
$url     = "http://" . $client_idTHRON . "-view.thron.com/api/xcontents/resources/category/removeCategory";
$header  = array(
    'X-TOKENID: ' . $tokenTHRON,
    "Content-Type: application/x-www-form-urlencoded"
);
//echo $url;        
$request = 'clientId=' . $client_idTHRON . '&catId=' . $idCatTHRON . '&cascade=' . $cascadeRemove;

$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);

$resHeadersString = substr($curlRes, 0, $curlResInfo['header_size']);
$resBody          = substr($curlRes, $curlResInfo['header_size']);
$response         = json_decode($resBody);

//#########################################
//output
echo ("<br>REMOVE CATEGORY <br>");
print_r($response);

?>

[/dropdown] [dropdown:JAVA - CREATING A FOLDER]

import it.newvision.nvp.xcontents.model.MCategory4Locale;
import it.newvision.nvp.xcontents.services.model.category.MResponseNewCategory;
import it.newvision.nvp.xcontents.services.model.common.MCredential;
import it.newvision.nvp.xcontents.services.model.request.MCategorycreateCategoryReq;
import it.newvision.nvp.xcontents.services.rest.JCategoryClient;
import org.codehaus.jackson.map.ObjectMapper;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by THRON s.p.a. on 18/12/14.
 */
public class createCategory {

    public static void main(String [ ] args)
    {
        /*SETUP FILE*/
        String clientId="CLIENTID";
        String tokenID="TOKEN";
        // name category
        String categoryNameTHRON = " NAME CATEGORY";
        // locale
        String categoryLocale = "LOCALE"; //IT or EN
        //MAIN
        //init object
        ObjectMapper mapper = new ObjectMapper();
        try {
            JCategoryClient categoryClient= new JCategoryClient("http://"+clientId+"-view.thron.com/api/xcontents/resources");
            //set param
            MCategorycreateCategoryReq param = new MCategorycreateCategoryReq();
            MCredential credential = new MCredential();
            MCategory4Locale category4Locale= new MCategory4Locale();
            // param
            credential.setClientId(clientId);
            category4Locale.setLocale(categoryLocale);
            category4Locale.setName(categoryNameTHRON);
            param.setClient(credential);
            param.setCatLocales(category4Locale);
            //execute
            MResponseNewCategory ris=categoryClient.createCategory(tokenID, param, null);
            //RESULT THRON
            System.out.println(mapper.writeValueAsString(ris));
        }
        catch (Exception e)
        {
            //error file THRON
            System.out.println(e);
        }
    }
   }

[/dropdown] [dropdown:JAVA - UPDATING A FOLDER]

import it.newvision.nvp.xcontents.model.MCategory4Locale;
import it.newvision.nvp.xcontents.services.model.category.MResponseUpdateCategory;
import it.newvision.nvp.xcontents.services.model.common.MCredential;
import it.newvision.nvp.xcontents.services.model.request.MCategoryupdateCategory4LocaleReq;
import it.newvision.nvp.xcontents.services.rest.JCategoryClient;
import org.codehaus.jackson.map.ObjectMapper;
import java.util.ArrayList;
 import java.util.List;


/**
 * Created by THRON s.p.a. on 18/12/14.
 */
public class updateCategory {

    public static void main(String [ ] args)
    {

        /*SETUP FILE*/
        String clientId="CLIENTID";
        String tokenID="TOKEN";
        // name category
        String categoryNameTHRON = "NEW NAME CATEGORY";
        // locale
        String categoryLocale = "LOCALE";//IT or EN
        // id category
        String idCatTHRON="CATEGORY ID";
        //MAIN
        //init object
        ObjectMapper mapper = new ObjectMapper();
        try {

            JCategoryClient categoryClient= new JCategoryClient("http://"+clientId+"-view.thron.com/api/xcontents/resources");
            //set param
            MCategoryupdateCategory4LocaleReq param = new MCategoryupdateCategory4LocaleReq();
            MCredential credential = new MCredential();
            MCategory4Locale category4Locale= new MCategory4Locale();
            // param
            credential.setClientId(clientId);
            category4Locale.setLocale(categoryLocale);
            category4Locale.setName(categoryNameTHRON);
            param.setClient(credential);
            param.setProperty(category4Locale);
            param.setCatId(idCatTHRON);
            //execute
            MResponseUpdateCategory ris=categoryClient.updateCategory4Locale(tokenID, param, null);
            //RESULT THRON
            System.out.println(mapper.writeValueAsString(ris));

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

    }
   }

[/dropdown] [dropdown:JAVA - DELETING A FOLDER]

import it.newvision.nvp.xcontents.services.model.category.MResponseRemoveCategory;
import it.newvision.nvp.xcontents.services.rest.JCategoryClient;
import org.codehaus.jackson.map.ObjectMapper;
import java.util.ArrayList;
import java.util.List;


/**
 * Created by THRON s.p.a. on 18/12/14.
 */
public class removeCategory {

    public static void main(String [ ] args)
    {

        /*SETUP FILE*/
        String clientId="CLIENTID";
        String tokenID="TOKEN";
        // id category
        String idCatTHRON="CATEGORY ID";
        //cascade remove (Used to force the remove also in the subcategories)
        boolean cascadeRemove=true;
        //MAIN
        //init object
        ObjectMapper mapper = new ObjectMapper();
        try {
            //set param
            JCategoryClient categoryClient= new JCategoryClient("http://"+clientId+"-view.thron.com/api/xcontents/resources");
            //execute
            MResponseRemoveCategory ris=categoryClient.removeCategory(tokenID, clientId,idCatTHRON,cascadeRemove, null);
            //RESULT THRON
            System.out.println(mapper.writeValueAsString(ris));

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

    }
   }

[/dropdown] [/tab]

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

Have more questions?

SUBMIT A REQUEST

Hai altre domande?

INOLTRA UNA RICHIESTA

Comments