MarkLogic v1/transactions create by REST API

2019-07-18 16:03发布

I have been trying to create a transaction via the MarkLogic REST API (/v1/transactions) using the Developer guidance here: https://docs.marklogic.com/REST/POST/v1/transactions

When I try to call the transaction REST service to create a new transaction (I am using CURL), then I receive the following HTTP Response:

curl -X POST -d "" -i --anyauth --user user:password http://localhost:7010/v1/transactions

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Digest realm="public", ...
Content-type: application/xml
Server: MarkLogic
Content-Length: 211
Connection: Keep-Alive
Keep-Alive: timeout=5

HTTP/1.1 400 Bad Request
Content-type: application/xml
Server: MarkLogic
Content-Length: 316
Connection: Keep-Alive
Keep-Alive: timeout=5

<rapi:error xmlns:rapi="http://marklogic.com/rest-api">
  <rapi:status-code>400</rapi:status-code><rapi:status>Bad Request</rapi:status>
  <rapi:message-code>REST-INVALIDPARAM</rapi:message-code>
  <rapi:message>REST-INVALIDPARAM: (err:FOER0000) Invalid parameter: could not parse transaction id </rapi:message>
</rapi:error>

Interestingly, when I use POSTMAN within Chrome, I can create the transaction, but the response is different to that expected (It response with 200 status and with XML detailing the transaction, rather than a 303 response and the "Location" header set to the transaction ID).

Can anyone help me explain why this CURL statement is failing?

Cheers

1条回答
趁早两清
2楼-- · 2019-07-18 16:54

The problem is a curl "convenience" and not your request.

When you don't specify the Content-Type for a POST, curl "helpfully" defaults the Content-Type to application/x-www-form-urlencoded

The REST API processes a application/x-www-form-urlencoded POST as a GET because there is no payload, only parameters, which is why it looks like a bad request.

Try the same curl command but adding a -H 'Content-Type: text/plain' argument.

Hoping that helps

查看更多
登录 后发表回答