Closed hidden-69 closed 2 years ago
When I add the attachment, it returns a 404 bad request, when I remove the attachment part it works fine. $Request=@" { "Message": { "Subject": $(Escape-StringToJson $Subject), "Body": { "ContentType": "HTML", "Content": $(Escape-StringToJson $Message) }, "ToRecipients": [ { "EmailAddress": { "Address": "$Recipient" } } ], "attachments": [ { "@odata.type": "#microsoft.graph.fileAttachment", "name": "attachment.txt", "contentType": "text/plain", "contentBytes": "SGVsbG8gV29ybGQh" } ] }, "SaveToSentItems": "$(if($SaveToSentItems){"true"}else{"false"})" } "@
Also, any idea why this doesn't work with a access token and does work with a app registration in Graph Explorer Developer?
$url="https://graph.microsoft.com/beta/me/mailFolders/inbox/messageRules"
Invoke-RestMethod -UseBasicParsing -Uri $Url -Method GET -Headers @{Authorization = "Bearer $($attributes.EXO)"} -Debug
VERBOSE: GET https://graph.microsoft.com/beta/me/mailFolders/inbox/messageRules with 0-byte payload
Invoke-RestMethod : The remote server returned an error: (401) Unauthorized.
At line:5 char:9
+ Invoke-RestMethod -UseBasicParsing -Uri $Url -Method GET -Hea ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Or this, any help would be appreciated :)
`$headers = @{ "Authorization" = "Bearer $($attributes.EXO)" "Accept" = "gzip, deflate, br" "Accept-Encoding" = "gzip, deflate, br" "Accept-Language" = "en-US,en;q=0.9" }
$url="https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messagerules"
Invoke-RestMethod -UseBasicParsing -Uri $Url -Method GET -Headers $headers
`
https://graph.microsoft.com requires that the client you are using has permissions to the API you're calling. You can check the scp claim from the access token to see the permissions with Read-AADIntAccessToken
or at https://aka.ms/JWT
What comes to sending attachments, I haven't tried that in years so can't tell what's wrong in your code. Try to double-check the attribute names and structure (should the first letter be capital etc.).
Any idea on how to accomplish this? I can't get it to work with access or refresh tokens, only with a registered app registration...