Prev |  | Next

## 20.7. Nodes

### 20.7.1. Create node

Figure 20.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/8`

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

### 20.7.2. Create node with properties

Figure 20.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:` `1156`
- `Content-Type:` `application/json; charset=UTF-8`
- `Location:` `http://localhost:7474/db/data/node/4`

    {
      "extensions" : {
      },
      "labels" : "http://localhost:7474/db/data/node/4/labels",
      "outgoing_relationships" : "http://localhost:7474/db/data/node/4/relationships/out",
      "traverse" : "http://localhost:7474/db/data/node/4/traverse/{returnType}",
      "all_typed_relationships" : "http://localhost:7474/db/data/node/4/relationships/all/{-list|&|types}",
      "self" : "http://localhost:7474/db/data/node/4",
      "property" : "http://localhost:7474/db/data/node/4/properties/{key}",
      "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/4/relationships/out/{-list|&|types}",
      "properties" : "http://localhost:7474/db/data/node/4/properties",
      "incoming_relationships" : "http://localhost:7474/db/data/node/4/relationships/in",
      "create_relationship" : "http://localhost:7474/db/data/node/4/relationships",
      "paged_traverse" : "http://localhost:7474/db/data/node/4/paged/traverse/{returnType}{?pageSize,leaseTime}",
      "all_relationships" : "http://localhost:7474/db/data/node/4/relationships/all",
      "incoming_typed_relationships" : "http://localhost:7474/db/data/node/4/relationships/in/{-list|&|types}",
      "data" : {
        "foo" : "bar"
      }
    }

### 20.7.3. Get node

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

Figure 20.15. Final Graph

Example request

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

Example response

- `200:` `OK`
- `Content-Type:` `application/json; charset=UTF-8`

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

### 20.7.4. Get non-existent node

Figure 20.16. Final Graph

Example request

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

Example response

- `404:` `Not Found`
- `Content-Type:` `application/json; charset=UTF-8`

    {
      "message": "Cannot find node with id [3400000] 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)",
        "org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)",
        "java.lang.Thread.run(Thread.java:724)"
      ]
    }

### 20.7.5. Delete node

Figure 20.17. Final Graph

Example request

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

Example response

- `204:` `No Content`

### 20.7.6. Nodes with relationships cannot be deleted

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

Figure 20.18. Final Graph

Example request

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

Example response

- `409:` `Conflict`
- `Content-Type:` `application/json; charset=UTF-8`

    {
      "message": "The node with id 12 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)",
        "org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)",
        "java.lang.Thread.run(Thread.java:724)"
      ]
    }

Copyright © 2014 Neo Technology

Prev | Up | Next
| Home |