AnsweredAssumed Answered

How to create a site with REST API from javascript?

Question asked by anandhan on Aug 30, 2017
Latest reply on Aug 31, 2017 by anandhan

This is what am trying to do ,top create a site from REST API in javascript.

(Alfresco community edition 201707)

function CreateSite(){
/*TEST API - START*/
var siteBodyCreate = {
"id": "NewTest",
"title": "NewTest",
"description": "NewTest",
"visibility": "PUBLIC"
};

$.ajax({
type: 'POST',
beforeSend: function(request) {
request.setRequestHeader("Authority", 'Basic YWRtaW46YWRtaW4=');
},
headers: {
'Content-Type': 'application/json',
'Accept':'application/json',
'Authorization': 'Basic YWRtaW46YWRtaW4='
},
dataType: 'json',
url: 'http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/sites?skipConfiguration=false&skipAddToFavorites=false',
data:JSON.stringify({"entry" : siteBodyCreate}) ,
success: function(data) {
alert(data);
} ,
failure : function(data){
alert(data);
}
});
/*TEST API - END*/
}

i get the following error

{
"error": {
"errorKey": "Could not read content from HTTP request body: Unrecognized field \"entry\" (Class org.alfresco.rest.api.model.Site), not marked as ignorable\n at [Source: java.io.BufferedReader@5ad545e1; line: 1, column: 11] (through reference chain: org.alfresco.rest.api.model.Site[\"entry\"])",
"statusCode": 400,
"briefSummary": "07300002 Could not read content from HTTP request body: Unrecognized field \"entry\" (Class org.alfresco.rest.api.model.Site), not marked as ignorable\n at [Source: java.io.BufferedReader@5ad545e1; line: 1, column: 11] (through reference chain: org.alfresco.rest.api.model.Site[\"entry\"])",
"stackTrace": "For security reasons the stack trace is no longer displayed, but the property is kept for previous versions",
"descriptionURL": "https://api-explorer.alfresco.com"
}
}

 

What is the right approach?

Outcomes