Begin and commit a transaction in one request

If there is no need to keep a transaction open across multiple HTTP requests, you can begin a transaction, execute statements, and commit within a single HTTP request.

Example request

  • POST http://localhost:7474/db/neo4j/tx/commit

  • Accept: application/json;charset=UTF-8

  • Content-Type: application/json

{
  "statements": [
    {
      "statement": "MATCH (n) WHERE id(n) = $nodeId RETURN n",
      "parameters": {
        "nodeId": 7
      }
    }
  ]
}

Example response

  • 200: OK

  • Content-Type: application/json;charset=utf-8

{
  "results" : [ {
    "columns" : [ "n" ],
    "data" : [ {
      "row" : [ { } ],
      "meta" : [ {
        "id" : 7,
        "type" : "node",
        "deleted" : false
      } ]
    } ]
  } ],
  "errors" : [ ]
}

It is also possible to send CALL IN TRANSACTION requests to this endpoint.

Example request

  • POST http://localhost:7474/db/neo4j/tx/commit

  • Accept: application/json;charset=UTF-8

  • Content-Type: application/json

{
  "statements": [
    {
      "statement": "UNWIND [4, 2, 1, 0] AS i CALL { WITH i CREATE ()} IN TRANSACTIONS OF 2 ROWS RETURN i"
    }
  ]
}

If you send multiple statements (at least one being CALL IN TRANSACTION), and one of the normal statements fails, the CALL IN TRANSACTION query will not be rolled back, while the others will. In the example below, the simple CREATE statements would be rolled back in case of failure, but the CALL IN TRANSACTION would not. The final node count would thus be 4.

Example request

  • POST http://localhost:7474/db/neo4j/tx/commit

  • Accept: application/json;charset=UTF-8

  • Content-Type: application/json

{
  "statements": [
    {
      "statement": "UNWIND [4, 2, 1, 0] AS i CALL { WITH i CREATE ()} IN TRANSACTIONS OF 2 ROWS RETURN i"
    },
    {
      "statement": "CREATE ()"
    },
    {
      "statement": "CREATE ()"
    }
  ]
}