How to send messages in a chat via API

Darsh Mishra 0 Reputation points
2023-07-13T09:17:28.6333333+00:00

Basically i want to repopulate a group chat in MS-Teams incase it gets deleted. So i have backed up all the messages in a json and will run a script to repopulate them in a new group chat by sending the messages in sorted by time manner so it will appear similar to as they appeared before. So i am looking for an API to send message in a group chat but i am getting the following error:: "

{ "error": { "code": "Unauthorized", "message": "Message POST is allowed in application-only context only for import purposes. Refer to https://docs.microsoft.com/microsoftteams/platform/graph-api/import-messages/import-external-messages-to-teams for more details.", "innerError": { "date": "2023-07-12T12:00:13", "request-id": "c88404fc-1233-445a-bdb7-cdfef1aa86e3", "client-request-id": "c88404fc-1233-445a-bdb7-cdfef1aa86e3" } } }

Microsoft Teams | Development
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 46,371 Reputation points
    2023-07-13T10:28:45.7933333+00:00

    Hi @Darsh Mishra

    Importing messages in chat is not supported, only team channels support importing third-party platform messages, which requires you to use the Teamwork.Migrate.All application permission to obtain an access token in the application-only context (client credentials flow), then create the team and channel in the migrated state.

    User's image

    After the team and channel have been created, you can begin sending back-in-time messages using the createdDateTime and from keys in the request body.

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.