19.7. Nodes

Create node

Figure 19.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/111
{
  "extensions" : {
  },
  "outgoing_relationships" : "http://localhost:7474/db/data/node/111/relationships/out",
  "labels" : "http://localhost:7474/db/data/node/111/labels",
  "traverse" : "http://localhost:7474/db/data/node/111/traverse/{returnType}",
  "all_typed_relationships" : "http://localhost:7474/db/data/node/111/relationships/all/{-list|&|types}",
  "self" : "http://localhost:7474/db/data/node/111",
  "property" : "http://localhost:7474/db/data/node/111/properties/{key}",
  "properties" : "http://localhost:7474/db/data/node/111/properties",
  "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/111/relationships/out/{-list|&|types}",
  "incoming_relationships" : "http://localhost:7474/db/data/node/111/relationships/in",
  "create_relationship" : "http://localhost:7474/db/data/node/111/relationships",
  "paged_traverse" : "http://localhost:7474/db/data/node/111/paged/traverse/{returnType}{?pageSize,leaseTime}",
  "all_relationships" : "http://localhost:7474/db/data/node/111/relationships/all",
  "incoming_typed_relationships" : "http://localhost:7474/db/data/node/111/relationships/in/{-list|&|types}",
  "metadata" : {
    "id" : 111,
    "labels" : [ ]
  },
  "data" : {
  }
}

Create node with properties

Figure 19.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: 1239
  • Content-Type: application/json; charset=UTF-8
  • Location: http://localhost:7474/db/data/node/107
{
  "extensions" : {
  },
  "outgoing_relationships" : "http://localhost:7474/db/data/node/107/relationships/out",
  "labels" : "http://localhost:7474/db/data/node/107/labels",
  "traverse" : "http://localhost:7474/db/data/node/107/traverse/{returnType}",
  "all_typed_relationships" : "http://localhost:7474/db/data/node/107/relationships/all/{-list|&|types}",
  "self" : "http://localhost:7474/db/data/node/107",
  "property" : "http://localhost:7474/db/data/node/107/properties/{key}",
  "properties" : "http://localhost:7474/db/data/node/107/properties",
  "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/107/relationships/out/{-list|&|types}",
  "incoming_relationships" : "http://localhost:7474/db/data/node/107/relationships/in",
  "create_relationship" : "http://localhost:7474/db/data/node/107/relationships",
  "paged_traverse" : "http://localhost:7474/db/data/node/107/paged/traverse/{returnType}{?pageSize,leaseTime}",
  "all_relationships" : "http://localhost:7474/db/data/node/107/relationships/all",
  "incoming_typed_relationships" : "http://localhost:7474/db/data/node/107/relationships/in/{-list|&|types}",
  "metadata" : {
    "id" : 107,
    "labels" : [ ]
  },
  "data" : {
    "foo" : "bar"
  }
}

Get node

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

Figure 19.15. Final Graph

Example request

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

Example response

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

Get non-existent node

Figure 19.16. Final Graph

Example request

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

Example response

  • 404: Not Found
  • Content-Type: application/json; charset=UTF-8
{
  "message": "Cannot find node with id [28900000] in database.",
  "exception": "NodeNotFoundException",
  "fullname": "org.neo4j.server.rest.web.NodeNotFoundException",
  "stacktrace": [
    "org.neo4j.server.rest.web.DatabaseActions.node(DatabaseActions.java:183)",
    "org.neo4j.server.rest.web.DatabaseActions.getNode(DatabaseActions.java:228)",
    "org.neo4j.server.rest.web.RestfulGraphDatabase.getNode(RestfulGraphDatabase.java:268)",
    "java.lang.reflect.Method.invoke(Method.java:606)",
    "org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:139)",
    "java.lang.Thread.run(Thread.java:744)"
  ]
}

Delete node

Figure 19.17. Final Graph

Example request

  • DELETE http://localhost:7474/db/data/node/108
  • 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 19.18. Final Graph

Example request

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

Example response

  • 409: Conflict
  • Content-Type: application/json; charset=UTF-8
{
  "message": "The node with id 115 cannot be deleted. Check that the node is orphaned before deletion.",
  "exception": "OperationFailureException",
  "fullname": "org.neo4j.server.rest.web.OperationFailureException",
  "stacktrace": [
    "org.neo4j.server.rest.web.DatabaseActions.deleteNode(DatabaseActions.java:237)",
    "org.neo4j.server.rest.web.RestfulGraphDatabase.deleteNode(RestfulGraphDatabase.java:282)",
    "java.lang.reflect.Method.invoke(Method.java:606)",
    "org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:139)",
    "java.lang.Thread.run(Thread.java:744)"
  ]
}