2

Using the Sharepoint REST API, I am able to get "Author" (which I take as owner/creator info) information for both Files and Folders. For Files, I can simply expand the "Author" element and get Title and UserId information. For Folders, I have to use the "AuthorId" field from expanding "ListItemAllFields" to make a subsequent REST call to resolve the Title and UserId information by Id (I don't like this extra step either but I haven't found a way to get that info for Folders with a single GET). However, for the base Lists and their associated "RootFolder"s, I do not get Author information, even if I expand the RootFolder's ListItemAllFields. Is there a way to get the owner\creator information for at least the Document Library Lists where my Folders and Files reside? I expected that expanding the RootFolder's ListItemAllFields would give me the "AuthorId" like it does for the sub-folders that have been created in the Document Library but all I get for this: .../_api/Web/GetFolderByServerRelativeUrl('docLibraryRootFolderServerRelativeUrl')/ListItemAllFields, is:

{
    "d": {
        "ListItemAllFields": null
    }
}

1 Answer 1

1

ListItemAllFields property returns associated List Item with File or Folder objects.

For List object

REST query:

http://<sitecollection>/<site>/_api/web/lists/getbytitle(listtitle)/ListItemAllFields

returns nothing since List object is not associated with List Item object.


In order to retrieve Author property for List object you could utilize the following approach. The solution is to extract Author property from List XML schema.

The following method is used to return all available properties for List object:

function getListProperties(listTitle) {
   var listEndpointUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/SchemaXml";
   return getJson(listEndpointUrl).then(
          function(data){
              var schemaXml = data.d.SchemaXml;
              return schemaXml2Json(schemaXml);     
          });     
}

where

function getJson(url) 
{
    return $.ajax({       
       url: url,   
       type: "GET",  
       contentType: "application/json;odata=verbose",
       headers: { 
          "Accept": "application/json;odata=verbose"
       }
    });
}

function schemaXml2Json(schemaXml)
{ 
    var jsonObject = {};
    var schemaXmlDoc = $.parseXML(schemaXml);
    $(schemaXmlDoc).find('List').each(function() {
      $.each(this.attributes, function(i, attr){
           jsonObject[attr.name] = attr.value;
      });
    });
    return jsonObject;
}    

Usage

How to get Author property for List object:

getListProperties('Discussion Board')
.done(function(properties)
{
    console.log('List created by: ' + properties.Author);
})
.fail(
function(error){
    console.log(JSON.stringify(error));
});

Please follow this post for a more details.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Vadim, I'll have to give that a try. My code is written in Java and I request JSON for my responses. Will requesting the "schemaXml" endpoint with "Accept": application/json;odata=verbose give me a JSON response or would I have to get the XML and convert it to JSON as in your example.
Thomas, good question. Unfortunately requesting "schemaXml" endpoint will return a xml string and that's the reason why i am using schemaXml2Json. But I hope that converting xml string into json object could be done also easily in Java

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.