# Updating multiple objects in single request

**URL:** <https://discuss.jsonapi.org/t/updating-multiple-objects-in-single-request/183>\
**Category:** Uncategorized\
**Created:** [November 4, 2015, 8:04am UTC](https://discuss.jsonapi.org/t/updating-multiple-objects-in-single-request/183 "2015-11-04T08:04:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mehulkar](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/mehulkar/32/108_2.png) [@mehulkar](https://discuss.jsonapi.org/u/mehulkar)\
**Post date:** [November 4, 2015, 8:04am UTC](https://discuss.jsonapi.org/t/updating-multiple-objects-in-single-request/183/1 "2015-11-04T08:04:22Z")

</div>

About updating objects, the spec says:

> The PATCH request MUST include a **single** resource object as primary data.

I’m personally against updating multiple objects in a single request, but there _are_ times when you want to to accomplish this. For example, a multi-select UI may allow a user to set the same attribute on multiple records.

Has there been a discussion about batch updates anywhere?

---

<div class="post-metadata">

**Author:** ![steveklabnik](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/steveklabnik/32/2_2.png) [@steveklabnik](https://discuss.jsonapi.org/u/steveklabnik)\
**Post date:** [November 4, 2015, 8:47am UTC](https://discuss.jsonapi.org/t/updating-multiple-objects-in-single-request/183/2 "2015-11-04T08:47:09Z")

</div>

> <https://github.com/json-api/json-api/issues/795>
>
> It has been widely requested that JSON-API support creating/editing/updating/deleting multiple records in a single request (#202, #205, #753, #536). We have...

---

<div class="post-metadata">

**Author:** ![mehulkar](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/mehulkar/32/108_2.png) [@mehulkar](https://discuss.jsonapi.org/u/mehulkar)\
**Post date:** [November 5, 2015, 12:52am UTC](https://discuss.jsonapi.org/t/updating-multiple-objects-in-single-request/183/3 "2015-11-05T00:52:22Z")

</div>

ah, awesome. thanks! 😄

---

<div class="post-metadata">

**Author:** ![andrewhenderson](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/andrewhenderson/32/115_2.png) [@andrewhenderson](https://discuss.jsonapi.org/u/andrewhenderson)\
**Post date:** [March 30, 2016, 5:56pm UTC](https://discuss.jsonapi.org/t/updating-multiple-objects-in-single-request/183/4 "2016-03-30T17:56:18Z")

</div>

**My team came up with the idea to support `included` in POST and PATCH requests.**

For instance, when updating a child that has an effect on one of the parent’s values.

In our case, a change to one of the children’s values changes values on the parent’s attributes at the top-level as well as values within another set of the parent’s children, a sibling array.

We chose to include the parent’s changes in the request.

**PATCH**

```auto
{
  "data":{
    "id":"1",
    "type":"expense",
    "attributes":{
      "amount":25
    }
  },
  "included":[
    {
      "id":"43",
      "type":"report",
      "attributes":{
        "amount":100,
        "allocations":[
          {
            "percent":60,
            "amount":60
          },
          {
            "percent":40,
            "amount":40
          }
        ]
      }
    }
  ]
}
```

In this case, the change to the expense resource’s `amount` changes the `amount` of the report resource, which also changes the `amount` on the report resource’s allocations objects, which get adjusted according to their percentages.

\*Interestingly, I realized after doing this, that as long as you provide a `type` and `id` in the objects provided in the `included` array, you could provide the server with any resource change, regardless of an existing `relationship` as long as the server knows how to handle the request.
