22.5. Nodes

22.5.1. Create node
22.5.2. Create node with properties
22.5.3. Get node
22.5.4. Get non-existent node
22.5.5. Delete node
22.5.6. Nodes with relationships can not be deleted

22.5.1. Create node

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

22.5.2. Create node with properties

Figure 22.10. 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: 1096
  • Content-Type: application/json
  • Location: http://localhost:7474/db/data/node/5
{
  "extensions" : {
  },
  "paged_traverse" : "http://localhost:7474/db/data/node/5/paged/traverse/{returnType}{?pageSize,leaseTime}",
  "outgoing_relationships" : "http://localhost:7474/db/data/node/5/relationships/out",
  "traverse" : "http://localhost:7474/db/data/node/5/traverse/{returnType}",
  "all_typed_relationships" : "http://localhost:7474/db/data/node/5/relationships/all/{-list|&|types}",
  "property" : "http://localhost:7474/db/data/node/5/properties/{key}",
  "all_relationships" : "http://localhost:7474/db/data/node/5/relationships/all",
  "self" : "http://localhost:7474/db/data/node/5",
  "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/5/relationships/out/{-list|&|types}",
  "properties" : "http://localhost:7474/db/data/node/5/properties",
  "incoming_relationships" : "http://localhost:7474/db/data/node/5/relationships/in",
  "incoming_typed_relationships" : "http://localhost:7474/db/data/node/5/relationships/in/{-list|&|types}",
  "create_relationship" : "http://localhost:7474/db/data/node/5/relationships",
  "data" : {
    "foo" : "bar"
  }
}

22.5.3. Get node

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

Figure 22.11. Final Graph


Example request

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

Example response

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

22.5.4. Get non-existent node

Figure 22.12. Final Graph


Example request

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

Example response

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

22.5.5. Delete node

Figure 22.13. Final Graph


Example request

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

Example response

  • 204: No Content

22.5.6. Nodes with relationships can not be deleted

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

Figure 22.14. Final Graph


Example request

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

Example response

  • 409: Conflict
  • Content-Type: application/json
{
  "message": "The node with id 13 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:231)",
    "org.neo4j.server.rest.web.RestfulGraphDatabase.deleteNode(RestfulGraphDatabase.java:248)",
    "java.lang.reflect.Method.invoke(Method.java:597)"
  ]
}