SOLVED

Sending message/replies to teams channel using graph api

Copper Contributor

I am trying to send message to teams channel using graph api and Python's msal library to get tokens. I have registered the app in Azure portal and added permission(delegated and application) to it as per docs . I am able to generate token, although tokens received only reflect application permission and not delegated permission. I am able to send messages using my username in graph explorer but NOT able to do it using my app. 

I tried searching many docs/forums but no luck:sad:; not sure what I am missing.



pritam2277_0-1624889777697.pngpritam2277_1-1624889798051.png

 Below are received decoded token and error message:{
"aud": "https://graph.microsoft.com",
"iss": "https://sts.windows.net/ff9b87e***********************/",
"iat": 1624887965,
"nbf": 1624887965,
"exp": 1624891865,
"aio": "E2Z*************=",
"app_displayname": "MyApp",
"appid": "dc753**************",
"appidacr": "1",
"idp": "https://sts.windows.net/ff9b87e3-c54*******************/",
"idtyp": "app",
"oid": "2b5abfe6-7********************",
"rh": "0.AR*********************************************",
"roles": [
"Teamwork.Migrate.All"
],
"sub": "2b5abfe6-73*************************",
"tenant_region_scope": "NA",
"tid": "ff9b87e3-c5************************",
"uti": "cv5Yb******************",
"ver": "1.0",
"wids": [
"0997a1d0-0d1d-*****************"
],
"xms_tcdt": 1420304885
}
Token Expires at: 2021-06-28 20:21:05
{'error': {'code': 'UnknownError', 'message': '', 'innerError': {'date': '2021-06-28T13:51:08', 'request-id': '2cc385c5-85e4-4fde-824c-399bac232e1e', 'client-request-id': '2cc385c5-85e4-4fde-824c-399bac232e1e'}}}

8 Replies
best response confirmed by Wajeed-MSFT (Microsoft)
Solution

@pritam2277 - You are currently using Get access without a user(Application permission). Application permissions are only supported for migration. Instead you should try delegated flow:  Get access on behalf of a userPlease go though the documentation and you can try it using Postman or Fiddler. 

 

You can also try Get started with Microsoft Graph and Python tutorial which shows fetching calendar information using Graph APIs.

 

Please let me know if you are still facing any issues.

Thanks @Wajeed-MSFT  for reply. Will it be possible for you have a quick call with me?

@pritam2277 - Unfortunatly no. Could you please share more specifics on issue which you are facing currently? Did you try  Get started with Microsoft Graph and Python?

@Wajeed-MSFT  While sending message to teams channel, I was getting error as protected api access denied. So I requested protected api access for my application. Microsoft teams has approved the access for application but they also mentioned and I quote "Application-only context sending of messages is only supported in teams which are in migration mode and requires Teamwork.Migrate.All. Refer to

Use Microsoft Graph to import external platform messages to Teams - Teams | Microsoft Docs for what migration mode means. "

 

Does it mean that it's not possible to send messages FROM APPLICATION to existing channels in team as it only support teams in migration mode?

@pritam2277 Yes, while using application permission for sending messages, you can't just send message until team is in migration state. Please use delegated flow(Get access on behalf of a user - Microsoft Graph | Microsoft Docs) .

@Wajeed-MSFT @HunaidHanfee-MSFT I tried with delegated workflow. It's working. Thank you!

Hi @HunaidHanfee-MSFT ,

 

Which particular permission should be assigned for replies to teams channel post. I am able to make a new post but not send a reply to one. Getting below error.

 

Error posting reply: {"error":{"code":"Unauthorized","message":"Message POST is allowed in application-only context only for import purposes.

@varunjassidpl Permissions to my app.


pritam2277_0-1710320409144.png

 

1 best response

Accepted Solutions
best response confirmed by Wajeed-MSFT (Microsoft)
Solution

@pritam2277 - You are currently using Get access without a user(Application permission). Application permissions are only supported for migration. Instead you should try delegated flow:  Get access on behalf of a userPlease go though the documentation and you can try it using Postman or Fiddler. 

 

You can also try Get started with Microsoft Graph and Python tutorial which shows fetching calendar information using Graph APIs.

 

Please let me know if you are still facing any issues.

View solution in original post