26.7. Relationships

26.7.1. Get Relationship by ID
26.7.2. Create relationship
26.7.3. Create a relationship with properties
26.7.4. Delete relationship
26.7.5. Get all properties on a relationship
26.7.6. Set all properties on a relationship
26.7.7. Get single property on a relationship
26.7.8. Set single property on a relationship
26.7.9. Get all relationships
26.7.10. Get incoming relationships
26.7.11. Get outgoing relationships
26.7.12. Get typed relationships
26.7.13. Get relationships on a node without relationships

Relationships are a first class citizen in the Neo4j REST API. They can be accessed either stand-alone or through the nodes they are attached to.

The general pattern to get relationships from a node is:

GET http://localhost:7474/db/data/node/123/relationships/{dir}/{-list|&|types}

Where dir is one of all, in, out and types is an ampersand-separated list of types. See the examples below for more information.

26.7.1. Get Relationship by ID

Figure 26.16. Final Graph


Example request

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

Example response

  • 200: OK
  • Content-Type: application/json; charset=UTF-8
{
  "extensions" : {
  },
  "start" : "http://localhost:7474/db/data/node/20",
  "property" : "http://localhost:7474/db/data/relationship/9/properties/{key}",
  "self" : "http://localhost:7474/db/data/relationship/9",
  "properties" : "http://localhost:7474/db/data/relationship/9/properties",
  "type" : "know",
  "end" : "http://localhost:7474/db/data/node/19",
  "data" : {
  }
}

26.7.2. Create relationship

Upon successful creation of a relationship, the new relationship is returned.

Figure 26.17. Final Graph


Example request

  • POST http://localhost:7474/db/data/node/7/relationships
  • Accept: application/json; charset=UTF-8
  • Content-Type: application/json
{
  "to" : "http://localhost:7474/db/data/node/6",
  "type" : "LOVES"
}

Example response

  • 201: Created
  • Content-Type: application/json; charset=UTF-8
  • Location: http://localhost:7474/db/data/relationship/1
{
  "extensions" : {
  },
  "start" : "http://localhost:7474/db/data/node/7",
  "property" : "http://localhost:7474/db/data/relationship/1/properties/{key}",
  "self" : "http://localhost:7474/db/data/relationship/1",
  "properties" : "http://localhost:7474/db/data/relationship/1/properties",
  "type" : "LOVES",
  "end" : "http://localhost:7474/db/data/node/6",
  "data" : {
  }
}

26.7.3. Create a relationship with properties

Upon successful creation of a relationship, the new relationship is returned.

Figure 26.18. Starting Graph


Figure 26.19. Final Graph


Example request

  • POST http://localhost:7474/db/data/node/17/relationships
  • Accept: application/json; charset=UTF-8
  • Content-Type: application/json
{
  "to" : "http://localhost:7474/db/data/node/16",
  "type" : "LOVES",
  "data" : {
    "foo" : "bar"
  }
}

Example response

  • 201: Created
  • Content-Type: application/json; charset=UTF-8
  • Location: http://localhost:7474/db/data/relationship/8
{
  "extensions" : {
  },
  "start" : "http://localhost:7474/db/data/node/17",
  "property" : "http://localhost:7474/db/data/relationship/8/properties/{key}",
  "self" : "http://localhost:7474/db/data/relationship/8",
  "properties" : "http://localhost:7474/db/data/relationship/8/properties",
  "type" : "LOVES",
  "end" : "http://localhost:7474/db/data/node/16",
  "data" : {
    "foo" : "bar"
  }
}

26.7.4. Delete relationship

Figure 26.20. Starting Graph


Figure 26.21. Final Graph


Example request

  • DELETE http://localhost:7474/db/data/relationship/2
  • Accept: application/json; charset=UTF-8

Example response

  • 204: No Content

26.7.5. Get all properties on a relationship

Figure 26.22. Final Graph


