Hello everybody,
I am quite new in BOX api. Trying to accomplish simple task: Upload File, but using PowerShell instead of offered cURL.
# get Token from Registry and refresh if it's expired. It works well, as other requests, like get file info or create folder works fine
$TokenObj = Get-ItemProperty -Path $RegKey
if ((Get-Date) -ge [datetime]$TokenObj.expires_in){
$TokenObj = Register-BoxApp -AppName $AppName -ClientID $ClientID -ClientSecret $ClientSecret -Mode Refresh
}
# Prepare Header
$headers = @{Authorization = "Bearer $($TokenObj.access_token)"}
# This doesn't work
$json ="{ ""name"": ""test.txt"", ""parent"": {""id"": ""2***phone number removed for privacy***""}, ""file"": ""$(get-content C:\Temp\Box\test.txt -Enc Byte -raw)""}"
Invoke-RestMethod -Headers $headers -Uri 'https://upload.box.com/api/2.0/files/content' -Method Post -Body $JSON -ContentType "multipart/form-data"
# This doesn't work either
$json = '{"name": "test.txt", "parent":{"id":"0"}, "file":"C:\Temp\Box\test.txt"}'
Invoke-RestMethod -Headers $headers -Uri 'https://upload.box.com/api/2.0/files/content' -Method Post -Body $JSON -ContentType "multipart/form-data"
# This doesn't work either by Powershell design (Body and InFile self excluding parameters..)
$json = '{"name": "test.txt", "parent":{"id":"0"}}'
Invoke-RestMethod -Headers $headers -Uri 'https://upload.box.com/api/2.0/files/content' -Method Post -Body $JSON -InFile "C:\Temp\Box\test.txt" -ContentType "multipart/form-data"
Please Advice, if someone knows, HOW to upload file to Box using API in PowerShell?
