0

I have done some research and seems like this isn't possible, so I figured I would ask.

I am doing a rest GET call to see if a folder exists, if it doesn't I create a new folder, if it does then I use that folder.

Anyway, I am taking advantage of this for this specific function, so to me it's not really an error, but would obviously return a 404 not found error if the folder doesn't exist.

Is it possible to add anything inside of my code to not return this error?

try {
    $.ajax({
        url: serverUrl+"/_api/Web/GetFolderByServerRelativeUrl('"+serverRelativeUrlToFolder+"')",
        type: "GET",
        headers: { "accept": "application/json;odata=verbose" },
        async: false,
        success: function(data)
        {   // if the call was successfull, then the folder must already exist
            returnValue = true;
        },
        error: function(data)
        {
            returnValue = false;
        }
    });

console returns

jquery.min.js:4 GET myurlhere 404 (Not Found)

nalzok
  • 14,965
  • 21
  • 72
  • 139
user2620493
  • 7
  • 1
  • 6
  • 1
    Is this your REST api or a third party? If it is yours, why not design an endpoint which you use to check if a folder exists and it can return a 200 response and data containing info about. – aalcutt Jul 20 '17 at 21:18
  • Sorry totally new to most of all of this, just started in feb.. It is to a sharepoint document folder. I dont have access to any of our server infastructure. Only to my sites where I am writing custom javascript for. If I can still do this could you kindly point me to some literature or maybe some search terms I could be using? – user2620493 Jul 21 '17 at 18:13

1 Answers1

0

i don't know if its just me, but I dont think an $.ajax call can really check if a folder exists, unless you have index.html in that folder or something... $.ajax calls an URL, not a folder... so its all based on which webserver you use, which configuration you use, etc. etc. (For example the webserver can use url_rewrite module, and it would look like the folder exists) . but still, folder and url are 2 totally different things...

Raf A.
  • 124
  • 1
  • 4
  • 9
  • I figured as much, its for sharepoint. Im just going to leave as is, but the other option I could do is return the actual folder names (the names are the id's) then just loop through and return true or false. This way I am not specifying a specific folder name (number). – user2620493 Jul 21 '17 at 18:11
  • Oh I should have mentioned. The folder ID is the ID of the content Item that already exists. The name is also the ID of the content Item it belongs to. – user2620493 Jul 21 '17 at 18:16
  • I realized I put in the wrong function in the question. Updated to reflect actual scendario – user2620493 Jul 21 '17 at 18:19