# Can't get a POST URL working with HTTPRequest [duplicate]

I'm puzzled by the syntax of building a URL with HTTPRequest. I can build a URL POST request with postman and that works perfectly. The HTTP code that is build with Postman is:

Host: myhost Accept: application/json

X-API-Version: 200

Content-Type: application/json

Cache-Control: no-cache

Postman-Token: 0408e579-7571-fd08-fa7c-4bf16ea70a3d

{

}

With Mathematica 11.1.1.0 on Windows 10 I try:

header = "Headers" -> {"Accept" -> "application/json",
"X-API-Version" -> "200", "Content-Type" -> "application/json"}

gettoken =
HTTPRequest[


URLRead[gettoken]["Body"]


Output:

"{\"errorSource\":null,\"nestedErrors\":[],\"details\":\"The JSON \ sent in the request is malformed and cannot be parsed. There is an \ error on line 1 near column 0.\",\"recommendedActions\":[\"Correct \ the malformed JSON and try the request \ again.\"],\"data\":{},\"errorCode\":\"MALFORMED_JSON\",\"message\":\"\ Malformed JSON cannot be parsed.\"}"

So it seems that the JSON format is wrong but I can't find a way to see how it's build. When I use the token generated through Postman I can build valid GET requests so that works perfectly fine.

Any thoughts?

• You need to ExportString the body to Json. – Kuba May 15 '17 at 20:23
• – Kuba May 15 '17 at 20:27
• @Kuba, I wish I posted this question before :). Thanks! I don't find this obvious reading through the documentation. – Lou May 15 '17 at 20:37
• I'm glad it works. I have marked it a duplicate because both are in essence about correct http request syntax. Let me know if you disagree. – Kuba May 15 '17 at 20:45
• @Kuba No problem. I did already see that post but even then it didn't sink in :).. – Lou May 16 '17 at 20:49

"Body" ->