0

I want to update Author Name of a file in Sharepoint using Rest api. I can retrieve the author name of a file using the url "_api/web/getfolderbyserverrelativeurl('Foldername')/Files('Filename')?$select=Author/Title&$expand=Author". Is there a way to update the Author name of a file using rest api call? The file is present in a particular folder and the folder is present under Shared documents.

1 Answer 1

0

I tested to update Author field using the Rest API below, it turns out for system field "Author", it's not available to update.

Even set "ReadOnlyField" to false, still not able to update:

<script type="text/javascript">
var properties = {
    '__metadata': { "type": "SP.Data.Shared_x0020_DocumentsItem" },
    'Title':'TestTitle',
    'AuthorId': 27  //Another User Id 
};
var requestUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getfolderbyserverrelativeurl('/sites/dev/shared%20documents')/Files('Test2019.txt')/ListItemAllFields";
updateJson(requestUrl,properties)
.done(function(data){
   console.log('List item has been updated'); 
})
.fail(function(error){
   console.log(JSON.stringify(error)); 
})

function updateJson(url,payload)
{
   return $.ajax({
      url: url,
      type: "POST",
      contentType: "application/json;odata=verbose",
      data: JSON.stringify(payload),
      headers: {
         "Accept": "application/json;odata=verbose",
         "X-RequestDigest": $("#__REQUESTDIGEST").val(),
         "X-HTTP-Method": "MERGE",
         "If-Match": "*"
      }
   });    
}
</script>

For other normal person field, it's working.

In Summary, per the test result, the Author field can't be updated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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