none
Why when using PowerShell to get Teams Messages fails with UnknownError, but Graph Explorer works? RRS feed

  • Question

  • I use PowerShell for calling Graph via Invoke-RestMethod, which generally works very well using an App ID and Secret to get the Access Token (IDs below are fake)

    If I use the following URI, it works in both PowerShell and Graph Explorer:

    $URI = 'https://graph.microsoft.com/beta/teams/cUpX2eyd-8740-mndi-fhf6sdfgJ7CUXJbgk/channels/RDJY0i4RfoZSijwuwCqXyrRCLq05eDRU1GP4ocJHfxFOEhGTZw

    However, if I add "messages" to the URI, PowerShell fails, but Graph Explorer returns the messages. The App does have the right API permissions (Group.ReadWrite.All)

    $URI = 'https://graph.microsoft.com/beta/teams/cUpX2eyd-8740-mndi-fhf6-aSHJ7CUXJbgk/channels/RDJY0i4RfoZSijwuwCqXyrRCLq05eDRU1GP4ocJHfxFOEhGTZw/messages'

    PS C:\SharedData\GIT Projects\GRAPH> $Request = Invoke-RestMethod -Uri $URI -Headers $Header -Method get -ContentType "application/json"
    Invoke-RestMethod : {
      "error": {
        "code": "UnknownError",
        "message": "",
        "innerError": {
          "request-id": "65avdf89-w3t4-aw3r-asdgf-hasdfg6asdfgj",
          "date": "2020-05-13T03:15:15"
        }
      }
    }
    At line:1 char:12
    + $Request = Invoke-RestMethod -Uri $URI -Headers $Header -Method get - ...
    +            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
        + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand


    Is there a reason why this fails? Is there a way of getting it to work?

    Thanks

    Wednesday, May 13, 2020 4:12 AM