question

VarunAggarwal-9388 avatar image
0 Votes"
VarunAggarwal-9388 asked

Download ODB shared file

I am trying to develop a process which can download the files from ODB which are shared by user using the "Share" feature in office application like word, excel and powerpoint.

When a file is shared an email is sent to the person with whom the file is shared. The Url in the email is

"https://tenant-my.sharepoint.com/:w:/g/personal/tuser1_tenant_onmicrosoft_com/EX_7Bb_h4kdBvWht8sF5l9UBEkQOJg2rnDSXG_gDhkmZmQ?email=tuser2%40tenant.onmicrosoft.com&e=4%3apRWJGC&at=9"

The code i am using is

$Norma1izedURL = [System.Web.HttpUtility]::UrlDecode($Source)
$Bytes = [System.Text.Encoding]::UTF8.GetBytes($Norma1izedURL)
$EncodedText =[Convert]::ToBase64String($Bytes)
$EncodedText = "u!" + $EncodedText.TrimEnd('=').Replace('/','_').Replace('+','-')
$SharedDriveItem = "https://graph.microsoft.com/v1.0/shares/" + $EncodedText + "/driveitem"
$DownloadURL = Invoke-Restmethod -method Get -Headers @{'Authorization' = "Bearer $($Authresult.accesstoken)"} -Uri $SharedDriveItem

This fails with the error Invoke-Restmethod : The remote server returned an error: (400) Bad Request. At line:1 char:1 + Invoke-Restmethod -method Get -Headers @{'Authorization' = "Bearer $( ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

I am using an azure app with application permissions File.Read.All

i have searched a lot but could not find anything with similar issue... any pointers would be of great help

microsoft-graph-sdk
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

0 Answers