Relating Resources

Resources in OData often have relationships with other resources.
These relationships can be managed through PUT, POST, and DELETE operations.


Adding a Single Relationship

Use HTTP PUT with @odata.id to assign a related entity:

PUT http://myserver:5181/odata/ServiceRequest(139239)/Caller/$ref  HTTP/1.1
Content-Length: 23
Content-Type: application/json


{
    ‘@odata.id’: http://myserver:5181/odata/Person(146)
}

Adding to a Collection

Use HTTP POST to add a new entity to a collection:

POST http://myserver:5181/odata/ServiceRequest(139239)/Workorders/$ref  HTTP/1.1
Content-Length: 23
Content-Type: application/json


{
    ‘@odata.id’: http://myserver:5181/odata/Workorders(281486108328022)
}

Removing a Relationship

To remove a relationship, use HTTP DELETE:

DELETE http://myserver:5181/odata/ServiceRequest(139239)/Caller/$ref  HTTP/1.1

➡ This removes the Caller reference, leaving it empty.


Removing from a Collection

For collections, provide the specific entity id:

http://myserver:5181/odata/ServiceRequests(3101097999)/Workorders(281486108328022)/$ref  HTTP/1.1

➡ This removes Workorder (281486108328022) from ServiceRequest (3101097999).


Nested Relationships

The same approach applies to nested references within complex properties:

http://myserver:5181/odata/ServiceRequest(139239)/Assignment/AssigneeWorkgroup/$ref
http://myserver:5181/odata/ServiceRequest(139239)/Assignment/AssigneePerson/$ref

Notes

  • PUT / POST → assign a relationship.
  • DELETE → remove a relationship.
  • A Prefer header can be included to return the updated object.
Back to top