3

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.

1
  • CreatedBy is type of person & group. So i think you have to make changes in query. Refer this link Commented Feb 29, 2016 at 5:48

1 Answer 1

6

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"
6
  • 1
    You can try like this to get the ID of the Authour without expanding the field var Ownurl = _spPageContextInfo.webAbsoluteUrl + "_api/web/lists/getbytitle('Listname')/items?$select=AuthorId" Commented Jul 30, 2016 at 9:35
  • @VishnuPS I get Column 'AuthorId' does not exist doing that. Commented Aug 28, 2019 at 13:54
  • @VishnuPS Could you please share your REST API Url.. Commented Aug 28, 2019 at 14:46
  • @VishnuPS Actually, I figured out my issue. I could not include a filter like I wanted to do. That line was fine. It just meant I would have to check for the length of my results and iterate each one, then check if the data.d.results[i].AuthorId == authorId; ... Commented Aug 28, 2019 at 20:45
  • @RohitWaghela That actually IS the entire API URL... And I couldn't get your version to work, but his was fine... Commented Aug 28, 2019 at 20:46

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.