Microsoft Graph API get email message attachments by RRS feed

  • Question

  • Hi, 

    I'm trying to get an email message attachments via Microsoft Graph API with PowerShell.

    I'm already connected and collected messages with code

    $messages = Invoke-RestMethod -Method Get -Headers @{Authorization = "Bearer $accesstoken"; 'Content-Type' = 'application/json'} -Uri ""
    foreach ($message in $messages.value) {
    if ($message.hasAttachments) {
    $encodedMessageId = [System.Web.HttpUtility]::UrlEncode($ 
    $attachments = Invoke-RestMethod -Method Get -Headers @{Authorization = "Bearer $accesstoken"; 'Content-Type' = 'application/json'} -Uri ""+$encodedMessageId+"/attachments"

    but see an exception 

    Invoke-RestMethod : A positional parameter cannot be found that accepts argument '+A....AA%3d+/attachments'.
    At 111.ps1:14 char:18
    + ... tachments = Invoke-RestMethod -Method Get -Headers @{Authorization =  ...
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Invoke-RestMethod], ParameterBindingException
        + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

    in examples I see what looks like AAMkADA1M-zAAA= but mine looks like  


    what I'm doing wrong?

    Thursday, October 19, 2017 4:19 PM

All replies

  • Would you mind sharing the code you used to collect the messages? I'm having some trouble figuring that out. 
    Thursday, September 12, 2019 9:41 PM