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 !



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!

Same, the order with an id of 002 is still there after executing the command given

Tbh I found this lesson pretty hard to follow once we finished with the Swagger UI, and ended up largely just comparing the solution to what I had at each stage - even something as basic as “copy paste your api file into the project directory” isn’t ever actually mentioned (just a load of bumf about “look at the files that were generated - we’re not going to use any of them though lol”)

Neither surprised nor impressed to find that, yet again, the end result of a bunch of headscratching and forum troubleshooting leads to a final result that still doesn’t do what it says anyway

1 Like

I did some researching and after following their instructions and updating server.js file, the DELETE command ACTUALLY deletes the information:

const express = require(‘express’);
const server = express();
const fs = require(‘fs’);

// Function to read orders from the file and parse it as JSON
function readOrdersFromFile() {
const data = fs.readFileSync(‘orders.json’, ‘utf8’);
return JSON.parse(data);

let orderData = readOrdersFromFile();
server.set(‘port’, process.env.PORT || 3000);

response.send(‘Welcome to our simple online order managing web app!’);

});‘/neworder’, express.json(), (request,response)=>{
fs.writeFileSync(‘orders.json’, JSON.stringify(orderData));

server.put(‘/update/:id’, express.text({type: ‘/’}), (request,response)=>{
var items = orderData.orders

items.forEach(function(o) {
if ( =={
console.log(‘Modifying order!’)
o.state = request.body;

fs.writeFileSync(‘orders.json’, JSON.stringify(orderData));


server.delete(‘/delete/:id’, (request, response) => {
const orderId =;
const orderIndex = orderData.orders.findIndex((o) => === orderId);

  if (orderIndex !== -1) {
    // Remove the order from the orders array using splice
    orderData.orders.splice(orderIndex, 1);

    // Write the updated orderData back to the file
    fs.writeFileSync('orders.json', JSON.stringify(orderData));

    console.log('Deleting order!');
  } else {
    console.log('Order not found!');
    response.status(404).send("Order not found!");

console.log(‘Express server started at port 3000’);

1 Like

Using the original solution code, the orders.json file does delete the order, it’s just the /orders/ path does not reflect this. If you restart the server, the change takes place. Not exactly sure why this only occurs for the DELETE path and not the PUT path. Might it have to do with the middleware (or lack there of in the DELETE path)?

1 Like