AnsweredAssumed Answered

Reset favourites script

Question asked by cristianfrog on Jul 23, 2013
Latest reply on Jul 24, 2013 by zladuric
Hi all,

I'm searching for a solution to manage or better saying RESET specific user's favourites. For this purpose I didn't find a function or maybe webscript, so I tried writing one by myself.

I figured out that to reset someone's favourites from Admin account I need to send this POST content:
{"org":{"alfresco":{"share":{"documents":{"favourites":""}}}}}


to this page:

http://localhost:8080/share/proxy/alfresco/api/people/USERNAME/preferences


It works fine when I do it manually through Live Http Headers, but can't get it work within a script.

Here how my JS script looks:

var simplehttpresult = "no result";
var xmlhttpresult = "no result";
var error = "no error";

// try calling the web script a couple different ways
try {

   //call the web service using SimpleHttpConnection
   simplehttpresult = SimpleHttpConnection
               .getContentAsString("http://localhost:8080/share/proxy/alfresco/api/people/usernametest/preferences");

   //call the web service synchronously via XMLHttpRequest
   XMLHttpRequest
                .open("POST", "http://localhost:8080/share/proxy/alfresco/api/people/usernametest/preferences",
                         false, "user", "pass");
   
   XMLHttpRequest.setRequestHeader("Host", "localhost:8080");
   XMLHttpRequest.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
   XMLHttpRequest.setRequestHeader("Cookie", "_alfTest=_alfTest; JSESSIONID=72F1A690CC001AF5080B86854CA10542; alfLogin=1374511322; alfUsername3=admin");
   
   XMLHttpRequest.send("{\"org\":{\"alfresco\":{\"share\":{\"documents\":{\"favourites\":\"\"}}}}}");
   xmlhttpresult = XMLHttpRequest.getResponseText();
   XMLHttpRequest.close();

}catch(ex){error = String(ex)}


How you can see I've used XMLHttpRequest to send the HTTP POST content, I found and installed the JAR library here:
http://www.unorganizedmachines.com/site/software-and-technology/34-software-development/97-calling-web-services-from-alfresco-web-scripts

It works well when I'm trying to send a HTTP Request to an external site or page (example: www.google.com) but it doesn't when I'm trying to reset favourites…

Can someone help me about this??
There is not much documentation about managing favourites  :(

Outcomes