Here's the cURL request that should work according to the example in API's documentation:
curl
-X POST
-F "url=http://example.com/myjs.min.js"
-F "file=@C:\website\js\myjs.min.js"
https://restApi/endPoint
This is what I've tried but it didn't work (--> 400 Bad Request):
$uri = 'https://restApi/endPoint'
$file = Get-Item C:\website\js\myjs.min.js
$body = @{
url = 'http://example.com/myjs.min.js'
file = $file
}
Invoke-RestMethod -Method Post -Uri $uri -Body $body
What am I missing/doing wrong here? I'm assuming it's the part where I assign the file to the $body
but I don't know how it should be fixed.
Edit
Changed $file = Get-Content C:\website\js\myjs.min.js -raw
but still doesn't work. Also took a little closer look to response I get back from the server and it says the following:
No file present, please ensure that the file was posted with parameter name "file".
But the "file" is set in the body, so why it is complaining?