Search code examples
marklogic

MarkLogic REST API tutorial unable to run xquery


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

Solution

  • 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:

    • Omit the $ character at the beginning of the command. This is the Unix default prompt, equivalent to > in Windows.
    • For aesthetic reasons, long example command lines are broken into multiple lines using the Unix line continuation character ''. Remove the line continuation characters and place the entire command on one line, or replace the line continuation characters with the Windows equivalent, '^'.
    • Replace arguments enclosed in single quotes (') with double quotes ("). If the single-quoted string contains embedded double quotes, escape the inner quotes.
    • Escape any unescaped characters that have special meaning to the Windows command interpreter.