Example request

  • GET http://localhost:7474/db/data/relationship/5/properties
  • Accept: application/json; charset=UTF-8

Example response

  • 200: OK
  • Content-Type: application/json; charset=UTF-8
{
  "since" : "1day",
  "cost" : "high"
}

26.7.6. Set all properties on a relationship

Figure 26.23. Starting Graph


Figure 26.24. Final Graph


Example request

  • PUT http://localhost:7474/db/data/relationship/10/properties
  • Accept: application/json; charset=UTF-8
  • Content-Type: application/json
{
  "happy" : false
}

Example response

  • 204: No Content

26.7.7. Get single property on a relationship

Figure 26.25. Final Graph


Example request

  • GET http://localhost:7474/db/data/relationship/6/properties/cost
  • Accept: application/json; charset=UTF-8

Example response

  • 200: OK
  • Content-Type: application/json; charset=UTF-8
"high"

26.7.8. Set single property on a relationship

Figure 26.26. Starting Graph


Figure 26.27. Final Graph


Example request

  • PUT http://localhost:7474/db/data/relationship/4/properties/cost
  • Accept: application/json; charset=UTF-8
  • Content-Type: application/json
"deadly"

Example response

  • 204: No Content

26.7.9. Get all relationships

Figure 26.28. Final Graph


Example request

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

Example response

  • 200: OK
  • Content-Type: application/json; charset=UTF-8
[ {
  "start" : "http://localhost:7474/db/data/node/263",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/156",
  "property" : "http://localhost:7474/db/data/relationship/156/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/156/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/264"
}, {
  "start" : "http://localhost:7474/db/data/node/265",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/157",
  "property" : "http://localhost:7474/db/data/relationship/157/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/157/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/263"
}, {
  "start" : "http://localhost:7474/db/data/node/263",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/158",
  "property" : "http://localhost:7474/db/data/relationship/158/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/158/properties",
  "type" : "HATES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/266"
} ]

26.7.10. Get incoming relationships

Figure 26.29. Final Graph


Example request

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

Example response

  • 200: OK
  • Content-Type: application/json; charset=UTF-8
[ {
  "start" : "http://localhost:7474/db/data/node/284",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/168",
  "property" : "http://localhost:7474/db/data/relationship/168/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/168/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/282"
} ]

26.7.11. Get outgoing relationships

Figure 26.30. Final Graph


Example request

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

Example response

  • 200: OK
  • Content-Type: application/json; charset=UTF-8
[ {
  "start" : "http://localhost:7474/db/data/node/307",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/182",
  "property" : "http://localhost:7474/db/data/relationship/182/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/182/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/308"
}, {
  "start" : "http://localhost:7474/db/data/node/307",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/184",
  "property" : "http://localhost:7474/db/data/relationship/184/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/184/properties",
  "type" : "HATES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/310"
} ]

26.7.12. Get typed relationships

Note that the "&" needs to be encoded like "%26" for example when using cURL from the terminal.

Figure 26.31. Final Graph


Example request

  • GET http://localhost:7474/db/data/node/238/relationships/all/LIKES&HATES
  • Accept: application/json; charset=UTF-8

Example response

  • 200: OK
  • Content-Type: application/json; charset=UTF-8
[ {
  "start" : "http://localhost:7474/db/data/node/238",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/141",
  "property" : "http://localhost:7474/db/data/relationship/141/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/141/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/239"
}, {
  "start" : "http://localhost:7474/db/data/node/240",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/142",
  "property" : "http://localhost:7474/db/data/relationship/142/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/142/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/238"
}, {
  "start" : "http://localhost:7474/db/data/node/238",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/143",
  "property" : "http://localhost:7474/db/data/relationship/143/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/143/properties",
  "type" : "HATES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/241"
} ]

26.7.13. Get relationships on a node without relationships

Figure 26.32. Final Graph


Example request

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

Example response

  • 200: OK
  • Content-Type: application/json; charset=UTF-8
[ ]