AnsweredAssumed Answered

Récupérer une réponse de RESTApi

Question asked by jackarnd on May 30, 2017
Latest reply on Jun 1, 2017 by jackarnd

Bonjour,
J'aimerais parser une chaîne de caractères reçue par : http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/people 
J'ai donc écris ce code qui devrait me retourner le nom, le prénom et le mail de la première personne :

<p id="peoplelist"></p>

<script>
   
var people = new XMLHttpRequest();
   
people.onreadystatechange = function() {
      
if (this.readyState == 4 && this.status == 200) {
         
obj = JSON.parse(this.responseText);
         
document.getElementById("peoplelist").innerHTML = obj.list.entries[0].entry.firstName + obj.list.entries[0].entry.lastName + "," + obj..list.entries[0].entry.email;
      
}
   
};
   
people.open('GET', 'http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/people'true, 'admin', 'admin');
   
people.send();
</script>

Seulement je reçois une erreur basique d'authentification But this gives me a basic 401 console error about the authentification

:8080/alfresco/api/-default-/public/alfresco/versions/1/people Failed to load resource: the server responded with a status of 401 (Unauthorized)
new-page:1 XMLHttpRequest cannot load http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/people. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8081' is therefore not allowed access. The response had HTTP status code 401.

En outre quand je vais manuellement sur http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/people la pop-up basique de login s'ouvre et je peux me loguer avec admin/admin normalement et récupérer le résultat attendu :

{"list":{"pagination":{"count":7,"hasMoreItems":false,"totalItems":7,"skipCount":0,"maxItems":100},"entries":[{"entry":{"lastName":"Beecher","userStatus":"Helping to design the look and feel of the new web site","jobTitle":"Graphic Designer","statusUpdatedAt":"2011-02-15T20:20:13.432+0000","mobile":"0112211001100","emailNotificationsEnabled":true,"description":"Alice is a demo user for the sample Alfresco Team site.","telephone":"0112211001100","enabled":false,"firstName":"Alice","skypeId":"abeecher","avatarId":"198500fc-1e99-4f5f-8926-248cea433366","location":"Tilbury, UK","company":{"organization":"Moresby, Garland and Wedge","address1":"200 Butterwick Street","address2":"Tilbury","address3":"UK","postcode":"ALF1 SAM1"},"id":"abeecher","email":"abeecher@example.com"}},{"entry":{"firstName":"Administrator","emailNotificationsEnabled":true,"company":{},"id":"admin","enabled":true,"email":"admin@alfresco.com"}},{"entry":{"firstName":"Alex","lastName":"lol","emailNotificationsEnabled":true,"company":{},"id":"alexandra","enabled":true,"email":"alexandra.lol@test.com"}},{"entry":{"firstName":"Guest","emailNotificationsEnabled":true,"company":{},"id":"guest","enabled":false}},{"entry":{"firstName":"Jack","lastName":"lol","emailNotificationsEnabled":true,"company":{},"id":"jack","enabled":true,"email":"jack.lol@test.com"}},{"entry":{"lastName":"Jackson","userStatus":"Working on a new web design for the corporate site","jobTitle":"Web Site Manager","statusUpdatedAt":"2011-02-15T20:13:09.649+0000","mobile":"012211331100","emailNotificationsEnabled":true,"description":"Mike is a demo user for the sample Alfresco Team site.","telephone":"012211331100","enabled":false,"firstName":"Mike","skypeId":"mjackson","avatarId":"3fbde500-298b-4e80-ae50-e65a5cbc2c4d","location":"Threepwood, UK","company":{"organization":"Green Energy","address1":"100 Cavendish Street","address2":"Threepwood","address3":"UK","postcode":"ALF1 SAM1"},"id":"mjackson","email":"mjackson@example.com"}},{"entry":{"firstName":"Nicolas","lastName":"lol","emailNotificationsEnabled":true,"company":{},"id":"nicolas","enabled":true,"email":"nicolas.lol@test.com"}}]}}

Si quelqu'un sait comment faire pour accéder à cette page avec du code ou où est-ce que je me suis tromper merci d'avance !

Outcomes