21.8. Nodes

Create node

Figure 21.13. Final Graph

Example request

  • POST http://localhost:7474/db/data/node
  • Accept: application/json; charset=UTF-8

Example response

  • 201: Created
  • Content-Type: application/json; charset=UTF-8
  • Location: http://localhost:7474/db/data/node/8
{
  "extensions" : { },
  "labels" : "http://localhost:7474/db/data/node/8/labels",
  "outgoing_relationships" : "http://localhost:7474/db/data/node/8/relationships/out",
  "all_typed_relationships" : "http://localhost:7474/db/data/node/8/relationships/all/{-list|&|types}",
  "traverse" : "http://localhost:7474/db/data/node/8/traverse/{returnType}",
  "property" : "http://localhost:7474/db/data/node/8/properties/{key}",
  "self" : "http://localhost:7474/db/data/node/8",
  "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/8/relationships/out/{-list|&|types}",
  "properties" : "http://localhost:7474/db/data/node/8/properties",
  "incoming_relationships" : "http://localhost:7474/db/data/node/8/relationships/in",
  "create_relationship" : "http://localhost:7474/db/data/node/8/relationships",
  "paged_traverse" : "http://localhost:7474/db/data/node/8/paged/traverse/{returnType}{?pageSize,leaseTime}",
  "all_relationships" : "http://localhost:7474/db/data/node/8/relationships/all",
  "incoming_typed_relationships" : "http://localhost:7474/db/data/node/8/relationships/in/{-list|&|types}",
  "metadata" : {
    "id" : 8,
    "labels" : [ ]
  },
  "data" : { }
}

Create node with properties

Figure 21.14. Final Graph

Example request

  • POST http://localhost:7474/db/data/node
  • Accept: application/json; charset=UTF-8
  • Content-Type: application/json
{
  "foo" : "bar"
}

Example response

  • 201: Created
  • Content-Length: 1209
  • Content-Type: application/json; charset=UTF-8
  • Location: http://localhost:7474/db/data/node/4
{
  "extensions" : { },
  "labels" : "http://localhost:7474/db/data/node/4/labels",
  "outgoing_relationships" : "http://localhost:7474/db/data/node/4/relationships/out",
  "all_typed_relationships" : "http://localhost:7474/db/data/node/4/relationships/all/{-list|&|types}",
  "traverse" : "http://localhost:7474/db/data/node/4/traverse/{returnType}",
  "property" : "http://localhost:7474/db/data/node/4/properties/{key}",
  "self" : "http://localhost:7474/db/data/node/4",
  "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/4/relationships/out/{-list|&|types}",
  "properties" : "http://localhost:7474/db/data/node/4/properties",
  "incoming_relationships" : "http://localhost:7474/db/data/node/4/relationships/in",
  "create_relationship" : "http://localhost:7474/db/data/node/4/relationships",
  "paged_traverse" : "http://localhost:7474/db/data/node/4/paged/traverse/{returnType}{?pageSize,leaseTime}",
  "all_relationships" : "http://localhost:7474/db/data/node/4/relationships/all",
  "incoming_typed_relationships" : "http://localhost:7474/db/data/node/4/relationships/in/{-list|&|types}",
  "metadata" : {
    "id" : 4,
    "labels" : [ ]
  },
  "data" : {
    "foo" : "bar"
  }
}

Get node

Note that the response contains URI/templates for the available operations for getting properties and relationships.

Figure 21.15. Final Graph

Example request

  • GET http://localhost:7474/db/data/node/10075
  • Accept: application/json; charset=UTF-8

Example response

  • 200: OK
  • Content-Type: application/json; charset=UTF-8
{
  "extensions" : { },
  "labels" : "http://localhost:7474/db/data/node/10075/labels",
  "outgoing_relationships" : "http://localhost:7474/db/data/node/10075/relationships/out",
  "all_typed_relationships" : "http://localhost:7474/db/data/node/10075/relationships/all/{-list|&|types}",
  "traverse" : "http://localhost:7474/db/data/node/10075/traverse/{returnType}",
  "property" : "http://localhost:7474/db/data/node/10075/properties/{key}",
  "self" : "http://localhost:7474/db/data/node/10075",
  "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/10075/relationships/out/{-list|&|types}",
  "properties" : "http://localhost:7474/db/data/node/10075/properties",
  "incoming_relationships" : "http://localhost:7474/db/data/node/10075/relationships/in",
  "create_relationship" : "http://localhost:7474/db/data/node/10075/relationships",
  "paged_traverse" : "http://localhost:7474/db/data/node/10075/paged/traverse/{returnType}{?pageSize,leaseTime}",
  "all_relationships" : "http://localhost:7474/db/data/node/10075/relationships/all",
  "incoming_typed_relationships" : "http://localhost:7474/db/data/node/10075/relationships/in/{-list|&|types}",
  "metadata" : {
    "id" : 10075,
    "labels" : [ ]
  },
  "data" : { }
}

Get non-existent node

Figure 21.16. Final Graph

