0

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 -rawbut 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?

JZ555
  • 617
  • 2
  • 7
  • 16
  • Why `Get-Item`? I'd expect `Get-Content filepath -raw` – wOxxOm Nov 10 '16 at 16:46
  • @wOxxOm I figured that we want to somehow send the file directly instead of reading its contents to a variable. But that is not how it works then? Sorry if this sounds dumb but I'm total noob when it comes to powershell scripts at this point. – JZ555 Nov 10 '16 at 16:54
  • 2
    Maybe see this Q for an example?http://stackoverflow.com/questions/22770213/using-powershell-invoke-restmethod-to-post-large-binary-multipart-form-data – sodawillow Nov 10 '16 at 17:09

0 Answers0