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

Get non-existent node

Figure 21.16. Final Graph

Example request

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

Example response

  • 404: Not Found
  • Content-Type: application/json; charset=UTF-8
{
  "message": "Cannot find node with id [600000] in database.",
  "exception": "NodeNotFoundException",
  "fullname": "org.neo4j.server.rest.web.NodeNotFoundException",
  "stacktrace": [
    "org.neo4j.server.rest.web.DatabaseActions.node(DatabaseActions.java:175)",
    "org.neo4j.server.rest.web.DatabaseActions.getNode(DatabaseActions.java:220)",
    "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)"
  ],
  "errors": [
    {
      "message": "Cannot find node with id [600000] in database.",
      "code": "Neo.DatabaseError.General.UnknownFailure",
      "stacktrace": "org.neo4j.server.rest.web.NodeNotFoundException: Cannot find node with id [600000] in database.\n\tat org.neo4j.server.rest.web.DatabaseActions.node(DatabaseActions.java:175)\n\tat org.neo4j.server.rest.web.DatabaseActions.getNode(DatabaseActions.java:220)\n\tat org.neo4j.server.rest.web.RestfulGraphDatabase.getNode(RestfulGraphDatabase.java:265)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.java:606)\n\tat com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)\n\tat com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)\n\tat com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)\n\tat org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:139)\n\tat com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)\n\tat com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)\n\tat com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)\n\tat com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)\n\tat com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)\n\tat com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)\n\tat com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)\n\tat com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)\n\tat com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)\n\tat com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)\n\tat com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:540)\n\tat com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:715)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:790)\n\tat org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:751)\n\tat org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:566)\n\tat org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:219)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1111)\n\tat org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:498)\n\tat org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1045)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)\n\tat org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:98)\n\tat org.eclipse.jetty.server.Server.handle(Server.java:461)\n\tat org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:284)\n\tat org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:244)\n\tat org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:534)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:536)\n\tat java.lang.Thread.run(Thread.java:744)\n"
    }
  ]
}

Delete node

Figure 21.17. Final Graph

Example request

  • DELETE http://localhost:7474/db/data/node/57
  • 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/64
  • Accept: application/json; charset=UTF-8

Example response

  • 409: Conflict
  • Content-Type: application/json; charset=UTF-8
{
  "message": "The node with id 64 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:229)",
    "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)"
  ],
  "errors": [
    {
      "message": "The node with id 64 cannot be deleted. Check that the node is orphaned before deletion.",
      "code": "Neo.DatabaseError.General.UnknownFailure",
      "stacktrace": "org.neo4j.server.rest.web.OperationFailureException: The node with id 64 cannot be deleted. Check that the node is orphaned before deletion.\n\tat org.neo4j.server.rest.web.DatabaseActions.deleteNode(DatabaseActions.java:229)\n\tat org.neo4j.server.rest.web.RestfulGraphDatabase.deleteNode(RestfulGraphDatabase.java:279)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.java:606)\n\tat com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)\n\tat com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)\n\tat com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)\n\tat org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:139)\n\tat com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)\n\tat com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)\n\tat com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)\n\tat com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)\n\tat com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)\n\tat com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)\n\tat com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)\n\tat com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)\n\tat com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)\n\tat com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)\n\tat com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:540)\n\tat com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:715)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:790)\n\tat org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:751)\n\tat org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:566)\n\tat org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:219)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1111)\n\tat org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:498)\n\tat org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1045)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)\n\tat org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:98)\n\tat org.eclipse.jetty.server.Server.handle(Server.java:461)\n\tat org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:284)\n\tat org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:244)\n\tat org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:534)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:536)\n\tat java.lang.Thread.run(Thread.java:744)\n"
    }
  ]
}