Example request

  • GET http://localhost:7474/db/data/node/1007900000
  • Accept: application/json; charset=UTF-8

Example response

  • 404: Not Found
  • Content-Type: application/json; charset=UTF-8
{
  "message": "Cannot find node with id [1007900000] in database.",
  "exception": "NodeNotFoundException",
  "fullname": "org.neo4j.server.rest.web.NodeNotFoundException",
  "stackTrace": [
    "org.neo4j.server.rest.web.DatabaseActions.node(DatabaseActions.java:174)",
    "org.neo4j.server.rest.web.DatabaseActions.getNode(DatabaseActions.java:219)",
    "org.neo4j.server.rest.web.RestfulGraphDatabase.getNode(RestfulGraphDatabase.java:279)",
    "java.lang.reflect.Method.invoke(Method.java:606)",
    "org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:139)",
    "org.neo4j.server.rest.web.CollectUserAgentFilter.doFilter(CollectUserAgentFilter.java:69)",
    "java.lang.Thread.run(Thread.java:745)"
  ],
  "cause": {
    "message": "Node 1007900000 not found",
    "errors": [
      {
        "message": "Node 1007900000 not found",
        "code": "Neo.ClientError.Statement.EntityNotFound"
      }
    ],
    "cause": {
      "message": "Unable to load NODE with id 1007900000.",
      "errors": [
        {
          "message": "Unable to load NODE with id 1007900000.",
          "code": "Neo.ClientError.Statement.EntityNotFound"
        }
      ],
      "exception": "EntityNotFoundException",
      "fullname": "org.neo4j.kernel.api.exceptions.EntityNotFoundException",
      "stackTrace": [
        "org.neo4j.kernel.impl.factory.GraphDatabaseFacade.getNodeById(GraphDatabaseFacade.java:226)",
        "org.neo4j.server.rest.web.DatabaseActions.node(DatabaseActions.java:170)",
        "org.neo4j.server.rest.web.DatabaseActions.getNode(DatabaseActions.java:219)",
        "org.neo4j.server.rest.web.RestfulGraphDatabase.getNode(RestfulGraphDatabase.java:279)",
        "java.lang.reflect.Method.invoke(Method.java:606)",
        "org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:139)",
        "org.neo4j.server.rest.web.CollectUserAgentFilter.doFilter(CollectUserAgentFilter.java:69)",
        "java.lang.Thread.run(Thread.java:745)"
      ]
    },
    "exception": "NotFoundException",
    "fullname": "org.neo4j.graphdb.NotFoundException",
    "stackTrace": [
      "org.neo4j.kernel.impl.factory.GraphDatabaseFacade.getNodeById(GraphDatabaseFacade.java:226)",
      "org.neo4j.server.rest.web.DatabaseActions.node(DatabaseActions.java:170)",
      "org.neo4j.server.rest.web.DatabaseActions.getNode(DatabaseActions.java:219)",
      "org.neo4j.server.rest.web.RestfulGraphDatabase.getNode(RestfulGraphDatabase.java:279)",
      "java.lang.reflect.Method.invoke(Method.java:606)",
      "org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:139)",
      "org.neo4j.server.rest.web.CollectUserAgentFilter.doFilter(CollectUserAgentFilter.java:69)",
      "java.lang.Thread.run(Thread.java:745)"
    ]
  },
  "errors": [
    {
      "message": "Cannot find node with id [1007900000] in database.",
      "code": "Neo.ClientError.Statement.EntityNotFound"
    }
  ]
}

Delete node

Figure 21.17. Final Graph

Example request

  • DELETE http://localhost:7474/db/data/node/5
  • Accept: application/json; charset=UTF-8

Example response

  • 204: No Content

Nodes with relationships cannot be deleted

The relationships on a node has to be deleted before the node can be deleted.

Figure 21.18. Final Graph

Example request

  • DELETE http://localhost:7474/db/data/node/12
  • Accept: application/json; charset=UTF-8

Example response

  • 409: Conflict
  • Content-Type: application/json; charset=UTF-8
{
  "message": "The node with id 12 cannot be deleted. Check that the node is orphaned before deletion.",
  "exception": "ConstraintViolationException",
  "fullname": "org.neo4j.graphdb.ConstraintViolationException",
  "stackTrace": [
    "org.neo4j.server.rest.web.DatabaseActions.deleteNode(DatabaseActions.java:228)",
    "org.neo4j.server.rest.web.RestfulGraphDatabase.deleteNode(RestfulGraphDatabase.java:293)",
    "java.lang.reflect.Method.invoke(Method.java:606)",
    "org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:139)",
    "org.neo4j.server.rest.web.CollectUserAgentFilter.doFilter(CollectUserAgentFilter.java:69)",
    "java.lang.Thread.run(Thread.java:745)"
  ],
  "errors": [
    {
      "message": "The node with id 12 cannot be deleted. Check that the node is orphaned before deletion.",
      "code": "Neo.ClientError.Schema.ConstraintViolation"
    }
  ]
}