Forum Discussion
JGlowacki
May 31, 2023Copper Contributor
How to use Microsoft Teams (free) chat API?
I want to consume the Microsoft Teams (free) API using my personal account to read my chats. This API lives under https://teams.live.com/api/*, not https://teams.microsoft.com/api/*. I cannot use Get chat method from Microsoft Graph since it does not support personal Microsoft accounts, only work or school accounts.
How can I do it?
4 Replies
Sort By
- JGlowackiCopper Contributor
I have found out the following private Microsoft Teams (Free) API endpoints:
# Get users by ID: POST https://teams.live.com/api/mt/beta/users/fetch?isMailAddress=false&canBeSmtpAddress=false&enableGuest=true&includeIBBarredUsers=true&skypeTeamsInfo=true Headers: {"authorization": "Bearer xxx", "content-type": "application/json;charset=UTF-8", "x-skypetoken": "xxx", ...} Request body: ["8:live:.cid.xxx"] Response: {"type":"Microsoft.SkypeSpaces.MiddleTier.Models.User","value":[{"isShortProfile":true,"isBlocked":false,"imageUri":"https://substrate.office.com/profile/v1.0/users/cid:xxx/image/$value?hashKey=''","cid":"xxx","objectId":"00000000-0000-0000-xxxx-xxxxxxxxxxxx","skypeTeamsInfo":{"isSkypeTeamsUser":true},"featureSettings":{"isPrivateChatEnabled":true,"enableShiftPresence":false,"enableScheduleOwnerPermissions":false},"userPrincipalName":"live:.cid.xxx","givenName":"xxx","surname":"xxx","status":200,"phonesInfo":[],"emailsInfo":[{"address":"xxx"}],"displayName":"xxx","type":"TFLUser","mri":"8:live:.cid.xxx"}]} # Get my chats: GET https://teams.live.com/api/csa/api/v1/teams/users/me/updates?isPrefetch=false&enableMembershipSummary=true Headers: {"x-ms-session-id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "x-ms-synctoken": "xxx", "x-skypetoken": "xxx", "x-csendpoint": "https://msgapi.teams.live.com/", ...} Response: {"teams":[],"chats":[{"id":"19:xxx@thread.v2","consumptionHorizon":{"originalArrivalTime":000,"timeStamp":000,"clientMessageId":"xxx"},"retentionHorizon":null,"retentionHorizonV2":null,"members":[{"isMuted":false,"mri":"8:live:.cid.xxx","objectId":".cid.xxx","role":"User","isIdentityMasked":false},{"isMuted":false,"mri":"8:live:.cid.xxx","objectId":".cid.xxx","role":"Admin","isIdentityMasked":false}],"title":null,"version":000,"threadVersion":000,"isRead":true,"isHighImportance":true,"isOneOnOne":true,"lastMessage":{"messageType":"RichText/Html","content":"xxx","clientMessageId":"xxx","imDisplayName":"xxx","id":"xxx","type":"Message","composeTime":"xxx","originalArrivalTime":"xxx","containerId":"19:xxx@thread.v2","parentMessageId":"xxx","from":"8:live:.cid.xxx","sequenceId":2,"version":000,"threadType":null,"isEscalationToNewPerson":false},"isLastMessageFromMe":false,"chatSubType":0,"lastJoinAt":"xxx","createdAt":"xxx","creator":"8:live:.cid.xxx","tenantId":"00000000-0000-0000-0000-000000000000","hidden":true,"isGapDetectionEnabled":true,"interopType":0,"isConversationDeleted":false,"isExternal":false,"addedBy":"8:live:.cid.xxx","addedByTenantId":"00000000-0000-0000-0000-000000000000","isMessagingDisabled":false,"extensionDefinition":{"updatedTime":"xxx","tabsEtag":null},"isDisabled":false,"importState":"unknown","chatType":"chat","interopConversationStatus":"None","conversationBlockedAt":0,"hasTranscript":false,"templateType":"immutableroster","isSticky":true,"relationshipState":{"inQuarantine":true},"meetingPolicy":"Unknown","rosterVersion":000,"identityMaskEnabled":false}],"users":[],"channels":[],"privateFeeds":[],"metadata":{"syncToken":"xxx","forwardSyncToken":null,"isPartialData":false,"hasMoreChats":false}} # Add a buddy: POST https://teams.live.com/api/mt/beta/contacts/buddylist/TflContacts/managebuddies?migrationRequested=true&federatedContactsSupported=true Headers: {"authorization": "Bearer xxx", "content-type": "application/json;charset=UTF-8", "x-skypetoken": "xxx", "x-ms-session-id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", ...} Request body: {"add":[{"mri":"8:live:.cid.xxx","displayName":"xxx"}]} Response: {"id":"TflContacts","displayName":"TflContacts","groupType":"TflContacts","buddies":[{"displayName":"xxx","mri":"8:live:.cid.xxx"}]} # Send message: POST https://msgapi.teams.live.com/v1/users/ME/conversations/19:xxx@thread.v2/messages Headers: {"authentication": "skypetoken=xxx", "x-ms-session-id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "content-type": "application/json;charset=UTF-8", ...} Request body: {"content":"xxx","messagetype":"RichText/Html","contenttype":"text","amsreferences":[],"clientmessageid":"xxx","imdisplayname":"xxx","properties":{"importance":"","subject":""}} Response: {"OriginalArrivalTime":000} # Edit message: PUT https://msgapi.teams.live.com/v1/users/ME/conversations/19:xxx@thread.v2/messages/xxx Headers: {"authentication": "skypetoken=xxx", "x-ms-session-id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "content-type": "application/json;charset=UTF-8", ...} Request body: {"content":"xxx","messagetype":"RichText/Html","contenttype":"text","amsreferences":[],"clientmessageid":"xxx","imdisplayname":"xxx","properties":{"importance":"","subject":""}} Response: {"OriginalArrivalTime":000} # Poll for new messages: GET https://weu.notifications.skype.com/users/8:live:.cid.xxx/endpoints/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/events/poll Headers: {"authentication": "skypetoken=xxx", "x-ms-session-id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "x-ms-query-params": "cursor=000&epfs=srt&sca=1"} Response: {"next":"https://weu.notifications.skype.com/users/8:live:.cid.xxx/endpoints/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/events/poll?cursor=000&lsid=xxx&lsv=xxx&epfs=srt&sca=0","eventMessages":[{"time":"xxx","type":"EventMessage","resourceLink":"https://notifications.skype.net/v1/users/ME/conversations/19:xxx@thread.v2/messages/xxx","resourceType":"NewMessage","resource":{"clientmessageid":"xxx","content":"xxx","from":"https://notifications.skype.net/v1/users/ME/contacts/8:live:.cid.xxx","imdisplayname":"xxx","id":"xxx","messagetype":"RichText/Html","originalarrivaltime":"xxx","properties":{"importance":"","subject":"","languageStamp":"languages=null:0;&detector=Bling"},"sequenceId":000,"version":"xxx","composetime":"xxx","type":"Message","prioritizeimdisplayname":null,"conversationLink":"https://notifications.skype.net/v1/users/ME/conversations/19:xxx@thread.v2","to":"19:xxx@thread.v2","contenttype":"text","threadtype":"chat","isactive":true}}]}
- Meghana-MSFT
Microsoft
It is not possible to read chats using personal accounts. As you rightly said Get chat graph API does not support personal Microsoft account.- JGlowackiCopper Contributor
Meghana-MSFTThanks, but is there another way to read chats apart from Microsoft Graph API? Or will it be available in the near future?
- Meghana-MSFT
Microsoft
JGlowacki - No there aren't any.