We are in the same situation. Probably because of the outlook.office365.com REST Api shutting down and the Graph API being the default from now on:
How to retrieve contents of an itemAttachment via the Microsoft Graph API
https://learn.microsoft.com/nl-be/graph/api/attachment-get?view=graph-rest-1.0#request-2
Now, I hacked together a script to do this properly and it works. But (1) it requires a GUI input of the password every time the script starts up (for example after a power failure) and once logged in (2) the access token keeps expiring...
Invoke-RestMethod : {
"error": {
"code": "InvalidAuthenticationToken",
"message": "Access token has expired.",
"innerError": {
"request-id": "1c991403-ab46-4aec-a7a1-316dbdfb4eb8",
"date": "2019-01-16T12:29:50"
}
}
}
Now when you get into the documentation and start reading up on things like refreshing a token and such... It is just nuts! https://learn.microsoft.com/nl-be/graph/auth-v2-user
I have developed API interfacing for MailChimp which I completed in under ONE hour... (1) Generate API key in MailChimp, (2) use that API key in your scripts and if needed (3) revoke key in MailChimp in case of an emergency (DONE).
This token M$ BS is really mind blowing. As far as I understand, you either have to use an admin PowerShell tool to change tokens to 90 days default duration (but server wide as I understand instead of app wide?) or automatically refresh the access token every 5 minutes in your script.
That's why I'm now looking into using PSMSGraph which does all of that for you apparently: https://psmsgraph.readthedocs.io/en/latest/
If you would get it working properly before I do, please share your code. As my current solution requires manual password entry (which I don't see how I could make this headless by the way) and stops working after an hour, because of the expiring token.
I'm sure there is a good (security) reason to have this access token way of doing things, but if the MailChimp way of generating lifetime tokens JUST WORKS... Than I fail to see why this access token complexity thing with Microsoft Graph API is needed in the first place.