# Alternative ways to update multiple objects

**URL:** <https://discuss.jsonapi.org/t/alternative-ways-to-update-multiple-objects/952>\
**Category:** Uncategorized\
**Created:** [April 13, 2017, 7:16am UTC](https://discuss.jsonapi.org/t/alternative-ways-to-update-multiple-objects/952 "2017-04-13T07:16:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanylcs](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@sanylcs](https://discuss.jsonapi.org/u/sanylcs)\
**Post date:** [April 13, 2017, 7:16am UTC](https://discuss.jsonapi.org/t/alternative-ways-to-update-multiple-objects/952/1 "2017-04-13T07:16:58Z")

</div>

I am trying to find a workaround for implementation of updating multiple objects in one request. I am aware of issue [github issue #795](https://github.com/json-api/json-api/issues/795) and also read [comment here](https://github.com/json-api/json-api/issues/795#issuecomment-181576452). I am trying to implement what krainboltgreene said.

I have an object _errand_ in database where it has a field _dirty_ default as _false_. I need a request to bulk update _dirty_ field for many rows of object _errand_

In single update:

```
PATCH /errands/1 HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json

{
  "data": {
  "type": "errands",
  "id": "1",
  "attributes": {
    "dirty": true
  }
}

```

For multiple objects update I am planning to do something as:

```
POST /errand_dirty_list/0/relationships/errands HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json

{
  "data": [
    { "type": "errands", "id": "123" },
    { "type": "errands", "id": "124" }
  ]
}

```

Or may be do something like this:

```
POST /errand_dirty_list HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json

{
  "data": {
  "type": "errand_dirty_list",
  "attributes": {
    "dirty_errands": [123, 124, 125]
  }
}

```

For both workaround cases, I need to response a fake resource identifier object **id** because my database do not have the object **errand\_dirty\_list**.

My question is **_is this way of workaround to implement multiple object update as single request still valid as JSONAPI specification?_** If not, is there any other way that still work and compliance with current JSONAPI specification?

---

<div class="post-metadata">

**Author:** ![michaelhibay](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/michaelhibay/32/405_2.png) [@michaelhibay](https://discuss.jsonapi.org/u/michaelhibay)\
**Post date:** [April 14, 2017, 3:24pm UTC](https://discuss.jsonapi.org/t/alternative-ways-to-update-multiple-objects/952/2 "2017-04-14T15:24:57Z")

</div>

~~Here’s a thought, why not just manage it yourself as an async resource?~~

EDIT: Ok, actually read the comment and I think that is exactly his suggestion. Maybe without the async part.

The way I would approach this is to create a resource which represents a bulk operation, maybe not even on the errand resource. I wouldn’t concern myself with what the operation is, the resource representation should give that information.

```
/bulktransactions/.....
```

That way your payload could be something like this:

```
{
  "data": {
    "type": "bulktransaction",
    "attributes": {
      "resources": [{"type":"errands"}],
      "operations": [
        {"id":123,"method":"PATCH", "payload":1},
        {"id":124,"method":"PATCH", "payload":1},
        {"id":125,"method":"PATCH","payload":1}
      ],
      "payload":[
        {"id":1,
          "value":{
            "data": {
              "type": "errands",
              "attributes": {
                "dirty": true
              }
            }
          }
        }
      ]
    }
  }
}
```

You could return a location header for the bulk transaction resource itself, and get all the info and updates you needed from there.

---

<div class="post-metadata">

**Author:** ![sanylcs](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@sanylcs](https://discuss.jsonapi.org/u/sanylcs)\
**Post date:** [April 16, 2017, 11:59pm UTC](https://discuss.jsonapi.org/t/alternative-ways-to-update-multiple-objects/952/3 "2017-04-16T23:59:02Z")

</div>

Look like what you recommended is more alike of the recommended way. Thank you!
