SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I get CreatedBy field using REST API SharePoint? Below is the code

var Ownurl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Listname')/items?$select=Author,ID&$filter=ID eq 1;  

        $.ajax({  
               url: Ownurl,  
               headers: { Accept: "application/json;odata=verbose" },  
               async:false,  
               success: function (data) {  
                        var items = data.d.results;  
                        if (items[0].Author!= "") {  
                                author = items[0].Author;
                            }  
                        },eror: function (data) {  
                            alert("An error occurred. Please try again.");  
                            }  
               }); 

But somehow I am not able to get Author. Is there anything wrong?

Any help would be appreciated

Thanks.

share|improve this question
    
CreatedBy is type of person & group. So i think you have to make changes in query. Refer this link – Vishal M. Patil Feb 29 at 5:48
up vote 4 down vote accepted

Please try following REST URL, you must expand the Person and Group field.

var Ownurl = _spPageContextInfo.webAbsoluteUrl + "_api/web/lists/getbytitle('Listname')/items?$filter=Id eq 1&$expand=Author&$select=Author/Id"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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