Reputation: 722
I am trying to write the below curl command against MarkLogic server :-
curl --digest -u "${USERNAME}:${PASSWORD}" -k -X POST "${URLCALL}" -H "Content-Type: application/json" -H "cache-control: no-cache" -H "Accept: text/csv" -d@"{$SELECTQUERY}"
But the above command is not working for me. The error i am getting is :
Warning: Couldn't read data from file "{select count(*) from
Warning: db.table1}", this makes an empty POST.
where in :
USERNAME=admin
PASSWORD=admin
URLCALL="https://localhost:8010/v1/rows"
SELECTQUERY="select count(*) from db.table1"
I am trying to execute this curl and run the SQL query inside SELECTQUERY
variable in my MarkLogic server and I want the count from this query to be sent to a variable also. How can I achieve it?
Upvotes: 0
Views: 4954
Reputation: 66783
For the curl data parameter (-d
or --data
), if you are setting a string and not a reference to a file path, then remove the @
.
And if you are sending over SQL statements, then change the Content-type
from application/json
to application/sql
https://docs.marklogic.com/REST/POST/v1/rows
Content-type
The MIME type of the request body. Allowed values:
application/json
for an Optic query serialized as an AST (Abstract Syntax Tree) in JSON formatapplication/vnd.marklogic.querydsl+javascript
for an Optic query represented in JavaScript syntaxapplication/sql
for an SQL SELECT statementapplication/sparql-query
for a SPARQL SELECT statementYou would want to use:
curl --digest -u "${USERNAME}:${PASSWORD}" -k -X POST "${URLCALL}" -H "Content-Type: application/sql" -H "cache-control: no-cache" -H "Accept: text/csv" -d "{$SELECTQUERY}"
Upvotes: 1