简体   繁体   中英

How to post XQuery code to MarkLogic using cURL from Ubuntu?

I am using Ubuntu machine. I am doing POST call using curl command and sending xquery code as --data in string format. In response I am getting below error:

xdmp:database()HTTP/1.1 500 REST-UNSUPPORTEDPARAM: (rest:UNSUPPORTEDPARAM) Endpoint does not support query parameter: xdmp:database()

Below is the complete curl command

curl -v --digest -u username --request POST "http://host:port/qconsole/endpoints/evaler.xqy?dbid=someid&querytype=xquery&action=eval" --data "xdmp:database()"

In the above command Basically I am trying to run xquery code on the targeted machine (host:port/endpoints/evaler.xqy)

Is this the right way to pass xquery code?

Update:

I am using ML 7

After passing the headers I am able to run the XQuery code but facing one more issue.

When I am passing "xdmp:database()" as data It's working fine (see the below command), in the response I am getting database ID.

 curl -v --digest -uusername --data "xdmp:database()" --header "Content-type:text/x-www-form-urlencoded" --header "Accept: multipart/mixed; boundary=BOUNDARY" --request POST "http://host:port/qconsole/endpoints/evaler.xqy?dbid=dbid&querytype=xquery&action=eval"

When I tried with passing "let $x := 10 return $x" as data (As given in below command) I am getting

x: undefined variable

even not asking for password!!

 curl -v --digest -u username --data "let $x := 10 return $x" --header "Content-type:text/x-www-form-urlencoded" --header "Accept: multipart/mixed; boundary=BOUNDARY" --request POST "http://host:port/qconsole/endpoints/evaler.xqy?dbid=dbid&querytype=xquery&action=eval"

Not able to figure it out, What I am doing wrong.

Please help.

Here is some example bash that uses cURL to eval JavaScript from stdin. (Changing to XQuery is just a matter of changing the parameter name.)

#!/usr/bin/env bash

# Pipes stdin as the JavaScript body of a REST Client API eval request
#
# Usage:
#   cat cat mycode.js | awk … | curl … @-
#   pbpaste | awk … | curl … @-

awk '{print "javascript="$0}' | curl http://localhost:8000/v1/eval --digest -u "$USER":"$PASS" -X POST -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: multipart/mixed' -d @-

You'll need to set up your $USER and $PASS variables appropriately.

I think you are better off using the REST endpoint for evaluation:

http://docs.marklogic.com/REST/POST/v1/eval

HTH!

If using MarkLogic 8+, then you should use /v1/eval, as @grtjn noted. Since you used the marklogic-7 tag, it looks like you're on ML7.

The top choice, regardless of version, would be to create a REST API extension for whatever this code is supposed to do, assuming you're not trying to support arbitrary XQuery execution. If you are, you could create an extension that mimics what /v1/eval does. Better yet, upgrade to ML8 if you can and use /v1/eval itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM