I have this curl command:
curl -X POST https://api.nexmo.com/v0.1/messages -H 'Authorization: Bearer elided' -H 'Content-Type: application/json' -H 'Accept: application/json' -d $'{ "from": { "type": "whatsapp", "number": "elided" }, "to": { "type": "whatsapp", "number": "elided" }, "message": { "content": { "type": "text", "text": "This is a WhatsApp Message sent with curl" } } }'
(copied the structure from here: https://github.com/Nexmo/nexmo-curl-code-snippets/blob/master/messages/whatsapp/send-text.sh)
I have tested this and it works (I used the actual JWT and phone numbers in my tests, but I've elided them from the above snippet). I've executed it on the command line, and I've used Run within Mathematica.
I would like to use the Mathematica functions intended for web communication. I tried using URLExecute with a HTTPRequest that looks like this:
HTTPRequest[
"https://api.nexmo.com/v0.1/messages",
<|
Method->"POST",
"Headers"->
{
"Authorization"->"Bearer "<>JWT,
"Accept"->"application/json"
},
"ContentType"->"JSON",
"Body"-> "{ "from":{ "type":"whatsapp", "number":"elided" }, "to":{ "type":"whatsapp", "number":"elided" }, "message":{ "content":{ "type":"text", "text":"This was sent from MMA" } } }"
|>
]
This fails with a bad request error (400).
First question: Why is this HTTPRequest not a correct transformation of the curl command to a Mathematica expression?
Second question: Are there general guidelines for how to do such transformations correctly?
Third question: Does Mathematica offer any sort of inspection or debugging capabilities that would allow me to see what actual POST is generated by the URLExecute?