Designing and Documenting an API with Swagger: curl commands don't work


whenever I try to execute the curl testing commands, like this one,

curl --header "Content-Type: application/json" -d "@new_order.json" http://localhost:3000/neworder

I always get an error in my console :

Invoke-WebRequest : A positional parameter cannot be found that accepts argument 'Content-Type: application/json'.
At line:1 char:1
+ curl --header "Content-Type: application/json" -d "@new_order.json" h ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Does anyone know the root cause and how I can fix it ?

Thank you,
Johan (Belgium)

Never mind.

I found the solution myself . It seems that my default Visual Studio Code installation is not using the Curl you installed but a CmdLet called Invoke-WebRequest .

I needed to execute first :

Remove-item alias:curl

And the rerun the commands.

Now it works !


1 Like

I was getting the same thing, I ended up executing the command in Git BASH and it worked

I am however having an issue getting the /delete/{id} endpoint to work. I dont get any error code, but the order just doesnt delete. I tried also doing it with the solution code provided and it still did not work.

I am having the same issue! In the terminal it says ‘deleting order’ and ‘success’, but after refreshing the page the order does not delete. If you have solved this problem, please let me know. Thanks!