Request Body Format is Invalid when posting from CURL

Hello

I am writing some manual routines in the shell (bash) to test and perform manualish tasks that don’t require a lot of bells and whistles, and to prove some concepts for when I do it for real in Python.

Using CURL (7.21.0, Linux), I can perform GET requests to the paper API just fine, and process the returned JSON just fine.

However when trying to make POST requests, I am running into “request body format is invalid” messages no matter what i do.

Can anyone explain what might be going on, or what I need to do to fix it?

Here is an example:

CURL command:

curl -gqsS --retry 1 -m 3 --proto =https -o - \
-H "APCA-API-KEY-ID: $APCA_API_KEY_ID" \
-H "APCA-API-SECRET-KEY: $APCA_API_SECRET_KEY" \
-X POST -H "Content-Type: application/json; charset=UTF-8" \
--data-binary @/tmp/order \
"https://paper-api.alpaca.markets/v2/orders"

Alternatives I have tried:

  • Content-Type: application/x-www-form-urlencoded.
  • Passing the JSON via STDIN
  • Pretty-printed JSON
  • JSON on one line with spaces
  • JSON with no spaces at all (this example)
  • Zero, one or two new lines before the JSON
  • zero or one newlines after.

JSON from /tmp/order:

{"symbol":"PSEC","qty":"10","side":"buy","type":"limit","time_in_force":"day","extended_hours":"false","order_class":"simple","limit_price":"4.82"}

I have tried it with and without the quotes around the quantity, since the spec asks for a “string <int>”, whatever that is.

Thanks for any pointers!

How about unquote “false” for extended_hourse?

Unbelievable, why didn’t I see that?

SOLVED. Thank you.

Actually, I think I know why I didn’t see it.
I was focused more on “body format”, like the message said, than I was on an
element with an invalid value.

I would have expected to see a “Body parameter has invalid value” message. It
never occurred to me that a body format error would be thrown for a
parameter type error.

Bad mental assumption on my part, although a more specific error here would be
appreciated eventually.