2

I need to display the Creator of the SarePoint List in a Project using REST api. When I use

/_api/web/lists/getbytitle('Employee')

I get a response but , I don't find the Created By Field. How do I know who has created the List. Here is my Response:

"AllowContentTypes": true,
"BaseTemplate": 100,
"BaseType": 0,
"ContentTypesEnabled": false,
"CrawlNonDefaultViews": false,
"Created": "2014-12-03T06:58:18Z",
"DefaultContentApprovalWorkflowId": "00000000-0000-0000-0000-000000000000",
"Description": "",
"Direction": "none",
"DocumentTemplateUrl": null,
"DraftVersionVisibility": 0,
"EnableAttachments": true,
"EnableFolderCreation": false,
"EnableMinorVersions": false,
"EnableModeration": false,
"EnableVersioning": false,
"EntityTypeName": "EmployeeList",
"ForceCheckout": false,
"HasExternalDataSource": false,
"Hidden": false,
"Id": "13cdc8f4-7fed-42eb-9a38-08c30eec6a87",
"ImageUrl": "/_layouts/15/images/itgen.png?rev=38",
"IrmEnabled": false,
"IrmExpire": false,
"IrmReject": false,
"IsApplicationList": false,
"IsCatalog": false,
"IsPrivate": false,
"ItemCount": 2,
"LastItemDeletedDate": "2014-12-03T06:58:18Z",
"LastItemModifiedDate": "2015-01-21T05:54:31Z",
"ListItemEntityTypeFullName": "SP.Data.EmployeeListItem",
"MajorVersionLimit": 0,
"MajorWithMinorVersionsLimit": 0,
"MultipleDataList": false,
"NoCrawl": false,
"ParentWebUrl": "/",
"ParserDisabled": false,
"ServerTemplateCanCreateFolders": true,
"TemplateFeatureId": "00bfea71-de22-43b2-a848-c05709900100",
"Title": "Employee"

Thanks

2 Answers 2

2

How to retrieve List Author property using SharePoint REST Interface

List resource does not expose Author property, but you could retrieve it from List Schema as demonstrated below (*).

  • First step is to retrieve List Schema: /_api/web/lists/getbytitle('list title')?$select=schemaXml
  • Then you could extract Author Id from SchemaXml property

(*) List SchemaXml property stores Author ID property

Example

function getListAuthor(webUrl,listTitle)
{
    var endpointUrl = webUrl + "/_api/web/lists/getbytitle('" + listTitle + "')?$select=schemaXml";
    return executeRequest(endpointUrl,'GET').then(function(data){
             var listProperties = schemaXml2Json(data.d.SchemaXml);
             return parseInt(listProperties.Author);
           });
}


//Usage: Retrieve List Author Id
getListAuthor(_spPageContextInfo.webAbsoluteUrl,'Contacts')
.done(function(authorId){
    console.log('List Author Id: ' + authorId);

});

If List Author Id property is not enough and you would like to retrieve Author user, then you could utilize the following example:

var webUrl = _spPageContextInfo.webAbsoluteUrl;
getListAuthor(webUrl,'Contacts')
.then(function(authorId){
    getSiteUser(webUrl,authorId)
    .done(function(data){
         var listAuthor = data.d;
         console.log(listAuthor);
    });     
}); 

where

function executeRequest(url,method,headers,payload) 
{
    if (typeof headers == 'undefined'){
        headers = {};
    }
    headers["Accept"] = "application/json;odata=verbose";
    if(method == "POST") {
        headers["X-RequestDigest"] = $("#__REQUESTDIGEST").val();
    }   

    var ajaxOptions = 
    {       
       url: url,   
       type: method,  
       contentType: "application/json;odata=verbose",
       headers: headers
    };
    if(method == "POST") {
      ajaxOptions.data = JSON.stringify(payload);
    }  

    return $.ajax(ajaxOptions);
}


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;
}


function getSiteUser(webUrl,userId){
    var endpointUrl = webUrl + "/_api/web/siteUsers/getById(" + userId +  ")";
    return executeRequest(endpointUrl,'GET');
}
8
  • That's right, only if you have items in your list, it's always safe to get the root folder of the list which exists by default in all cases.
    – user19105
    Commented Jan 21, 2015 at 7:51
  • I disagree, there is no need to get root folder at all Commented Jan 21, 2015 at 7:53
  • OK, what if there are not items yet in the list? :)
    – user19105
    Commented Jan 21, 2015 at 7:56
  • @VadimGremyachev: i need to know who has created the List and not the List item. Commented Jan 21, 2015 at 7:57
  • 2
    @VadimGremyachev, that is an amazing answer. I know these are the type of questions you like to answer. Another challenging question (at least for me :-)) here sharepoint.stackexchange.com/questions/128845/…, which hasn't got your attention yet. Commented Jan 21, 2015 at 11:23
1

That property is not exposed on the SharePoint Client API. You can get the 'Created' property but not the Author property. See SP.List Members here

5
  • Unfortunatelly this is incorrect statement Commented Jan 21, 2015 at 7:56
  • I believe the question is talking about 'Created By' or 'Author' of the SharePoint list not the items in the list and as per the documentation I do not see that property being available on the Client Api. Let me know otherwise.
    – sssreddy
    Commented Jan 21, 2015 at 8:00
  • Hi sssreddy, yes it's not available on the SPList object itself, but you can get this author from other locations, like AllItems.aspx view for example.
    – user19105
    Commented Jan 21, 2015 at 8:03
  • I guess you are right. I was able to pull author info from allitems.aspx which should technically be same as creator of the list.
    – sssreddy
    Commented Jan 21, 2015 at 8:13
  • @sssreddy, my mistake,I was assuming the OP wants to retrieve CreatedBy for List Item. You're right, List resource does not expose Author property. Commented Jan 21, 2015 at 11:45

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.