Updating a resource

To update an individual entity, the request would look like PATCH {{entity-type}}/{{id}}.json. For example, PATCH deals/54.json; deals is the entity type, 54 is the ID of the deal.

See Request structure for an example request. You can send the full entity in the request as that document implies but we actually recommended to only send what needs to change. Any omitted property will be treated as if they’re not changing. For example, if you wanted to update the title of the deal;

PATCH deals/54.json

{
	"deal": {
		"title": "New one",
	}
}

That’s it.

Response

PATCH requests will return a 200 OK with the full updated entity in the response (with your changes applied). See Response structure for an example response.

Updating relationships

Updating to-one relationships

To update a to-one relationship, just give it like so:

{
	"deal": {
		"owner": { "id": 99, "type": "users" },
	}
}

Updating to-many relationships

To update a to-one relationship, you must give all items like so:

{
	"deal": {
		"contacts": [
			{ "id": 19, "type": "contacts" },
			{ "id": 64, "type": "contacts" },
		]
	}
}

So whether you’re adding one, removing one, or substituting some, you need to get the existing ones and first, apply your changes and send them all in the request.

Partial updates to to-many relationships

You may want to apply partial updates; e.g. add one to a to-many relationship without needing to know the existing ones. We thought we’d need this but we never really needed it bad enough to build it. If there is a case where there are a lot of items in the to-many relationship, look at the other side of the relationship; it might be easier to apply the change there. If you really need this, let us know.

Feedback

If you have any feedback or suggestions, feel free to contact us at api@teamwork.com.