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/430
{
  "extensions" : {
  },
  "paged_traverse" : "http://localhost:7474/db/data/node/430/paged/traverse/{returnType}{?pageSize,leaseTime}",
  "labels" : "http://localhost:7474/db/data/node/430/labels",
  "outgoing_relationships" : "http://localhost:7474/db/data/node/430/relationships/out",
  "traverse" : "http://localhost:7474/db/data/node/430/traverse/{returnType}",
  "all_typed_relationships" : "http://localhost:7474/db/data/node/430/relationships/all/{-list|&|types}",
  "property" : "http://localhost:7474/db/data/node/430/properties/{key}",
  "all_relationships" : "http://localhost:7474/db/data/node/430/relationships/all",
  "self" : "http://localhost:7474/db/data/node/430",
  "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/430/relationships/out/{-list|&|types}",
  "properties" : "http://localhost:7474/db/data/node/430/properties",
  "incoming_relationships" : "http://localhost:7474/db/data/node/430/relationships/in",
  "incoming_typed_relationships" : "http://localhost:7474/db/data/node/430/relationships/in/{-list|&|types}",
  "create_relationship" : "http://localhost:7474/db/data/node/430/relationships",
  "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: 1182
  • Content-Type: application/json; charset=UTF-8
  • Location: http://localhost:7474/db/data/node/426
{
  "extensions" : {
  },
  "paged_traverse" : "http://localhost:7474/db/data/node/426/paged/traverse/{returnType}{?pageSize,leaseTime}",
  "labels" : "http://localhost:7474/db/data/node/426/labels",
  "outgoing_relationships" : "http://localhost:7474/db/data/node/426/relationships/out",
  "traverse" : "http://localhost:7474/db/data/node/426/traverse/{returnType}",
  "all_typed_relationships" : "http://localhost:7474/db/data/node/426/relationships/all/{-list|&|types}",
  "property" : "http://localhost:7474/db/data/node/426/properties/{key}",
  "all_relationships" : "http://localhost:7474/db/data/node/426/relationships/all",
  "self" : "http://localhost:7474/db/data/node/426",
  "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/426/relationships/out/{-list|&|types}",
  "properties" : "http://localhost:7474/db/data/node/426/properties",
  "incoming_relationships" : "http://localhost:7474/db/data/node/426/relationships/in",
  "incoming_typed_relationships" : "http://localhost:7474/db/data/node/426/relationships/in/{-list|&|types}",
  "create_relationship" : "http://localhost:7474/db/data/node/426/relationships",
  "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/275
  • Accept: application/json; charset=UTF-8

Example response

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

Get non-existent node

Figure 19.16. Final Graph

Example request

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

Example response

  • 404: Not Found
  • Content-Type: application/json; charset=UTF-8
{
  "message": "Cannot find node with id [27900000] 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:265)",
    "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/427
  • 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/434
  • Accept: application/json; charset=UTF-8

Example response

  • 409: Conflict
  • Content-Type: application/json; charset=UTF-8
{
  "message": "The node with id 434 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:279)",
    "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)"
  ]
}