Search code examples
microsoft-graph-apimicrosoft-teamsmicrosoft-graph-teams

Couldn't import messages to primary channel in Microsoft Teams


I followed this doc step by step to import messages in a channel to a new team

Things were going well, but I have a problem when I tried to import messages to a primary channel in a new created team.

The API responded success when I imported a message to a primary channel.

URL: https://graph.microsoft.com/v1.0/teams/61826bbc-4b7d-48f7-a5aa-ba8d82756170/channels/19:[email protected]/messages
METHOD: POST
REQ_BODY: {
  "createdDateTime": "2023-04-14T03:27:43.499Z",
  "importance": "normal",
  "from": {
    "user": {
      "id": "3aa4fc7d-c1b0-4f85-a72c-ca5c9057ef3d",
      "displayName": "CAT",
      "email": "[email protected]",
      "userIdentityType": "aadUser",
      "tenantId": "dcb0e1d1-6cde-4420-a658-ede52a8bead1"
    }
  },
  "body": {
    "contentType": "html",
    "content": "\u003cdiv\u003e\n\u003cdiv itemprop=\"copy-paste-block\"\u003e\n\n\u003cdiv style=\"font-size:14px\"\u003e一般的文字\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e"
  }
}
RES_STATUS: 201
RES_BODY: {"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#teams('61826bbc-4b7d-48f7-a5aa-ba8d82756170')/channels('19%3A4f99689e8f904f65bff4f68b55976d57%40thread.tacv2')/messages/$entity","id":"1681442863499","replyToId":null,"etag":"0","messageType":"message","createdDateTime":"2023-04-14T03:27:43.499Z","lastModifiedDateTime":"0001-01-01T00:00:00Z","lastEditedDateTime":null,"deletedDateTime":null,"subject":null,"summary":null,"chatId":null,"importance":"normal","locale":"en-us","webUrl":"https://teams.microsoft.com/l/message/19%3A4f99689e8f904f65bff4f68b55976d57%40thread.tacv2/1681442863499?groupId=61826bbc-4b7d-48f7-a5aa-ba8d82756170&tenantId=dcb0e1d1-6cde-4420-a658-ede52a8bead1&createdTime=1681442863499&parentMessageId=1681442863499","policyViolation":null,"eventDetail":null,"from":{"application":null,"device":null,"user":{"@odata.type":"#microsoft.graph.teamworkUserIdentity","id":"3aa4fc7d-c1b0-4f85-a72c-ca5c9057ef3d","displayName":"CAT","userIdentityType":"aadUser"}},"body":{"contentType":"html","content":"<div>\n\n<div itemprop=\"copy-paste-block\">\n\n\n<div style=\"font-size:14px\">\u4e00\u822c\u7684\u6587\u5b57</div>\n</div>\n</div>"},"channelIdentity":{"teamId":"61826bbc-4b7d-48f7-a5aa-ba8d82756170","channelId":"19:[email protected]"},"attachments":[],"mentions":[],"reactions":[]}

But when I listed messages in the channel after finishing migration, I saw null content with the uploaded message.

I expect the responded content of the message is the same as what I imported.

GET https://graph.microsoft.com/v1.0/teams/61826bbc-4b7d-48f7-a5aa-ba8d82756170/channels/19:[email protected]/messages
{
  "id": "1681442863499",
  "replyToId": null,
  "etag": "1681442863499",
  "messageType": "message",
  "createdDateTime": "2023-04-14T03:27:43.499Z",
  "lastModifiedDateTime": "2023-04-14T03:27:43.499Z",
  "lastEditedDateTime": null,
  "deletedDateTime": "2023-04-14T03:27:43.499Z",
  "subject": null,
  "summary": null,
  "chatId": null,
  "importance": "normal",
  "locale": "en-us",
  "webUrl": "https://teams.microsoft.com/l/message/19%3A4f99689e8f904f65bff4f68b55976d57%40thread.tacv2/1681442863499?groupId=61826bbc-4b7d-48f7-a5aa-ba8d82756170&tenantId=dcb0e1d1-6cde-4420-a658-ede52a8bead1&createdTime=1681442863499&parentMessageId=1681442863499",
  "from": null,
  "policyViolation": null,
  "eventDetail": null,
  "body": {
    "contentType": "text",
    "content": null
  },
  "channelIdentity": {
    "teamId": "61826bbc-4b7d-48f7-a5aa-ba8d82756170",
    "channelId": "19:[email protected]"
  },
  "attachments": [
    
  ],
  "mentions": [
    
  ],
  "reactions": [
    
  ]
},

This weird behavior only happens when I import messages to a primary channel. It's ok if I import messages to a new created channel.

I would be appreciate if someone can tell me how to sovle the problem, thank you.


Solution

  • From @Meghana-MSFT

    please verify the timestamp specified on messages during import was one that is later than the timestamp of creation of channel

    It works. Be noted that the create time of the primary channel can't be patched, the create time is the same as the create time of the team, and you can create a team with speicifed createdDateTime in migration mode.