I was trying out REST API interface provided by MarkLogic to run adhoc query (.xqy) files that was provided to me. I was following this guide by MarkLogic but I kept encountering 400 Bad Request:
HTTP/1.1 400 Bad Request
Content-Type: text/html; charset=utf-8
Server: MarkLogic
Content-Length: 982
Connection: Keep-Alive
Keep-Alive: timeout=5
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>400 Bad Request</title>
<meta name="robots" content="noindex,nofollow"/>
<link rel="stylesheet" href="/error.css"/>
</head>
<body>
<span class="error">
<h1>400 Bad Request</h1>
<dl>
<dt>XDMP-JSONCHAR: Unexpected character 'h' in JSON at line 1 char 8</dt>
<dd></dd>
<dt>in /eval [1.0-ml]</dt>
<dd></dd>
</dl>
</span>
</body>
</html>
This was the curl command used in Windows powershell:
curl --anyauth --user admin:admin -X POST -i `
-H "Content-type: application/x-www-form-urlencoded" `
-H "Accept: multipart/mixed" `
--data-urlencode xquery@./concat2.xqy `
--data-urlencode vars='{"word1":"hello","word2":"world"}' `
http://localhost:8000/LATEST/eval
You may need to modify the example if using Windows. Per the comment at the top of the example:
Windows users, see Modifying the Example Commands for Windows
https://docs.marklogic.com/guide/rest-dev/intro#id_75672
The command line examples in this guide use Unix command line syntax, usable from either a Unix or Cygwin command line. If you are the Windows command interpreter, Cmd.exe, use the following guidelines to modify the example commands for your environment: