1

I am attempting to do a cross domain request from my app.

Document Library Title name is !@$^&()-+={[}]|;MEEPBEEP with the Server URL of MEEPBEEP

In accessing the host web in my request executor my function is as follows

function findDL() {
var executor;
var dfd = new jQuery.Deferred();
executor = new SP.RequestExecutor(appweburl);
executor.executeAsync({
    url: appweburl + "/_api/SP.AppContextSite(@target)/Web/Lists" +
        "?@target='" + hostweburl + "'" +
        "&$select=Id, Title&$top=5000&$filter=Title eq '" + ListInfo.oldName + "'",
    type: "GET",
    dataType: "json",
    headers: {
        Accept: "application/json;odata=verbose"
    },
    success: successHandler(dfd),
    error: errorHandler(dfd)
});
return dfd;
}

function successHandler(dfd, data) {
return dfd.resolve;
}
function errorHandler(dfd, data, errorCode, errorMessage) {
console.log(errorMessage);
return dfd.reject;
}

When I attempt this without special character it works fine but when I add in the & my request 404 on me.

To continue testing I opened up postman and attempted to find the list by using

hostWEB/_api/web/lists?$filter=Title eq ' listname'

and without special characters I am able to get the list information.

When I search for a list name with a & in it It 404 on me. When I change the & to %26 I get the following JSON returned to me

{
    "d": {
        "results": []
    }
}

So clearly SharePoint can find the list but it's not returning any information to me. I have add the OData Select Statements to select the columns I wish to see but I still get a blank JSON result.

An attempt with GetByTitle returns the list information. Sadly I don't believe I can use this endpoint as it is a cross domain request.

If I am unable to fix this issue I simply make a workflow that will use the GetByTitle but I would rather not lose the code I have worked one.

The following request worked:

var executor;
var dfd = new jQuery.Deferred();
executor = new SP.RequestExecutor(appweburl);
executor.executeAsync({
    url: appweburl + "/_api/SP.AppContextSite(@target)/Web/Lists/GetByTitle('" + ListInfo.oldName + "')?@target='" + encodeURIComponent(hostweburl) + "'",
    type: "GET",
    dataType: "json",
    headers: {
        Accept: "application/json;odata=verbose"
    },
    success: successHandler(dfd),
    error: errorHandler(dfd)
});
return dfd;

Still I am left wondering why the OData Query gives me a blank result set. While the fix does seem to work, It leaves me to wonder if this is a bug with SharePoint OData Filtering options.

  • Are you encoding hostweburl? I'm not 100% certain, but I believe it needs to be encoded. I noticed your code snippet is missing an ending single quote ('). Is this just a typo when copying the code over? – wjervis Jul 24 '14 at 17:59
  • As for your belief about being unable to use GetByTitle, you can use it. I've never had any trouble with /web/lists/getbytitle() in Cross Domain calls. Almost all the REST I've been doing lately is Cross Domain, and I've yet to find any discrepancies in what you can do. – wjervis Jul 24 '14 at 18:02
  • It was an error thanks for point that out. I Tried to use the url appweburl + "/_api/SP.AppContextSite(@target)/Web/Lists/GetByTitle('" + ListInfo.oldName + "')" + "?@target='" + hostweburl + "'" but that didnt seem to work either. Is this correct format to use? – McFrank Jul 24 '14 at 18:25
  • Try encodeURIComponent(hostweburl) – wjervis Jul 24 '14 at 18:33
  • Just to verify, your REST request works in Postman, but fails when converting to Cross Domain request? – wjervis Jul 24 '14 at 18:34

Your Answer

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

Browse other questions tagged or ask your own question.