0
votes

MarkLogic version 8.0-4.2 on Windows 10

I'm sending a request to the /v1/eval endpoint to list the contents of a file system directory (xdmp:filesystem-directory) passing in the a directory path as a variable. The code works in the qconsole with xdmp:eval() however when using curl (see below) or powershell (using -Body with Invoke-RestMethod) I get the following error message when the external variable is accessed. The code I used is based on the example found at https://docs.marklogic.com/9.0/REST/POST/v1/eval which works as expected.

Response:

...
HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
...
{"errorResponse":{"statusCode":400, "status":"Bad Request",   "messageCode":"XDMP-EXTVAR", "message":"XDMP-EXTVAR: (err:XPDY0002) declare variable $dpath as xs:string external;  -- Undefined external variable fn:QName(\"\",\"dpath\")" ,"messageDetail":{"messageTitle":"Undefined external variable"}}}

Xquery example 1:

xquery=
xquery version "1.0-ml";
declare namespace dir="http://marklogic.com/xdmp/directory";
declare variable $dpath as xs:string external;
(string-join( fn:data(xdmp:filesystem-directory($dpath)//dir:pathname), ",") )
& 
vars=("dpath":"d:\wrk\markLogic\")

Xquery example 2:

xquery=
xquery version "1.0-ml";
declare namespace dir="http://marklogic.com/xdmp/directory";
declare variable $dpath as xs:string external;
($dpath)
& 
vars=("dpath":"abc")

Curl statement:

curl --anyauth --user user:password -X POST -i -d @./body.xqy  -H "Content-type: application/x-www-form-urlencoded"  -H "Accept: multipart/mixed; boundary=BOUNDARY"   http://localhost:8000/v1/eval
1
Fired the same code a Linux box running 8.0-4.2 same issue - Guy Yeates
I've now changed approach to send the finished version of the query without using external variables - Guy Yeates

1 Answers

1
votes

Use curly braces, instead of round parentheses:

vars={"dpath":"d:/wrk/markLogic/"}

You probably also need to escape characters like \ and &. Given the syntax, it probably follows JSON notation requirements.

HTH!