Let’s say I have a Document Library “Documents” with structured folders like this:

- Folder1(ID1)
     - SubfolderA(ID3)
     - SubfolderB(ID6)
- Folder2(ID2)

I need to get IDs of all checked out files beneath Folder1. In case of this example I would have IDs (5;7;8)

I can do this like this:

/_api/web/Lists/getbytitle('Documents')/items?$top=1000&$select=FieldValuesAsText/ID&$expand=FieldValuesAsText&$filter=((CheckoutUser ge '1') and (FSObjType eq '0') and (startswith(FileRef, ' MySite/Documents/Folder1/')))

But for large libraries (30 000 items) it is getting very slow as it probably goes through all items in all folders.

So, my second approach was using getfolderbyserverrelativeurl:

/_api/web/getfolderbyserverrelativeurl('/MySite/Documents/Folder1')/files?$expand=ListItemAllFields&$top=100&$filter=((CheckOutType eq 0) or (CheckOutType eq 1))&$select=ListItemAllFields/ID

But this returns me only files that are in Folder1 and will not return files that are located in subfolders.

My third approach was something like this:

/_api/web/getfolderbyserverrelativeurl('/MySite/Documents/Folder1')?$expand=Files,Files/ListItemAllFields,Folders/Files,Folders/Files/ListItemAllFields,Folders/Folders/Files,Folders/Folders/Files/ListItemAllFields&$select=Files/ListItemAllFields/ID,Files/CheckOutType,Folders/Files/ListItemAllFields/ID,Folders/Files/CheckOutType,Folders/Files/Name,Folders/Folders/Files/ListItemAllFields/ID,Folders/Folders/Files/CheckOutType,Folders/Folders/Files/Name&$top=100&$filter=((CheckOutType eq 0) or (CheckOutType eq 1))

That one returns me files few levels deep in subfolders as well, works quite fast, but I can’t use filters on it to return only files that are checked out.

Anyone with great ideas how to achieve described results without overloading the server and not taking forever to complete with large libraries? If that matters, I am on SP 2013.

2 Answers 2


Perhaps Search could be an option, look for documents where the CheckoutUser property contains a value


You can use GetItems method in combination with setting FolderServerRelativeUrl property and Scope.

var viewXml = "<View Scope='RecursiveAll'><Query><Where><Geq><FieldRef Name='CheckoutUser' LookupId="TRUE" /><Value Type='int'>0</Value></Geq></Where></Query></View>";
var url = webUrl + "/_api/web/lists/getbytitle('Title of the List')/getitems"; 
var query = {  
           'query' : {
                  '__metadata': { 'type': 'SP.CamlQuery' }, 
                  'ViewXml' : viewXml,
                  'FolderServerRelativeUrl': 'Server Relative Url to the folder' 

return $.ajax({
       url: url,
       method: "POST",
       data: JSON.stringify(query),
       headers: {
          "X-RequestDigest": $("#__REQUESTDIGEST").val(),
          "Accept": "application/json; odata=verbose",
          "content-type": "application/json; odata=verbose"
  • Is it possible to use this approach in SharePoint Designer workflow with Call HTTP Service action?
    – Ruba
    Oct 8, 2018 at 11:19
  • Yes, you can build a request in SPD.
    – sssreddy
    Oct 8, 2018 at 12:56
  • In SPD I can just call one URL. I can't just paste javascript code to the action URL. SPd stripes off everithing after first line. Perhaps I don't know yet how to feed this javascript to SPD. Would you point me to the right direction please?
    – Ruba
    Oct 11, 2018 at 10:25
  • You should not paste js code in SPD. You have to add a http call action and make a POST request. I do not have SPD right now to post screen shots but here is an example cann0nf0dder.wordpress.com/2017/06/26/… that uses http post. The data in variable query is what goes into request body.
    – sssreddy
    Oct 11, 2018 at 15:36
  • Anyone here to help, how to "convert" this javascript to be working with SPD Workflow Call HTTP Web Service action?
    – Ruba
    Oct 17, 2018 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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