22.6. Relationships

22.6.1. Get Relationship by ID
22.6.2. Create relationship
22.6.3. Create a relationship with properties
22.6.4. Delete relationship
22.6.5. Get all properties on a relationship
22.6.6. Set all properties on a relationship
22.6.7. Get single property on a relationship
22.6.8. Set single property on a relationship
22.6.9. Get all relationships
22.6.10. Get incoming relationships
22.6.11. Get outgoing relationships
22.6.12. Get typed relationships
22.6.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.

22.6.1. Get Relationship by ID

Figure 22.14. Final Graph


Example request

  • GET http://localhost:7474/db/data/relationship/91
  • 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/186",
  "property" : "http://localhost:7474/db/data/relationship/91/properties/{key}",
  "self" : "http://localhost:7474/db/data/relationship/91",
  "properties" : "http://localhost:7474/db/data/relationship/91/properties",
  "type" : "know",
  "end" : "http://localhost:7474/db/data/node/185",
  "data" : {
  }
}

22.6.2. Create relationship

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

Figure 22.15. Final Graph


Example request

  • POST http://localhost:7474/db/data/node/2/relationships
  • Accept: application/json; charset=UTF-8
  • Content-Type: application/json
{
  "to" : "http://localhost:7474/db/data/node/1",
  "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/2",
  "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/1",
  "data" : {
  }
}

22.6.3. Create a relationship with properties

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

Figure 22.16. Starting Graph


Figure 22.17. Final Graph


Example request

  • POST http://localhost:7474/db/data/node/12/relationships
  • Accept: application/json; charset=UTF-8
  • Content-Type: application/json
{
  "to" : "http://localhost:7474/db/data/node/11",
  "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/12",
  "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/11",
  "data" : {
    "foo" : "bar"
  }
}

22.6.4. Delete relationship

Figure 22.18. Starting Graph


Figure 22.19. Final Graph


Example request

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

Example response

  • 204: No Content

22.6.5. Get all properties on a relationship

Figure 22.20. Final Graph


Example request

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

Example response

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

22.6.6. Set all properties on a relationship

Figure 22.21. Starting Graph


Figure 22.22. Final Graph


Example request

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

Example response

  • 204: No Content

22.6.7. Get single property on a relationship

Figure 22.23. Final Graph


Example request

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

Example response

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

22.6.8. Set single property on a relationship

Figure 22.24. Starting Graph


Figure 22.25. Final Graph


Example request

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

Example response

  • 204: No Content

22.6.9. Get all relationships

Figure 22.26. Final Graph


Example request

  • GET http://localhost:7474/db/data/node/68/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/68",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/27",
  "property" : "http://localhost:7474/db/data/relationship/27/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/27/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/69"
}, {
  "start" : "http://localhost:7474/db/data/node/70",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/28",
  "property" : "http://localhost:7474/db/data/relationship/28/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/28/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/68"
}, {
  "start" : "http://localhost:7474/db/data/node/68",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/29",
  "property" : "http://localhost:7474/db/data/relationship/29/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/29/properties",
  "type" : "HATES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/71"
} ]

22.6.10. Get incoming relationships

Figure 22.27. Final Graph


Example request

  • GET http://localhost:7474/db/data/node/87/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/89",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/39",
  "property" : "http://localhost:7474/db/data/relationship/39/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/39/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/87"
} ]

22.6.11. Get outgoing relationships

Figure 22.28. Final Graph


Example request

  • GET http://localhost:7474/db/data/node/112/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/112",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/53",
  "property" : "http://localhost:7474/db/data/relationship/53/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/53/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/113"
}, {
  "start" : "http://localhost:7474/db/data/node/112",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/55",
  "property" : "http://localhost:7474/db/data/relationship/55/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/55/properties",
  "type" : "HATES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/115"
} ]

22.6.12. Get typed relationships

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

Figure 22.29. Final Graph


Example request

  • GET http://localhost:7474/db/data/node/43/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/43",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/12",
  "property" : "http://localhost:7474/db/data/relationship/12/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/12/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/44"
}, {
  "start" : "http://localhost:7474/db/data/node/45",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/13",
  "property" : "http://localhost:7474/db/data/relationship/13/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/13/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/43"
}, {
  "start" : "http://localhost:7474/db/data/node/43",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/14",
  "property" : "http://localhost:7474/db/data/relationship/14/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/14/properties",
  "type" : "HATES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/46"
} ]

22.6.13. Get relationships on a node without relationships

Figure 22.30. Final Graph


Example request

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

Example response

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