I'm trying to create a list using REST API, the javascript is in a Sharepoint Page, I'm logged as a System Account and every time I run the script I get the following error:
{"error":{"code":"-1, Microsoft.SharePoint.SPException","message":{"lang":"pt-BR","value":"N\u00e3o h\u00e1 contexto do aplicativo para executar esta solicita\u00e7\u00e3o."}}}
Translating to english it would be:
There is no app context to execute this request.
My code to create the list is:
var params = "{ '__metadata': { 'type': '"+type+"' },'AllowContentTypes': true,'ContentTypesEnabled': true, 'BaseTemplate': 100,'Description': '" + list + "', 'Title':'" + listName + "'}";
var Url = _spPageContextInfo.webAbsoluteUrl+"/_api/SP.AppContextSite(@target)/web/lists?@target='"+_spPageContextInfo.webAbsoluteUrl+"'";
var formDigest = $('#__REQUESTDIGEST').val();
$.ajax({
url: Url,
method: 'POST',
dataType: "json",
contentType: 'application/json',
headers: {
Accept: "application/json;odata=verbose",
"X-RequestDigest": formDigest
},
data: JSON.stringify(params),
cache: true,
error: function (data) {
console.log("Error");
},
success: callback
});