# Support updating through relationship links required?

**URL:** <https://discuss.jsonapi.org/t/support-updating-through-relationship-links-required/424>\
**Category:** Uncategorized\
**Created:** [April 10, 2016, 4:08pm UTC](https://discuss.jsonapi.org/t/support-updating-through-relationship-links-required/424 "2016-04-10T16:08:13Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![speterson14](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/speterson14/32/255_2.png) [@speterson14](https://discuss.jsonapi.org/u/speterson14)\
**Post date:** [April 10, 2016, 4:08pm UTC](https://discuss.jsonapi.org/t/support-updating-through-relationship-links-required/424/1 "2016-04-10T16:08:13Z")

</div>

Hi! I have a question about this section of the spec:

"Although relationships can be modified along with resources (as described above), JSON API also supports updating of relationships independently at URLs from relationship links."  
[http://jsonapi.org/format/#crud-updating-relationships](http://jsonapi.org/format/#crud-updating-relationships)

So, I understand that the relationships can be modified through PATCH requests to the resource itself (something like `books/1`), or by PATCH requests to relationship links (something like `/books/1/relationships/author`). But is the server also required to support relationship links/updates through relationship links, or is that optional?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![lukasoppermann](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/lukasoppermann/32/178_2.png) [@lukasoppermann](https://discuss.jsonapi.org/u/lukasoppermann)\
**Post date:** [April 10, 2016, 8:31pm UTC](https://discuss.jsonapi.org/t/support-updating-through-relationship-links-required/424/2 "2016-04-10T20:31:30Z")

</div>

Are you asking if you have to support an update to author through `/books/1/relationships/author`? I am pretty sure this is not supposed to be possible. You do also no show individual authors with links like `/books/1/relationships/author/uuid-of-author`.

Is that what you are asking, or did I misunderstand you?

---

<div class="post-metadata">

**Author:** ![speterson14](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/speterson14/32/255_2.png) [@speterson14](https://discuss.jsonapi.org/u/speterson14)\
**Post date:** [April 10, 2016, 9:43pm UTC](https://discuss.jsonapi.org/t/support-updating-through-relationship-links-required/424/3 "2016-04-10T21:43:28Z")

</div>

@lukasoppermann Thanks for responding! I think what you’re describing is not quite what I’m talking about–what I’m asking about is updating the relationship of, in this example, a book’s author, through a PATCH request to a relationship link. So you aren’t changing the author itself, you are just changing _which_ author a book has. It’s described in this part of the spec:

[http://jsonapi.org/format/#crud-updating-to-one-relationships](http://jsonapi.org/format/#crud-updating-to-one-relationships)

The reason I’m wondering if this is required is because you could accomplish the same thing by just sending an update request to the author itself with the new relationship specified (this is described in the spec here: [http://jsonapi.org/format/#crud-updating-resource-relationships.)](http://jsonapi.org/format/#crud-updating-resource-relationships.)) And the description in the spec here seemed a little ambiguous as to whether the server needed to support both of these strategies: [http://jsonapi.org/format/#crud-updating-relationships](http://jsonapi.org/format/#crud-updating-relationships)

---

<div class="post-metadata">

**Author:** ![jlangley](https://avatars.discourse-cdn.com/v4/letter/j/9e8a1a/32.png) [@jlangley](https://discuss.jsonapi.org/u/jlangley)\
**Post date:** [April 11, 2016, 8:29am UTC](https://discuss.jsonapi.org/t/support-updating-through-relationship-links-required/424/4 "2016-04-11T08:29:30Z")

</div>

The way I read the spec, it’s the `/relationships/` strategy that **has** to be supported, and the “via the resource” strategy is optional.

---

<div class="post-metadata">

**Author:** ![Sazzer](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/sazzer/32/262_2.png) [@Sazzer](https://discuss.jsonapi.org/u/Sazzer)\
**Post date:** [April 11, 2016, 3:34pm UTC](https://discuss.jsonapi.org/t/support-updating-through-relationship-links-required/424/5 "2016-04-11T15:34:15Z")

</div>

The spec is quite clear that you MUST support editing the relationship like this. Under the section “Updating Relationships \> Updating To-One Relationships”

> A server **MUST** respond to PATCH requests to a URL from a to-one relationship link as described below.

Further to that, under the section “Updating Resources \> Updating a Resource’s Relationships”, the wording is instead:

> Any or all of a resource’s relationships **MAY** be included in the resource object included in a PATCH request.

Meaning that you can choose to support this if you wish, but there’s no need to do so.

Edit: Actually, on re-reading that, it says the server must **respond** to the request. You can always choose to respond that the request is not allowed and still follow the letter of the spec, but I’d argue you’re then not following the spirit of the spec.

---

<div class="post-metadata">

**Author:** ![speterson14](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/speterson14/32/255_2.png) [@speterson14](https://discuss.jsonapi.org/u/speterson14)\
**Post date:** [April 11, 2016, 4:19pm UTC](https://discuss.jsonapi.org/t/support-updating-through-relationship-links-required/424/6 "2016-04-11T16:19:01Z")

</div>

Thanks @Sazzer and @jlangley --that makes sense! The clarification that “respond” could technically mean responding that it’s not allowed yet was helpful.

---

<div class="post-metadata">

**Author:** ![jlangley](https://avatars.discourse-cdn.com/v4/letter/j/9e8a1a/32.png) [@jlangley](https://discuss.jsonapi.org/u/jlangley)\
**Post date:** [April 11, 2016, 4:23pm UTC](https://discuss.jsonapi.org/t/support-updating-through-relationship-links-required/424/7 "2016-04-11T16:23:07Z")

</div>

> [@Sazzer](#):
>
> as described below.

That phrase could do with some clarification in a later version. Does it refer to the relationship link, to the URL, to the PATCH request, or to the server response?

---

<div class="post-metadata">

**Author:** ![Sazzer](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/sazzer/32/262_2.png) [@Sazzer](https://discuss.jsonapi.org/u/Sazzer)\
**Post date:** [April 11, 2016, 4:30pm UTC](https://discuss.jsonapi.org/t/support-updating-through-relationship-links-required/424/8 "2016-04-11T16:30:39Z")

</div>

@jlangley I think it’s meant to refer to the response from the server, which is described immediately below. I think all of the other options are actually described _above_ that line in the document.

---

<div class="post-metadata">

**Author:** ![jlangley](https://avatars.discourse-cdn.com/v4/letter/j/9e8a1a/32.png) [@jlangley](https://discuss.jsonapi.org/u/jlangley)\
**Post date:** [April 11, 2016, 4:35pm UTC](https://discuss.jsonapi.org/t/support-updating-through-relationship-links-required/424/9 "2016-04-11T16:35:32Z")

</div>

The PATCH request is described immediately below 😇.  
But I agree - I _think_ the phrase applies to the response, i.e. to [this](http://jsonapi.org/format/#crud-updating-relationship-responses), which would allow the server to respond with a `403` as you suggest 🙂

---

<div class="post-metadata">

**Author:** ![Sazzer](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/sazzer/32/262_2.png) [@Sazzer](https://discuss.jsonapi.org/u/Sazzer)\
**Post date:** [April 11, 2016, 4:37pm UTC](https://discuss.jsonapi.org/t/support-updating-through-relationship-links-required/424/10 "2016-04-11T16:37:26Z")

</div>

Ah - PATCH is described twice. Once under “Updating Relationships” which is immediately below as you say, but also under “Updating Resources” which is higher up. I’d somehow not noticed that…

---

<div class="post-metadata">

**Author:** ![Sazzer](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/sazzer/32/262_2.png) [@Sazzer](https://discuss.jsonapi.org/u/Sazzer)\
**Post date:** [April 12, 2016, 12:16pm UTC](https://discuss.jsonapi.org/t/support-updating-through-relationship-links-required/424/11 "2016-04-12T12:16:13Z")

</div>

@speterson14 - Reading over things in the Spec again, and there is another option that comes to mind. You don’t actually need to support the Relationship link at all.

When you have a Relationship, you must provide at least one of “self” and “related”. The “self” link is a link to the relationship record, as opposed to the record you are related to. The only real benefits of this are:

- It allows you to edit the Relationship directly, instead of editing it via the resource.
- It allows you to retrieve extra information about the relationship itself.

You are trying to avoid the first of those being possible. If you don’t have any need for the second of those, then just don’t return a “self” link for the relationship, and the problems go away.

---

<div class="post-metadata">

**Author:** ![cmeeren](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/cmeeren/32/596_2.png) [@cmeeren](https://discuss.jsonapi.org/u/cmeeren)\
**Post date:** [May 3, 2018, 10:06am UTC](https://discuss.jsonapi.org/t/support-updating-through-relationship-links-required/424/12 "2018-05-03T10:06:52Z")

</div>

I know I’m a bit late to the party, but I found the answer to this in [this issue](https://github.com/json-api/json-api/issues/1172) on the the JSON API GitHub repo.
