# Batch Operations (v4 API)

You can specify multiple operations to apply to various objects of various types.

<table><thead><tr><th width="537">Relative URL</th><th>HTTP Request Method</th></tr></thead><tbody><tr><td><code>/api/v4/</code><em><code>backend-deployment-id</code></em><code>/batch.json</code></td><td>POST</td></tr></tbody></table>

{% hint style="warning" %}
**Batch Operation Limit**

Up to 1000 operations are supported per payload. If more than 1000 operations are included in a payload the request will be considered invalid and result in [an error](https://docs.journeyapps.com/reference/backend-api/error-responses#invalid_api_request).
{% endhint %}

### Parameters

An array of operations is supplied in a [hash](http://en.wikipedia.org/wiki/Associative_array) under the key `operations`. These operations are applied in the order they appear in the array. Each operation consists of a hash with required fields: `method`, containing an appropriate keyword, and `object` containing a hash with, at least, the two required fields - `type` and `id`. If the optional key `stop_on_error: true` is supplied alongside `operations`, any operations following an error will not be applied.

<table><thead><tr><th width="202">Operation</th><th width="543">Parameters</th></tr></thead><tbody><tr><td>Create an object</td><td><p><code>"method"</code>: <code>"post"</code><br><code>"object"</code> : Hash with fields:</p><ul><li><code>"type"</code> : <em>(required)</em> The name of the model.</li><li><code>"id"</code> : <em>(optional)</em> The object ID. If omitted, one will be generated. If provided and the ID already exists, the operation will fail.</li><li>All the fields that represent the entire object</li></ul></td></tr><tr><td>Replace an object</td><td><p><code>"method"</code>: <code>"put"</code><br><code>"object"</code> : Hash with fields:</p><ul><li><code>"type"</code> : (required) The name of the model.</li><li><code>"id"</code>: (required) The object ID</li><li>All the fields that represent the entire object</li></ul></td></tr><tr><td>Partial update on an object</td><td><p><code>"method"</code>: <code>"patch"</code><br><code>"object"</code> : Hash with fields:</p><ul><li><code>"type"</code> : (required) The name of the model.</li><li><code>"id"</code> : (required) The object ID</li><li>Only the fields to be updated on the object</li></ul></td></tr><tr><td>Delete an object</td><td><p><code>"method"</code>: <code>"delete"</code><br><code>"object"</code> : Hash with fields:</p><ul><li><code>"type"</code> : (required) The name of the model.</li><li><code>"id"</code> : (required) The object ID</li></ul></td></tr></tbody></table>

### **Response**

An ill-formed or illegal request will fail without performing any of the operations. A well-formed request should execute each operation in order, and return a success response. The body of the response should contain the requested method, object model and object id, as well as a `"success"` flag and any relevant `"error"` details for each operation. See [Error Responses](https://docs.journeyapps.com/reference/backend-api/api-reference/error-responses) for a description of each error.

```json
{
  "stop_on_error": false,
  "operations": [
      {
        "method": "put",
        "object": {
          "type": "asset",
          "id": "eacb4836-f1b9-11e1-9750-001cc01904e3"
        },
        "success": true
      },
      {
        "method": "patch",
        "object": {
          "type": "asset",
          "id": "44218dfe-7c3f-11e2-95e1-0026189d9dc0"
        },
        "success": false,
        "error": {
          "type": "INVALID_VALUE",
          "title": "Invalid value specified.",
          "detail": "Invalid option \"adsghjsd\" for field 'make'.",
          "see": "https://docs.journeyapps.com/reference/backend-api/api-reference/error-responses#INVALID_VALUE"
        }
      },
      {
        "method": "delete",
        "object": {
          "type": "asset",
          "id": "efa3886d-d9a6-4383-a2c0-c7e28a6c21d0"
        },
        "success": false,
        "error": {
          "type": "OBJECT_NOT_FOUND",
          "title": "Object not found.",
          "detail": "No aseset found with ID: 'efa3886d-d9a6-4383-a2c0-c7e28a6c21d0'",
          "see": "https://docs.journeyapps.com/reference/backend-api/api-reference/error-responses#OBJECT_NOT_FOUND"
        }
      }
    ]
}
```

### **Example**

```json
{
  "operations": [
      {
        "method": "put",
        "object": {
          "type": "asset",
          "id": "eacb4836-f1b9-11e1-9750-001cc01904e3",
          "make": "Samsung"
        }
      },
      {
        "method": "patch",
        "object": {
          "type": "asset",
          "id": "44218dfe-7c3f-11e2-95e1-0026189d9dc0",
          "make": "Nokia"
        }
      },
      {
        "method": "delete",
        "object": {
          "type": "asset",
          "id": "efa3886d-d9a6-4383-a2c0-c7e28a6c21d0"
        }
      }
  ]
}
```

#### **Stop on error**

```json
{
  "stop_on_error": true,
  "operations": [
      {
        "method": "put",
        "object": {
          "type": "asset",
          "id": "eacb4836-f1b9-11e1-9750-001cc01904e3"
        },
        "success": true
      },
      {
        "method": "patch",
        "object": {
          "type": "asset",
          "id": "44218dfe-7c3f-11e2-95e1-0026189d9dc0",
          "make": "adsghjsd"
        },
        "success": false,
        "error": {
          "type": "INVALID_VALUE",
          "title": "Invalid value specified.",
          "detail": "Invalid option \"adsghjsd\" for field 'make'.",
          "see": "https://docs.journeyapps.com/reference/backend-api/api-reference/error-responses#INVALID_VALUE"
        }
      },
      {
        "method": "delete",
        "object": {
          "type": "asset",
          "id": "efa3886d-d9a6-4383-a2c0-c7e28a6c21d0"
        },
        "success": false,
        "error": {
          "type": "BATCH_ABORTED",
          "title": "Batch processing aborted due to error.",
          "detail": "Skipping this operation because a previous operation in this batch failed.",
          "see": "https://docs.journeyapps.com/reference/backend-api/api-reference/error-responses#BATCH_ABORTED"
        }
      }
    ]
}
```
