I am trying to send JSON via a POST request from eXist-db to an API using the eXPath HTTP-Module, but I'm always recieving the following Error:
exerr:ERROR Error serializing the body content
My XQuery looks like:
xquery version "3.1";
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";
let $payload := map {
"name": "testuser",
"role": "user"
}
return
hc:send-request(
<hc:request method='post'>
<hc:body media-type="application/json"/>
</hc:request>,
'https://reqres.in/api/users',
serialize($payload, <output:serialization-parameters>
<output:method>json</output:method>
</output:serialization-parameters>)
)[2] => util:base64-decode() => parse-json()
Expected Output (tested via Postman):
{
"name": "testuser",
"id": "820",
"createdAt": "2021-06-03T05:50:32.049Z"
}
How do i serialize content to JSON and send it via a POST-request from eXist-db? The solution prompted here is not working for me.