I'm trying to programmatically change the "Created By" -field of a list item in a SharePoint list. As a development tool, I'm using the Microsoft Graph API python library - msgraph-sdk for python.
I've read a lot about similar issues online, and the PowerAutomate solutions use the validateUpdateListItem REST endpoint, and other solutions seem to first change the list column read only state to false, then update the Author/Created By value.
I assume I need to use the second method, since if I simply try to change the "AuthorLookupId" of a list item, I get 403:
fields = FieldValueSet(
additional_data={
"AuthorLookupId": user_item.id,
}
)
await graph_client.sites.by_site_id(site_id).lists.by_list_id(
list.id
).items.by_list_item_id(added_item.id).fields.patch(fields)
In the above snippet, the added_item is the return value of a previous addition (POST) to the same list. This addition succeeds and I can see the row inside the list. user_item is a user from the User Information List, so the id should match and work with AuthorLookupId.
However, if I first patch the list's "Created By" field's readonly value to be false, I no longer get 403:
list_cols = (
await graph_client.sites.by_site_id(site_id)
.lists.by_list_id(list.id)
.columns.get()
)
author_col: Optional[ColumnDefinition] = next(
(col for col in list_cols.value if col.name == "Author"),
None,
)
patch_auth_col = ColumnDefinition(read_only=False)
await (
graph_client.sites.by_site_id(site_id)
.lists.by_list_id(list.id)
.columns.by_column_definition_id(author_col.id)
.patch(patch_auth_col)
)
After this patch, the first code snippet doesn't return 403 anymore, and the patch seems to succeed. However, the "Created By" -value inside the list item does not change. Why is that? What am I doing wrong?
