Koehler
Koehler

Reputation: 83

Microsoft Graph API for Teams: Send Channel/ Chat messages

I want to use the Microsoft Graph API to send messages to chats or channels.

I created an App in-app registrations. enter image description here

Created a secret and I am able to get a token with this, using the below URI

https://login.microsoftonline.com//oauth2/v2.0/token

I also set the permissions to the below enter image description here

I am trying to use the Teamwork API

POST /teams/{team-id}/channels/{channel-id}/messages

I get the below response

{"error":{"code":"Forbidden","message":"Missing role permissions on the request. API required one of 'Teamwork.Migrate.All, ChannelMessage.ReadWrite.All'. Roles on the request ''","innerError":{"date":"2021-08-10T19:01:16","request-id":"MyID","client-request-id":"MyID"}}}

Where would I assign these permissions would it be in API permissions or would I assign a new role in Roles and Administrators

Upvotes: 4

Views: 5161

Answers (1)

nastassiar
nastassiar

Reputation: 1621

Your issue is those are both application permissions where as all the existing ones are delegated permissions.

In the portal instead of clicking Delegated permissions click Application Permissions and you can add Teamwork.Migrate.All and ChannelMessage.ReadWrite.All.

Also note that these both require Admmin consent so you will have to have the admin either login first and grant permission, or send an admin a consent link to allow your app these permissions: https://learn.microsoft.com/en-us/azure/active-directory/manage-apps/grant-admin-consent

Go to portal.azure.com > Azure Active Directory Blade > App Registrations > Your App > API Permission > Graph API > Application permissions

enter image description here

You can find out more about delegated versus application permissions here: https://learn.microsoft.com/en-us/graph/permissions-reference#channel-permissions

Upvotes: 5

Related Questions