17.6. Relationships

17.6.1. Get Relationship by ID
17.6.2. Create relationship
17.6.3. Create a relationship with properties
17.6.4. Delete relationship
17.6.5. Get all properties on a relationship
17.6.6. Set all properties on a relationship
17.6.7. Get single property on a relationship
17.6.8. Set single property on a relationship
17.6.9. Get all relationships
17.6.10. Get incoming relationships
17.6.11. Get outgoing relationships
17.6.12. Get typed relationships
17.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.

17.6.1. Get Relationship by ID

Figure 17.16. Final Graph


Example request

  • GET http://localhost:7474/db/data/relationship/182
  • Accept: application/json

Example response

  • 200: OK
  • Content-Type: application/json
{
  "extensions" : {
  },
  "start" : "http://localhost:7474/db/data/node/295",
  "property" : "http://localhost:7474/db/data/relationship/182/properties/{key}",
  "self" : "http://localhost:7474/db/data/relationship/182",
  "properties" : "http://localhost:7474/db/data/relationship/182/properties",
  "type" : "know",
  "end" : "http://localhost:7474/db/data/node/294",
  "data" : {
  }
}

17.6.2. Create relationship

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

Figure 17.17. Final Graph


Example request

  • POST http://localhost:7474/db/data/node/333/relationships
  • Accept: application/json
  • Content-Type: application/json
{
  "to" : "http://localhost:7474/db/data/node/332",
  "type" : "LOVES"
}

Example response

  • 201: Created
  • Content-Type: application/json
  • Location: http://localhost:7474/db/data/relationship/200
{
  "extensions" : {
  },
  "start" : "http://localhost:7474/db/data/node/333",
  "property" : "http://localhost:7474/db/data/relationship/200/properties/{key}",
  "self" : "http://localhost:7474/db/data/relationship/200",
  "properties" : "http://localhost:7474/db/data/relationship/200/properties",
  "type" : "LOVES",
  "end" : "http://localhost:7474/db/data/node/332",
  "data" : {
  }
}

17.6.3. Create a relationship with properties

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

Figure 17.18. Starting Graph


Figure 17.19. Final Graph


Example request

  • POST http://localhost:7474/db/data/node/343/relationships
  • Accept: application/json
  • Content-Type: application/json
{
  "to" : "http://localhost:7474/db/data/node/342",
  "type" : "LOVES",
  "data" : {
    "foo" : "bar"
  }
}

Example response

  • 201: Created
  • Content-Type: application/json
  • Location: http://localhost:7474/db/data/relationship/207
{
  "extensions" : {
  },
  "start" : "http://localhost:7474/db/data/node/343",
  "property" : "http://localhost:7474/db/data/relationship/207/properties/{key}",
  "self" : "http://localhost:7474/db/data/relationship/207",
  "properties" : "http://localhost:7474/db/data/relationship/207/properties",
  "type" : "LOVES",
  "end" : "http://localhost:7474/db/data/node/342",
  "data" : {
    "foo" : "bar"
  }
}

17.6.4. Delete relationship

Figure 17.20. Starting Graph


Figure 17.21. Final Graph


Example request

  • DELETE http://localhost:7474/db/data/relationship/175
  • Accept: application/json

Example response

  • 204: No Content

17.6.5. Get all properties on a relationship

Figure 17.22. Final Graph


Example request

  • GET http://localhost:7474/db/data/relationship/178/properties
  • Accept: application/json

Example response

  • 200: OK
  • Content-Type: application/json
{
  "cost" : "high",
  "since" : "1day"
}

17.6.6. Set all properties on a relationship

Figure 17.23. Starting Graph


Figure 17.24. Final Graph


Example request

  • PUT http://localhost:7474/db/data/relationship/183/properties
  • Accept: application/json
  • Content-Type: application/json
{
  "happy" : false
}

Example response

  • 204: No Content

17.6.7. Get single property on a relationship

Figure 17.25. Final Graph


Example request

  • GET http://localhost:7474/db/data/relationship/179/properties/cost
  • Accept: application/json

Example response

  • 200: OK
  • Content-Type: application/json
"high"

17.6.8. Set single property on a relationship

Figure 17.26. Starting Graph


Figure 17.27. Final Graph


Example request

  • PUT http://localhost:7474/db/data/relationship/177/properties/cost
  • Accept: application/json
  • Content-Type: application/json
"deadly"

Example response

  • 204: No Content

17.6.9. Get all relationships

Figure 17.28. Final Graph


Example request

  • GET http://localhost:7474/db/data/node/389/relationships/all
  • Accept: application/json

Example response

  • 200: OK
  • Content-Type: application/json
[ {
  "start" : "http://localhost:7474/db/data/node/389",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/235",
  "property" : "http://localhost:7474/db/data/relationship/235/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/235/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/390"
}, {
  "start" : "http://localhost:7474/db/data/node/391",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/236",
  "property" : "http://localhost:7474/db/data/relationship/236/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/236/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/389"
}, {
  "start" : "http://localhost:7474/db/data/node/389",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/237",
  "property" : "http://localhost:7474/db/data/relationship/237/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/237/properties",
  "type" : "HATES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/392"
} ]

17.6.10. Get incoming relationships

Figure 17.29. Final Graph


Example request

  • GET http://localhost:7474/db/data/node/408/relationships/in
  • Accept: application/json

Example response

  • 200: OK
  • Content-Type: application/json
[ {
  "start" : "http://localhost:7474/db/data/node/410",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/247",
  "property" : "http://localhost:7474/db/data/relationship/247/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/247/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/408"
} ]

17.6.11. Get outgoing relationships

Figure 17.30. Final Graph


Example request

  • GET http://localhost:7474/db/data/node/433/relationships/out
  • Accept: application/json

Example response

  • 200: OK
  • Content-Type: application/json
[ {
  "start" : "http://localhost:7474/db/data/node/433",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/261",
  "property" : "http://localhost:7474/db/data/relationship/261/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/261/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/434"
}, {
  "start" : "http://localhost:7474/db/data/node/433",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/263",
  "property" : "http://localhost:7474/db/data/relationship/263/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/263/properties",
  "type" : "HATES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/436"
} ]

17.6.12. Get typed relationships

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

Figure 17.31. Final Graph


Example request

  • GET http://localhost:7474/db/data/node/364/relationships/all/LIKES&HATES
  • Accept: application/json

Example response

  • 200: OK
  • Content-Type: application/json
[ {
  "start" : "http://localhost:7474/db/data/node/364",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/220",
  "property" : "http://localhost:7474/db/data/relationship/220/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/220/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/365"
}, {
  "start" : "http://localhost:7474/db/data/node/366",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/221",
  "property" : "http://localhost:7474/db/data/relationship/221/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/221/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/364"
}, {
  "start" : "http://localhost:7474/db/data/node/364",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/222",
  "property" : "http://localhost:7474/db/data/relationship/222/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/222/properties",
  "type" : "HATES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/367"
} ]

17.6.13. Get relationships on a node without relationships

Figure 17.32. Final Graph


Example request

  • GET http://localhost:7474/db/data/node/422/relationships/all
  • Accept: application/json

Example response

  • 200: OK
  • Content-Type: application/json
[ ]