I'm trying to use the graph.microsoft.com
API to retrieve users and channels from Microsoft Teams and send messages to those channels. I'm using Python and trying to accomplish these tasks.
Access token fetch through msal
library using oauth 2.0 (initiate_auth_code_flow
+ acquire_token_by_auth_code_flow
)
import requests
url = "https://graph.microsoft.com/v1.0/users"
headers = {
"Authorization": "Bearer <TOKEN>",
"Content-Type": "application/json"
}
response = requests.get(url, headers=headers)
print(response.content)
However, I'm encountering different errors depending on the endpoint used:
- For
/me
, I receive a valid response.
{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users/$entity","userPrincipalName":"******@bugbug.io","id":"905eed23ad42a35c","displayName":"BugBug IT","surname":"IT","givenName":"BugBug","preferredLanguage":"en-US","mail":"******@bugbug.io","mobilePhone":null,"jobTitle":null,"officeLocation":null,"businessPhones":[]}'
- For
/users
, I receive an InternalServerError
with the message "Invalid response. Expected list response must have value property."
{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users","value":[{"error":{"code":"InternalServerError","message":"Invalid response. Expected list response must have value property.","innerError":{"date":"2024-02-16T07:52:25","request-id":"f5c6afb6-1435-4eee-8bc4-8987ef335eed","client-request-id":"f5c6afb6-1435-4eee-8bc4-8987ef335eed"}}}
- For
/users/{userId}/chats
, I receive a Forbidden
error with the message "No authorization information present on the request."
{"error":{"code":"Forbidden","message":"No authorization information present on the request.","innerError":{"date":"2024-02-16T07:52:26","request-id":"0a73d36b-cf32-47cc-9a31-9aa41fb2afe3","client-request-id":"0a73d36b-cf32-47cc-9a31-9aa41fb2afe3"}}}
Also, here are the scopes I'm using for the permissions (defined in my Application).
-
Channel.ReadBasic.All
-
ChannelMessage.Send
-
Chat.Create
-
Chat.Read
-
Chat.ReadBasic
-
Chat.ReadWrite
-
Chat.ReadWrite.All
-
ChatMember.Read
-
ChatMessage.Read
-
ChatMessage.Send
-
Directory.AccessAsUser.All
-
Directory.Read.All
-
profile
-
User.Read
-
User.Read.All
-
User.ReadBasic.All