How to retrieve List Author property using SharePoint REST Interface
By default REST query /_api/web/lists/getbytitle('<list title>')/items
returns AuthrorId
List resource does not expose Author property, but you could retrieve it from List Schema as demonstrated below (User Id for Created By
field*).
- 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:
{
"d": {
"results":function [getListAuthor(webUrl,listTitle)
{
var endpointUrl = webUrl + "/_api/remaining outputweb/lists/getbytitle('" is+ omittedlistTitle for+ clarity"')?$select=schemaXml";
"FileSystemObjectType":return 0executeRequest(endpointUrl,'GET').then(function(data){
var listProperties "Id":= 1,schemaXml2Json(data.d.SchemaXml);
"ContentTypeId":return "0x010070092C478B02EF49ADA0691DE01FFBF6",parseInt(listProperties.Author);
"Title": "John Doe",});
}
//Usage: Retrieve List "Email":Author "jdoe@contosoId
getListAuthor(_spPageContextInfo.com"webAbsoluteUrl,'Contacts')
"ID": 1,.done(function(authorId){
console.log('List "Modified":Author "2015-01-21T07:33Id:21Z",
' "Created":+ "2015-01-21T07:33:21Z",authorId);
"AuthorId": 17,
"EditorId": 17,});
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 "OData__UIVersionString":= "1_spPageContextInfo.0"webAbsoluteUrl;
getListAuthor(webUrl,'Contacts')
.then(function(authorId){
"Attachments": falsegetSiteUser(webUrl,authorId)
.done(function(data){
var listAuthor "GUID":= "01e58248-b0fc-4353-ad59-64010d9bb331"data.d;
}console.log(listAuthor);
}); ]
}
}
Using $expand
OData operator you can specify that the request returns projected fields from other lists and the values of lookups.
The following REST endpoint:
/_api/web/lists/getbytitle('<list title>')/items?$select=Author/Title,Author/EMail&$expand=Author;
returns Title
and Email
for Author
(Created By
) column in list:where
{
function "d":executeRequest(url,method,headers,payload)
{
if (typeof headers "results":== ['undefined'){
headers = {};
}
headers["Accept"] = "application/json;odata=verbose";
if(method == "__metadata":"POST") {
"id": "07849f26-815c-40df-ba3dheaders["X-efaac658c066",
RequestDigest"] "uri":= "https://contoso.sharepoint.com/_api/Web/Lists$(guid'81916ced-b57f-4940-bf1a-eef4af00aaee'"#__REQUESTDIGEST")/Items.val(1)",;
} "etag": "\"1\"",
var ajaxOptions "type":= "SP.Data.ContactsListItem"
{ },
"Author"url: {
url,
type: method,
"__metadata"contentType: {"application/json;odata=verbose",
"id"headers: "b503837d-4cce-4b8f-96a4-26341abfc39a",headers
};
if(method == "POST") {
ajaxOptions.data "type":= "SP.DataJSON.UserInfoItem"stringify(payload);
}
return $.ajax(ajaxOptions);
},
function schemaXml2Json(schemaXml)
{
var jsonObject = {};
var schemaXmlDoc = $.parseXML(schemaXml);
"Title": "John$(schemaXmlDoc).find('List').each(function() Doe",{
$.each(this.attributes, function(i, attr){
jsonObject[attr.name] "EMail":= "[email protected]attr.com"value;
});
});
return jsonObject;
}
function getSiteUser(webUrl,userId){
var endpointUrl }
= webUrl + "/_api/web/siteUsers/getById(" + userId + ]")";
}return executeRequest(endpointUrl,'GET');
}
Example