I am successful in getting data from host web to app web but the problem i am facing with is querying the API.

This is i am trying to do but getting error..

    var getTaskByUser = function (userID) {
            var hostweburl =
           var  appweburl =
            var scriptbase = hostweburl + "/_layouts/15/";

            // Load the js files and continue to the successHandler
            $.getScript(scriptbase + "SP.RequestExecutor.js", execCrossDomainRequest);
            function execCrossDomainRequest() {
            // executor: The RequestExecutor object
            // Initialize the RequestExecutor with the add-in web URL.
            var executor = new SP.RequestExecutor(appweburl);
            appweburl +
            "/_api/SP.AppContextSite(@target)/web/lists/GetByTitle('Asana2')/Items?$select=Title,Category?@target='" +
            hostweburl + "'",
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: successHandler,
        error: errorHandler


 GET https://niisar-3b7c10c2234504.sharepoint.com/Development/SharePointApp1/_ap…ect=Title,Category?@target=%27https://niisar.sharepoint.com/Development%27 
400 (Bad Request)

"{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"The expression \"Title,Category?@target='https://niisar.sharepoint.com/Development'\" is not valid."}}}"

Need help. I am new to sharepoint

  • What's your error? sharepoint hosted or provider hosted app? Oct 15 '15 at 4:55
appweburl + "/_api/SP.AppContextSite(@target)/web/lists/GetByTitle('Asana2')/Items?$select=Title,Category?@target='" + hostweburl + "'"

It seems your URL is not valid where you are requesting to. Try following URL

var url = appweburl +
"/_api/SP.AppContextSite(@target)/web/lists/GetByTitle('Asana2')/Items?$select=Title,Category&@target='" +
hostweburl + "'";

The problem is you have used ? after $select but it will be &.

Remember few things while constructing rest end-point.

  • Main part of URL should be ended up with ?
  • Rest of the parts will be joined with & like @target, $select, $filter and other query operators.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.