# Write a batch of changes

`POST https://data.inovacc.dev/v1/databases/{database}/batch`

Apply up to 100 creates, updates and deletes in one transaction: all of them, or none.

## Path params

- `database` (string), required: The database key.

## Body params

- `ops` (array), required: 1 to 100 operations, applied in order inside one transaction. The first failure is the answer and nothing is kept.
- `ops[].op` ("create" | "update" | "delete"), required: What the operation does. Each operation is checked against the collection's rule for it.
- `ops[].collection` (string), required: The collection the operation applies to.
- `ops[].id` (string): The record id: your own for a create, the existing one for an update or a delete.
- `ops[].version` (integer): The record version an update or a delete applies to.
- `ops[].data` (object): The fields of a create or an update.

## Headers

- `Authorization` (string), required: Bearer <API key>
- `Content-Type` (string), required: application/json, on a call with a body

## Request

**cURL**

```sh
curl -X POST "https://data.inovacc.dev/v1/databases/{database}/batch" \
  -H "Authorization: Bearer $INOVACC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "ops": [
    {
      "op": "create",
      "collection": "items",
      "data": {
        "owner": "user_123",
        "body": "Buy milk"
      }
    },
    {
      "op": "delete",
      "collection": "items",
      "id": "rec_01JCA2B7KM4N9P3Q5R8S6T1V0W",
      "version": 3
    }
  ]
}'
```

**TypeScript**

```ts
const body: Record<string, unknown> = {
  "ops": [
    {
      "op": "create",
      "collection": "items",
      "data": {
        "owner": "user_123",
        "body": "Buy milk"
      }
    },
    {
      "op": "delete",
      "collection": "items",
      "id": "rec_01JCA2B7KM4N9P3Q5R8S6T1V0W",
      "version": 3
    }
  ]
};

const url = "https://data.inovacc.dev/v1/databases/{database}/batch";

const response = await fetch(url, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.INOVACC_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(body),
});

console.log(response.status, await response.text());
```

**Python**

```py
import json
import os
import urllib.request

body = {
    "ops": [
        {
            "op": "create",
            "collection": "items",
            "data": {
                "owner": "user_123",
                "body": "Buy milk",
            },
        },
        {
            "op": "delete",
            "collection": "items",
            "id": "rec_01JCA2B7KM4N9P3Q5R8S6T1V0W",
            "version": 3,
        },
    ],
}

request = urllib.request.Request(
    "https://data.inovacc.dev/v1/databases/{database}/batch",
    data=json.dumps(body).encode(),
    method="POST",
    headers={
        "User-Agent": "inovacc-python-sample",
        "Authorization": "Bearer " + os.environ["INOVACC_API_KEY"],
        "Content-Type": "application/json",
    },
)

with urllib.request.urlopen(request) as response:
    print(response.status, response.read().decode())
```

**Go**

```go
package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
	"strings"
)

const url = "https://data.inovacc.dev/v1/databases/{database}/batch"

const body = `{
  "ops": [
    {
      "op": "create",
      "collection": "items",
      "data": {
        "owner": "user_123",
        "body": "Buy milk"
      }
    },
    {
      "op": "delete",
      "collection": "items",
      "id": "rec_01JCA2B7KM4N9P3Q5R8S6T1V0W",
      "version": 3
    }
  ]
}`

func main() {
	req, err := http.NewRequest("POST", url, strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Authorization", "Bearer "+os.Getenv("INOVACC_API_KEY"))
	req.Header.Set("Content-Type", "application/json")

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()

	out, err := io.ReadAll(res.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(res.Status, string(out))
}
```

**Rust**

```rs
// Cargo.toml: reqwest = { version = "0.12", features = ["blocking", "json"] }
// Cargo.toml: serde_json = "1"

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let api_key = std::env::var("INOVACC_API_KEY")?;
    let body = serde_json::json!({
        "ops": [
            {
                "op": "create",
                "collection": "items",
                "data": {
                    "owner": "user_123",
                    "body": "Buy milk"
                }
            },
            {
                "op": "delete",
                "collection": "items",
                "id": "rec_01JCA2B7KM4N9P3Q5R8S6T1V0W",
                "version": 3
            }
        ]
    });
    let response = reqwest::blocking::Client::new()
        .post("https://data.inovacc.dev/v1/databases/{database}/batch")
        .bearer_auth(api_key)
        .json(&body)
        .send()?;
    println!("{} {}", response.status(), response.text()?);
    Ok(())
}
```

**JavaScript**

```mjs
const body = {
  "ops": [
    {
      "op": "create",
      "collection": "items",
      "data": {
        "owner": "user_123",
        "body": "Buy milk"
      }
    },
    {
      "op": "delete",
      "collection": "items",
      "id": "rec_01JCA2B7KM4N9P3Q5R8S6T1V0W",
      "version": 3
    }
  ]
};

const url = "https://data.inovacc.dev/v1/databases/{database}/batch";

const response = await fetch(url, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.INOVACC_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(body),
});

console.log(response.status, await response.text());
```

**PHP**

```php
<?php

$body = <<<'JSON'
{
  "ops": [
    {
      "op": "create",
      "collection": "items",
      "data": {
        "owner": "user_123",
        "body": "Buy milk"
      }
    },
    {
      "op": "delete",
      "collection": "items",
      "id": "rec_01JCA2B7KM4N9P3Q5R8S6T1V0W",
      "version": 3
    }
  ]
}
JSON;

$curl = curl_init('https://data.inovacc.dev/v1/databases/{database}/batch');
curl_setopt_array($curl, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('INOVACC_API_KEY'),
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => $body,
]);

$response = curl_exec($curl);
echo curl_getinfo($curl, CURLINFO_HTTP_CODE), ' ', $response, "\n";
curl_close($curl);
```

