19.2. Nodes

19.2.1. Create Node
19.2.2. Create Node with properties
19.2.3. Get node
19.2.4. Get non-existent node
19.2.5. Delete node
19.2.6. Nodes with relationships can not be deleted

19.2.1. Create Node

Figure 19.2. Final Graph


Example request

  • POST http://localhost:7474/db/data/node
  • Accept: application/json

Example response

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

19.2.2. Create Node with properties

Figure 19.3. Final Graph


Example request

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

Example response

  • 201: Created
  • Content-Length: 1120
  • Content-Type: application/json
  • Location: http://localhost:7474/db/data/node/167
{
  "outgoing_relationships" : "http://localhost:7474/db/data/node/167/relationships/out",
  "data" : {
    "foo" : "bar"
  },
  "traverse" : "http://localhost:7474/db/data/node/167/traverse/{returnType}",
  "all_typed_relationships" : "http://localhost:7474/db/data/node/167/relationships/all/{-list|&|types}",
  "property" : "http://localhost:7474/db/data/node/167/properties/{key}",
  "self" : "http://localhost:7474/db/data/node/167",
  "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/167/relationships/out/{-list|&|types}",
  "properties" : "http://localhost:7474/db/data/node/167/properties",
  "incoming_relationships" : "http://localhost:7474/db/data/node/167/relationships/in",
  "extensions" : {
  },
  "create_relationship" : "http://localhost:7474/db/data/node/167/relationships",
  "paged_traverse" : "http://localhost:7474/db/data/node/167/paged/traverse/{returnType}{?pageSize,leaseTime}",
  "all_relationships" : "http://localhost:7474/db/data/node/167/relationships/all",
  "incoming_typed_relationships" : "http://localhost:7474/db/data/node/167/relationships/in/{-list|&|types}"
}

19.2.3. Get node

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

Figure 19.4. Final Graph


Example request

  • GET http://localhost:7474/db/data/node/3
  • Accept: application/json

Example response

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

19.2.4. Get non-existent node

Figure 19.5. Final Graph


Example request

  • GET http://localhost:7474/db/data/node/800000
  • Accept: application/json

Example response

  • 404: Not Found
  • Content-Type: application/json
{
  "message" : "Cannot find node with id [800000] in database.",
  "exception" : "org.neo4j.server.rest.web.NodeNotFoundException: Cannot find node with id [800000] in database.",
  "stacktrace" : [ "org.neo4j.server.rest.web.DatabaseActions.node(DatabaseActions.java:124)", "org.neo4j.server.rest.web.DatabaseActions.getNode(DatabaseActions.java:235)", "org.neo4j.server.rest.web.RestfulGraphDatabase.getNode(RestfulGraphDatabase.java:225)", "java.lang.reflect.Method.invoke(Method.java:597)" ]
}

19.2.5. Delete node

Figure 19.6. Final Graph


Example request

  • DELETE http://localhost:7474/db/data/node/175
  • Accept: application/json

Example response

  • 204: No Content

19.2.6. Nodes with relationships can not be deleted

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

Figure 19.7. Final Graph


Example request

  • DELETE http://localhost:7474/db/data/node/176
  • Accept: application/json

Example response

  • 409: Conflict
  • Content-Type: application/json
{
  "message" : "The node with id 176 cannot be deleted. Check that the node is orphaned before deletion.",
  "exception" : "org.neo4j.server.rest.web.OperationFailureException: The node with id 176 cannot be deleted. Check that the node is orphaned before deletion.",
  "stacktrace" : [ "org.neo4j.server.rest.web.DatabaseActions.deleteNode(DatabaseActions.java:256)", "org.neo4j.server.rest.web.RestfulGraphDatabase.deleteNode(RestfulGraphDatabase.java:239)", "java.lang.reflect.Method.invoke(Method.java:597)" ]
}