1

There is a way of how to add comments to Sharepoint site using REST API. It is explained here https://beaucameron.com/2021/01/18/add-comments-to-sharepoint-list-items-using-the-rest-api/ for example. But when I add comment like this, it adds it on behalf of my name - because REST endpoint is accessed using access token, which is linked to my e-mail.

I'd like to migrate comments from one site to the other, and keep original authors. Is there a way to post comments on behalf of other users? I tried this POST body:

{
  "__metadata": {
    "type": "Microsoft.SharePoint.Comments.comment"
  },
  "text": "Some new comment",
  "author": {
    "__metadata": {
      "type": "SP.Sharing.Principal"
    },
    "email": "AlexW@OnMicrosoft.com",
    "id": 18,
    "loginName": "i:0#.f|membership|alexw@onmicrosoft.com",
    "name": "Alex Wilber",
    "principalType": 1
  }
}

But still, comment is posted on behalf of my name. The response is like the following:

{
    "d": {
        "__metadata": {
            "id": "https://sharepoint.com/_api/web/lists('017dd808-5a37-4d65-89f9-b5ce994554b4')/GetItemById(1)/Comments(15)",
            "uri": "https://sharepoint.com/_api/web/lists('017dd808-5a37-4d65-89f9-b5ce994554b4')/GetItemById(1)/Comments(15)",
            "type": "Microsoft.SharePoint.Comments.comment"
        },
        "likedBy": {
            "__deferred": {
                "uri": "https://sharepoint.com/_api/web/lists('017dd808-5a37-4d65-89f9-b5ce994554b4')/GetItemById(1)/Comments(15)/likedBy"
            }
        },
        "replies": {
            "__deferred": {
                "uri": "https://sharepoint.com/_api/web/lists('017dd808-5a37-4d65-89f9-b5ce994554b4')/GetItemById(1)/Comments(15)/replies"
            }
        },
        "author": {
            "__metadata": {
                "type": "SP.Sharing.Principal"
            },
            "email": "myName.mySurname@onmicrosoft.com",
            "expiration": null,
            "id": 12,
            "isActive": true,
            "isExternal": false,
            "jobTitle": null,
            "loginName": "i:0#.f|membership|myName.mySurname@onmicrosoft.com",
            "name": "myName mySurname",
            "principalType": 1,
            "userId": null,
            "userPrincipalName": null
        },
        "createdDate": "2022-05-24T08:40:19.0841947Z",
        "id": "15",
        "isLikedByUser": false,
        "isReply": false,
        "itemId": 1,
        "likeCount": 0,
        "listId": "017dd808-5a37-4d65-89f9-b5ce994554b4",
        "mentions": null,
        "parentId": "0",
        "replyCount": 0,
        "text": "Some new comment"
    }
}

So still, I'm the author of the comment...

kosist
  • 2,868
  • 2
  • 17
  • 30

0 Answers0