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?

3
  • Why Get-Item? I'd expect Get-Content filepath -raw Commented Nov 10, 2016 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. Commented Nov 10, 2016 at 16:54
  • 2
    Maybe see this Q for an example?stackoverflow.com/questions/22770213/… Commented Nov 10, 2016 at 17:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.