**Ruby**

```rb
require "net/http"
require "uri"

uri = URI('https://data.inovacc.dev/v1/databases/{database}/batch')
body = <<~'JSON'
{
  "ops": [
    {
      "op": "create",
      "collection": "items",
      "data": {
        "owner": "user_123",
        "body": "Buy milk"
      }
    },
    {
      "op": "delete",
      "collection": "items",
      "id": "rec_01JCA2B7KM4N9P3Q5R8S6T1V0W",
      "version": 3
    }
  ]
}
JSON

request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer #{ENV.fetch('INOVACC_API_KEY')}"
request["Content-Type"] = "application/json"
request.body = body

response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
  http.request(request)
end

puts "#{response.code} #{response.body}"
```

**Java**

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        String apiKey = System.getenv("INOVACC_API_KEY");
        String body = "{" +
                "\"ops\": [" +
                "{" +
                "\"op\": \"create\"," +
                "\"collection\": \"items\"," +
                "\"data\": {" +
                "\"owner\": \"user_123\"," +
                "\"body\": \"Buy milk\"" +
                "}" +
                "}," +
                "{" +
                "\"op\": \"delete\"," +
                "\"collection\": \"items\"," +
                "\"id\": \"rec_01JCA2B7KM4N9P3Q5R8S6T1V0W\"," +
                "\"version\": 3" +
                "}" +
                "]" +
                "}";

        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create("https://data.inovacc.dev/v1/databases/{database}/batch"))
                .header("Authorization", "Bearer " + apiKey)
                .header("Content-Type", "application/json")
                .method("POST", HttpRequest.BodyPublishers.ofString(body))
                .build();

        HttpResponse<String> response = HttpClient.newHttpClient()
                .send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.statusCode() + " " + response.body());
    }
}
```

**C#**

```cs
using System.Text;

var body = "{" +
    "\"ops\": [" +
    "{" +
    "\"op\": \"create\"," +
    "\"collection\": \"items\"," +
    "\"data\": {" +
    "\"owner\": \"user_123\"," +
    "\"body\": \"Buy milk\"" +
    "}" +
    "}," +
    "{" +
    "\"op\": \"delete\"," +
    "\"collection\": \"items\"," +
    "\"id\": \"rec_01JCA2B7KM4N9P3Q5R8S6T1V0W\"," +
    "\"version\": 3" +
    "}" +
    "]" +
    "}";

var url = "https://data.inovacc.dev/v1/databases/{database}/batch";
var apiKey = Environment.GetEnvironmentVariable("INOVACC_API_KEY");

using var client = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Post, url);
request.Headers.Add("Authorization", $"Bearer {apiKey}");
request.Content = new StringContent(body, Encoding.UTF8, "application/json");

using var response = await client.SendAsync(request);
Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");
```

**Kotlin**

```kt
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse

fun main() {
    val apiKey = System.getenv("INOVACC_API_KEY")
    val body = "{" +
        "\"ops\": [" +
        "{" +
        "\"op\": \"create\"," +
        "\"collection\": \"items\"," +
        "\"data\": {" +
        "\"owner\": \"user_123\"," +
        "\"body\": \"Buy milk\"" +
        "}" +
        "}," +
        "{" +
        "\"op\": \"delete\"," +
        "\"collection\": \"items\"," +
        "\"id\": \"rec_01JCA2B7KM4N9P3Q5R8S6T1V0W\"," +
        "\"version\": 3" +
        "}" +
        "]" +
        "}"

    val request = HttpRequest.newBuilder()
        .uri(URI.create("https://data.inovacc.dev/v1/databases/{database}/batch"))
        .header("Authorization", "Bearer " + apiKey)
        .header("Content-Type", "application/json")
        .method("POST", HttpRequest.BodyPublishers.ofString(body))
        .build()

    val response = HttpClient.newHttpClient()
        .send(request, HttpResponse.BodyHandlers.ofString())
    println("${response.statusCode()} ${response.body()}")
}
```

**Swift**

```swift
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

let body = #"""
{
  "ops": [
    {
      "op": "create",
      "collection": "items",
      "data": {
        "owner": "user_123",
        "body": "Buy milk"
      }
    },
    {
      "op": "delete",
      "collection": "items",
      "id": "rec_01JCA2B7KM4N9P3Q5R8S6T1V0W",
      "version": 3
    }
  ]
}
"""#

let apiKey = ProcessInfo.processInfo.environment["INOVACC_API_KEY"] ?? ""

let url = URL(string: "https://data.inovacc.dev/v1/databases/{database}/batch")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = Data(body.utf8)

let (data, response) = try await URLSession.shared.data(for: request)
let status = (response as? HTTPURLResponse)?.statusCode ?? 0
print(status, String(decoding: data, as: UTF8.self))
```

## Response

**200**

```json
{
  "results": [
    {
      "id": "rec_01JCA4X9QY7M2KZ3N8PB5RT6VW",
      "version": 1,
      "created_at": "2026-10-06T12:00:00.000Z",
      "updated_at": "2026-10-06T12:00:00.000Z",
      "owner": "user_123",
      "body": "Buy milk"
    },
    {
      "id": "rec_01JCA2B7KM4N9P3Q5R8S6T1V0W",
      "deleted": true
    }
  ]
}
```

**400**: invalid_body, batch_too_large, cross_shard_batch

**401**: invalid_credentials

**403**: forbidden

**404**: database_not_found, record_not_found

**409**: version_conflict, already_exists, unique_violation

**429**: rate_limited

**503**: service_unavailable

## See also

- [Authentication](https://developer.inovacc.dev/en/guides/authentication/)
- [Errors](https://developer.inovacc.dev/en/guides/errors/)
- [Limits](https://developer.inovacc.dev/en/guides/limits/)
