I'm trying to get some project data using the REST API. My queries work fine when using Postman. But when it comes to SharePoint-Hosted app, I'm getting a "404 (Not Found)" error. My app is deployed on the PWA root web. Here is my code:
function GetProject() {
var deferred = $.Deferred();
JSRequest.EnsureSetup();
var hostweburl = decodeURIComponent(JSRequest.QueryString["SPHostUrl"]);
var appweburl = decodeURIComponent(JSRequest.QueryString["SPAppWebUrl"]);
var context = new SP.ClientContext(appweburl);
var appContextSite = new SP.AppContextSite(context, hostweburl);
var restQueryUrl = appweburl + "/_api/SP.AppContextSite(@target)/ProjectServer/Projects?@target='" + hostweburl + "'";
var executor = new SP.RequestExecutor(appweburl);
executor.executeAsync({
url: encodeURI(restQueryUrl),
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data, textStatus, xhr) {
deferred.resolve(JSON.parse(data.body).d);
},
error: function (xhr, textStatus, errorThrown) {
deferred.reject(JSON.parse(xhr.body).error.message.value);
}
});
return deferred;
};
Would you have some inputs to solve my problem? Thanks.
Regard,