Reputation: 21
Currently i am using the Transactional HTTP endpoint to delete all the nodes and the relations. I am able to do it using the browser. But when i do the same the statement is not getting committed. Below is the way i am trying to achieve it.
URI: http://xyz:7479/db/data/transaction
Method: POST Content-Type: application/json
{ "statements" : [ { "statement" : "MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r" } ] }
Response: {"commit":"http://xyz:7479/db/data/transaction/172/commit","results":[{"columns":[],"data":[]}],"transaction":{"expires":"Mon, 15 Sep 2014 14:15:31 +0000"},"errors":[]}
Can you please let me know whether i am doing it right ? and why the nodes are not getting deleted ? Or is there any other alternative way.
Thanks in advance.
Upvotes: 0
Views: 153
Reputation: 12035
From what it looks like you are trying to delete the nodes using transactional endpoint. This is ok, but you have to commit the transaction in order for the changes to take effect. The commit URL is send back to you with the response (http://xyz:7479/db/data/transaction/172/commit
in your example). It is different for each transaction, so you have to issue a request with the exact same URL which was send back to you.
You can avoid sending the second request to commit the transaction just by adding /commit
to your original URL:
http://xyz:7479/db/data/transaction/commit
This will cause the transaction to start and commit within single request. You can read about it in the manual.
EDIT: As mentioned by others the endpoint described below is DEPRECATED:
Having said that, the transaction is usually only for complex use cases (with at least two queries when one depends on the other). In your example there seem to be no need for a transaction. You can use plain old /db/data/cypher
endpoint as described here.
Your request body could look like this:
{
"query" : "MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r",
"params" : {}
}
Just remember to add Accept
and Content-Type
headers.
Upvotes: 1
Reputation: 20185
As mentionned by @Maciej, the uri should finish with /commit.
BTW the body is not right, this one is for the deprecated cypher endpoint.
It should contain something similar to this :
{ "statements": [ {"statement": "MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE r,n" } ] }
Please refer to the documentation :
Upvotes: 1