Graph Api File upload Powershell Issue

Copper Contributor

Hi Folks

 

What am i missing? I want to upload a file to SharePoint Online library using PS and Graph API for some test purpose. 

 

I am able to create the AAD oAuth Token

I am able to access the site and it's lists

But when i try to upload the a file to a library, i always get a bad request. Here is the code snippet below:-

 

----------------------------------------------------

$path = "D:\Knowledge Base\MyFile.xlsx"

$fileName = "MyFile.xlsx"
$url = "https://graph.microsoft.com/v1.0/sites/$siteID/drive/items/$listId/$fileName/content"
$headers = @{'Authorization' = "Bearer $oAuthToken" }
Invoke-RestMethod -Uri $url -Headers $headers -Method Put -InFile $path -ContentType 'multipart/form-data'

-----------------------------------------

The above code throws error: Invoke-RestMethod : The remote server returned an error: (400) Bad Request.

 

Thanks

Ani

 

 

0 Replies