0
votes

I'm having issues with extracting channel messages from a Microsoft Team. I have a javascript app that crawls through all Teams in a organization and extract the number of messages from all channels in all the teams. It works wonderfully in that it return the correct amount of messages, the problem is that when the app try to fetch a message from a channel where no one have made a message in the channel there is an HTTP error with the ErrorCode 403 (forbidden). Even though the app is successful in that it delivers on what it is supposed to do, I can't have an application that sends 50 angry, red messages every time it makes a http call.

The call I am using is the following https://graph.microsoft.com/beta/teams/{teamID}/channels/{channelID}/messages

Does anyone know if this is solvable? If not is it possible to check if a channel is empty? And if that is not an option; is there anyone to hide those dirty error messages from the console?

Edit #1

To call to the api I used:

  let header = new Headers();
  header.append("Authorization", "Bearer " + accessToken);
  header.append("Content-Type", "application/json");

  fetch("https://graph.microsoft.com/beta/teams/232808c2-d500-47b0-9ead-e238c5e2ab95/channels/19:[email protected]/messages", {method:"GET", headers: header})

Edit #2

I response object seems to be correct:

  {  
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#teams('90baabba-1b5e-471c-a163-8a9b4b680de7')/channels('19%3A01c741f599e547f0b9b38296283b7fec%40thread.skype')/messages",
    "@odata.count": 0,
    "value": [] 
  }

The problem is that in when I look in Google Chrome > Dev tools > Console, the fetch still displays the error:

GET https://graph.microsoft.com/beta/teams/4f460179-4691-42e5-8677-9101dcdb65fe/channels/19:[email protected]/messages 403 (Forbidden)

And when I console log the error it just displays as:

error: {code: "Forbidden", message: "Forbidden", innerError: {…}}
1
We, tried repro this issue at our end and couldn't see 403 error, Cloud you please post your request body? - Manish-MSFT
@Manish-MSFT I have added the call I am making to the Graph API. The request body is empty since the documentation documentation states "Do not supply a request body for this method." - Grelnog
@Grelnog- Yes, your request is correct but we don't see that happening at our end. Can you please check if your bearer token is correct and has required permissions. I don't see any other issue apart from that. - Manish-MSFT
@Manish-MSFT Ah I see! I have updated my question. - Grelnog
Did you try using Postman? Let us know here if you still get 403. - Manish-MSFT

1 Answers

1
votes

Only team members are allowed to read messages. Admins can do team management i.e. CRUD operations on teams, channels, tabs etc. They however cannot read messages. This is intentional and we do not have plans to change this in near future