-Visual Studio 2017.
To connect Rest API- App should needed the permission- try add app permissions in AppManifest.xml (I have added Site Collection with Full rights).
var appUrl;
var hostWebUrl;
//
Reading the query string from the URL
function
getQueryStringParameter(param) {
var params =
document.URL.split("?")[1].split("&");
var strParams = "";
for (var i = 0; i <
params.length; i = i + 1) {
var singleParam = params[i].split("=");
if (singleParam[0] == param) {
return singleParam[1];
}
}
}
$(document).ready(function () {
appUrl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));
hostWebUrl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
//cross
domain library
$.getScript(hostWebUrl + "/_layouts/15/SP.RequestExecutor.js", connectREST);
});
function connectREST() {
var url = appUrl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('Change
Request')/items?@target='" + hostWebUrl + "'";
var executor = new SP.RequestExecutor(appUrl);
executor.executeAsync({
url: url,
method: "GET",
headers: { "Accept": "application/json;odata=verbose" },
success: function (data) {
$("#message").html("REST call connected/success");
},
error: function (data) {
$("#message").html("Error while REST API");
}
});
}
No comments:
Post a Comment