cURL and Qt JSON formatting submit order issue

Developing order entry and I’m always getting code 400 , msg: “request body format is invalid”.

Here’s my full curl command and JSON order string (windows):

curl --request POST -H “Content-Type: application/json” -H “APCA-API-KEY-ID: BLAH” -H “APCA-API-SECRET-KEY: BLAH/BLAH” -d “{“symb”:“AAPL”,“qty”:“1”,“side”:“buy”,“type”:“market”,“time_in_force”:“gtc”}” https://paper-api.alpaca.markets/v2/orders

I’ve gotten several other GET requests working fine. Also tried diligently with Qt. Was successful with the python SDK, but couldn’t dump the actual POST command that goes out.

Does anything obviously stand out as wrong?

Thanks for any help in advanced,

Josh

Try single quotes to quote json body in your curl example?

I’ve tried single quotes, double quotes, triple quotes, delimited quotes , unlimited quotes and every other kind of quote there is… I tried the python sdk source which got me further into construction the POST message, but the debugger doesn’t step into Requests. I even switched to a mac computer and tried everything again.

On to wireshark… unless someone could test out curl on their computer?

@josh_t, I’m just getting started with the API, and your question is a top result for the search “site:alpaca.markets curl”. It’s not very helpful that you did not use code-block for your command, so your copy-pasting your command requires editing to change the quotes.

If I change the quotes to the correct ones I get the error {"code":40010001,"message":"symbol is required"}, meaning you used symb where symbol was required in JSON. Here’s a working example, which hopefully the future readers can copy-paste while using their own variables.

EP='https://paper-api.alpaca.markets'
API_KEY="redacted"
API_SECRET="redacted"

curl --request POST \
  -H "Content-Type: application/json" \
  -H "APCA-API-KEY-ID: $API_KEY" \
  -H "APCA-API-SECRET-KEY: $API_SECRET" \
  -d '{"symbol":"AAPL","qty":"1","side":"buy","type":"market","time_in_force":"gtc"}' \
  "$EP/v2/orders"

Thanks for your example. It worked like a charm for me.
Best, Ed M

Note that -d ‘{}’ won’t work on Windows. It has to be -d “{}” and the inner double quotes have to be escaped.