I am creating sharepoint hosted app. In that I created one list. Now I want to create folder in that list when I click on the button. Since it is in the same domain I am not using any cross domain requests. I am having following code. This code is working well in sharepoint without using any app, like adding into script editor webpart etc.

RESTQueries.createFolderInLibrary = function(){
    var execute = function(libraryName,folderName){
        var deferred = $.Deferred();
        var _url=   makeProperUrl();
            url: _url + "_api/web/getfolderbyserverrelativeurl('"+libraryName+"')/folders",
            contentType:"application/json; odata=verbose",
            data: JSON.stringify({ '__metadata': { 'type': 'SP.Folder' }, 'ServerRelativeUrl': folderName}),
                        "Accept":"application/json; odata=verbose", 
                        "X-RequestDigest": $("#__REQUESTDIGEST").val()
        return deferred;
        execute : execute

But if I execute the same code in sharepoint app, it is giving error like "(null) \"sites/mysite/sharepointapp/AllPicturesLibrary/Test\" not found. i dont know what is this meant for? Can't we create a folder under document library in app web using sharepoint hosted app?

  • What does makeProperUrl look like? – eirikb Nov 22 '14 at 19:18
  • makeProperUrl is appweburl – Mihir Nov 23 '14 at 8:46

I could be mistaken, but I think your problem is makeProperUrl function.
Based on your comments in your question I'm going to assume that the function returns the app web url from query string, and in most cases this will not end with a slash, so then your query would try to access .../MyPrettyLittleAppUrl_api/web...
To fix this simply add a forward slash before _api.

If you open your favorite web dev tools with a Network overview you should be able to see that the URL used for the query has this problem.

| improve this answer | |

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.