2

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.

  • CreatedBy is type of person & group. So i think you have to make changes in query. Refer this link – SP Developer Feb 29 '16 at 5:48
5

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"
  • 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" – Vishnu PS Jul 30 '16 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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