Table of contents
Introduction
I recently found out that one can modify an item's or file's author in SharePoint, along with other normally read-only fields. I've tested this with an item's Author and the FirstPublishedDate for news in SharePoint.
Even after changing the author, the SharePoint Lists' feature that only allows the item's author to edit it still works.
In my situation, I had to transfer list items from SharePoint into a new format, while preserving the original authors and their editing rights. This is why I developed a flow to serve as a subsidiary to a larger migration flow.
Actions
As this is a child flow, I have a manual trigger with inputs referencing the variables below and a „Respond to flow or app“ - action at the end.
Variables
I strongly recommend using variables. I have created three to help with the flow.
- intItemId - Integer - This holds the item ID where the author's information needs to be updated.
- strUserEmail - String - This is the user E-Mail that will replace the current author.
- strLibraryId - String - This is the unique ID of a library or list in SharePoint Online.
Getting the entity name
Getting the entity name is needed to write back the new author to the item.
Uri
_api/web/lists(guid'@{variables('strLibraryId')}')/?$select=ListItemEntityTypeFullName
Find the Id for the Author Field
Every field in SharePoint has a GUID (Globally Unique Identifier), which is used to modify the field. If you already have the GUID for the author field, you can skip this step. It should be consistent across SharePoint. Knowing this will make it easier to manage other fields without the need to verify each time.
Uri
_api/web/lists(guid'@{variables('strLibraryId')}')/fields?$filter=EntityPropertyName eq 'Author'
Lookup the user with the corresponding SharePoint user Id
The Author field does not accept a simple E-Mail address. That is why you will need to translate the users E-Mail address to a SharePoint unique user id.
Uri
_api/web/siteusers/getByEmail('@{variables('strUserEmail')}')
Unlock the Author field
Since the author field, among others, is technically locked and read-only, you'll need to unlock it to alter the author of a specific list item.
Uri
_api/web/lists(guid'@{variables('strLibraryId')}')/fields(guid'@{first(body('Send_an_HTTP_request_to_SharePoint_-_Find_Author_Field_Id')?['d']?['results'])?['Id']}')
Header
{
"Content-Type": "application/json;odata=verbose",
"IF-Match": "*",
"X-HTTP-Method": "PATCH"
}
Body
{ '__metadata': { 'type': 'SP.Field' }, 'ReadOnlyField': false }
Overwrite the Author field value
In this step we use the users SharePoint user id to update the author.
Uri
_api/web/lists(guid'@{variables('strLibraryId')}')/items(@{variables('intItemId')})
Header
{
"Content-Type": "application/json;odata=verbose",
"IF-Match": "*",
"X-HTTP-Method": "PATCH"
}
Body
{ '__metadata': { 'type': '@{body('Send_an_HTTP_request_to_SharePoint_-_Entity_Name')?['d']?['ListItemEntityTypeFullName']}' }, 'AuthorId': @{body('Send_an_HTTP_request_to_SharePoint_-_Lookup_User')?['d']?['Id']} }
Lock the Author field
Once you've made all the necessary changes, remember to lock the field again. In my case, each change requires unlocking and relocking the field. However, it's also possible to keep the field unlocked while making changes and only lock it once all changes are complete.
Uri
_api/web/lists(guid'@{variables('strLibraryId')}')/fields(guid'@{first(body('Send_an_HTTP_request_to_SharePoint_-_Find_Author_Field_Id')?['d']?['results'])?['Id']}')
Header
{
"Content-Type": "application/json;odata=verbose",
"IF-Match": "*",
"X-HTTP-Method": "PATCH"
}
Body
{ '__metadata': { 'type': 'SP.Field' }, 'ReadOnlyField': true}