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

Microsoft Graph API - Create a User and send message on behalf on the new user


I'm able to create a new user via /v1.0/users endpoint. Is it possible to send a new message to a channel on behalf of this new user, after adding it to the respective Team?

I've tried sending a POST request to https://graph.microsoft.com/beta/teams/team_id/channels/channel_id/messages, but all the messages send using this method creates a new message on behalf of the user, whose access_token I'm using to send the request.

So should I have to have access_token for the new user for sending on his behalf? Is there any thing else similar to this workflow?


Solution

  • There are only two ways to connect to Graph endpoints - either in "delegated" mode, in which case the call acts on the behalf of the signed in user, whose token you have, or "application", in which case it's acting on behalf of a backend application id, rather than a specific user. It's NOT possible to have one user act on behalf of another user - that could lead to many unpleasant situations.

    Consequently, for your scenario, you have two options:

    1. Once you've created the user, you need to have your code sign in on behalf of that user. This might not be practical to do 100% automated, depending on things like MFA policies in your organization.

    2. Post as an application, but prepend the message, e.g. "Bob says: ..."