---
title: "POST /v1/projects/{projectsId}/instances/{instancesId}/databases/{databasesId}/sessions/{sessionsId}:batchWrite"
method: POST
path: "/v1/projects/{projectsId}/instances/{instancesId}/databases/{databasesId}/sessions/{sessionsId}:batchWrite"
tags: ["projects"]
---

# POST /v1/projects/{projectsId}/instances/{instancesId}/databases/{databasesId}/sessions/{sessionsId}:batchWrite

`POST /v1/projects/{projectsId}/instances/{instancesId}/databases/{databasesId}/sessions/{sessionsId}:batchWrite`

## Request

- Base URL: `https://spanner.googleapis.com`
- URL: `https://spanner.googleapis.com/v1/projects/{projectsId}/instances/{instancesId}/databases/{databasesId}/sessions/{sessionsId}:batchWrite`
- Auth: one of:
  - OAuth 2 and OAuth 2
    - Implicit: `https://accounts.google.com/o/oauth2/auth`
    - Scopes: `https://www.googleapis.com/auth/cloud-platform`
    - Authorization code: `https://accounts.google.com/o/oauth2/auth`
    - Token URL: `https://accounts.google.com/o/oauth2/token` scopes: `https://www.googleapis.com/auth/cloud-platform`
  - OAuth 2 and OAuth 2
    - Implicit: `https://accounts.google.com/o/oauth2/auth`
    - Scopes: `https://www.googleapis.com/auth/spanner.data`
    - Authorization code: `https://accounts.google.com/o/oauth2/auth`
    - Token URL: `https://accounts.google.com/o/oauth2/token` scopes: `https://www.googleapis.com/auth/spanner.data`

Batches the supplied mutation groups in a collection of efficient transactions. All mutations in a group are committed atomically. However, mutations across groups can be committed non-atomically in an unspecified order and thus, they must be independent of each other. Partial failure is possible, that is, some groups might have been committed successfully, while some might have failed. The results of individual batches are streamed into the response as the batches are applied. `BatchWrite` requests are not replay protected, meaning that each mutation group can be applied more than once. Replays of non-idempotent mutations can have undesirable effects. For example, replays of an insert mutation can produce an already exists error or if you use generated or commit timestamp-based keys, it can result in additional rows being added to the mutation's table. We recommend structuring your mutation groups to be idempotent to avoid this issue.

## Path parameters

- `projectsId` string, required
- `instancesId` string, required
- `databasesId` string, required
- `sessionsId` string, required

## Query parameters

- `$.xgafv` '1' | '2'
- `access_token` string
- `alt` 'json' | 'media' | 'proto'
- `callback` string
- `fields` string
- `key` string
- `oauth_token` string
- `prettyPrint` boolean
- `quotaUser` string
- `uploadType` string
- `upload_protocol` string

## Request body

- BatchWriteRequest: The request for BatchWrite.
  - `excludeTxnFromChangeStreams` boolean: Optional. For change streams monitoring columns modified by transactions, when `exclude_txn_from_change_streams` is set to `true`, two scenarios are possible: * If the DDL option `allow_txn_exclusion` is set to `true`, then the updates made within all transactions in this batch write aren't recorded in the change stream. * If you don't set the DDL option `allow_txn_exclusion` or if it's set to `false`, then the updates made within this transaction are recorded in the change stream. If you don't set the `exclude_txn_from_change_streams` option or if it's set to `false`, then any change streams monitoring columns modified by transactions will capture the updates made within that transaction.
  - `mutationGroups` MutationGroup[]: Required. The groups of mutations to be applied.
    - `mutations` Mutation[]: Required. The mutations in this group.
      - `ack` Ack: Arguments to ack operations.
        - `ignoreNotFound` boolean: By default, an attempt to ack a message that does not exist will fail with a `NOT_FOUND` error. With `ignore_not_found` set to true, the ack will succeed even if the message does not exist. This is useful for unconditionally acking a message, even if it is missing or has already been acked.
        - `key` unknown[]: Required. The primary key of the message to be acked.
          - unknown
        - `queue` string: Required. The queue where the message to be acked is stored.
      - `delete` Delete: Arguments to delete operations.
        - `keySet` KeySet: `KeySet` defines a collection of Cloud Spanner keys and/or key ranges. All the keys are expected to be in the same table or index. The keys need not be sorted in any particular way. If the same key is specified multiple times in the set (for example if two ranges, two keys, or a key and a range overlap), Cloud Spanner behaves as if the key were only specified once.
          - `all` boolean: For convenience `all` can be set to `true` to indicate that this `KeySet` matches all keys in the table or index. Note that any keys specified in `keys` or `ranges` are only yielded once.
          - `keys` array[]: A list of specific keys. Entries in `keys` should have exactly as many elements as there are columns in the primary or index key with which this `KeySet` is used. Individual key values are encoded as described here.
            - unknown[]
              - …
          - `ranges` KeyRange[]: A list of key ranges. See KeyRange for more information about key range specifications.
            - `endClosed` unknown[]: If the end is closed, then the range includes all rows whose first `len(end_closed)` key columns exactly match `end_closed`.
              - …
            - `endOpen` unknown[]: If the end is open, then the range excludes rows whose first `len(end_open)` key columns exactly match `end_open`.
              - …
            - `startClosed` unknown[]: If the start is closed, then the range includes all rows whose first `len(start_closed)` key columns exactly match `start_closed`.
              - …
            - `startOpen` unknown[]: If the start is open, then the range excludes rows whose first `len(start_open)` key columns exactly match `start_open`.
              - …
        - `table` string: Required. The table whose rows will be deleted.
      - `insert` Write: Arguments to insert, update, insert_or_update, and replace operations.
        - `columns` string[]: The names of the columns in table to be written. The list of columns must contain enough columns to allow Cloud Spanner to derive values for all primary key columns in the row(s) to be modified.
        - `table` string: Required. The table whose rows will be written.
        - `values` array[]: The values to be written. `values` can contain more than one list of values. If it does, then multiple rows are written, one for each entry in `values`. Each list in `values` must have exactly as many entries as there are entries in columns above. Sending multiple lists is equivalent to sending multiple `Mutation`s, each containing one `values` entry and repeating table and columns. Individual values in each list are encoded as described here.
          - unknown[]
            - unknown
      - `insertOrUpdate` Write: Arguments to insert, update, insert_or_update, and replace operations.
        - `columns` string[]: The names of the columns in table to be written. The list of columns must contain enough columns to allow Cloud Spanner to derive values for all primary key columns in the row(s) to be modified.
        - `table` string: Required. The table whose rows will be written.
        - `values` array[]: The values to be written. `values` can contain more than one list of values. If it does, then multiple rows are written, one for each entry in `values`. Each list in `values` must have exactly as many entries as there are entries in columns above. Sending multiple lists is equivalent to sending multiple `Mutation`s, each containing one `values` entry and repeating table and columns. Individual values in each list are encoded as described here.
          - unknown[]
            - unknown
      - `replace` Write: Arguments to insert, update, insert_or_update, and replace operations.
        - `columns` string[]: The names of the columns in table to be written. The list of columns must contain enough columns to allow Cloud Spanner to derive values for all primary key columns in the row(s) to be modified.
        - `table` string: Required. The table whose rows will be written.
        - `values` array[]: The values to be written. `values` can contain more than one list of values. If it does, then multiple rows are written, one for each entry in `values`. Each list in `values` must have exactly as many entries as there are entries in columns above. Sending multiple lists is equivalent to sending multiple `Mutation`s, each containing one `values` entry and repeating table and columns. Individual values in each list are encoded as described here.
          - unknown[]
            - unknown
      - `send` Send: Arguments to send operations.
        - `deliverTime` string, google-datetime: The time at which Spanner will begin attempting to deliver the message. If `deliver_time` is not set, Spanner will deliver the message immediately. If `deliver_time` is in the past, Spanner will replace it with a value closer to the current time.
        - `key` unknown[]: Required. The primary key of the message to be sent.
          - unknown
        - `payload` unknown
        - `queue` string: Required. The queue to which the message will be sent.
      - `update` Write: Arguments to insert, update, insert_or_update, and replace operations.
        - `columns` string[]: The names of the columns in table to be written. The list of columns must contain enough columns to allow Cloud Spanner to derive values for all primary key columns in the row(s) to be modified.
        - `table` string: Required. The table whose rows will be written.
        - `values` array[]: The values to be written. `values` can contain more than one list of values. If it does, then multiple rows are written, one for each entry in `values`. Each list in `values` must have exactly as many entries as there are entries in columns above. Sending multiple lists is equivalent to sending multiple `Mutation`s, each containing one `values` entry and repeating table and columns. Individual values in each list are encoded as described here.
          - unknown[]
            - unknown
  - `requestOptions` RequestOptions: Common request options for various APIs.
    - `clientContext` ClientContext: Container for various pieces of client-owned context attached to a request.
      - `secureContext` object: Optional. Map of parameter name to value for this request. These values will be returned by any SECURE_CONTEXT() calls invoked by this request (e.g., by queries against Parameterized Secure Views).
    - `priority` 'PRIORITY_UNSPECIFIED' | 'PRIORITY_LOW' | 'PRIORITY_MEDIUM' | 'PRIORITY_HIGH': Priority for the request.
    - `requestTag` string: A per-request tag which can be applied to queries or reads, used for statistics collection. Both `request_tag` and `transaction_tag` can be specified for a read or query that belongs to a transaction. This field is ignored for requests where it's not applicable (for example, `CommitRequest`). Legal characters for `request_tag` values are all printable characters (ASCII 32 - 126) and the length of a request_tag is limited to 50 characters. Values that exceed this limit are truncated. Any leading underscore (_) characters are removed from the string.
    - `transactionTag` string: A tag used for statistics collection about this transaction. Both `request_tag` and `transaction_tag` can be specified for a read or query that belongs to a transaction. To enable tagging on a transaction, `transaction_tag` must be set to the same value for all requests belonging to the same transaction, including BeginTransaction. If this request doesn't belong to any transaction, `transaction_tag` is ignored. Legal characters for `transaction_tag` values are all printable characters (ASCII 32 - 126) and the length of a `transaction_tag` is limited to 50 characters. Values that exceed this limit are truncated. Any leading underscore (_) characters are removed from the string.

## Response `200`

Successful response

- BatchWriteResponse: The result of applying a batch of mutations.
  - `commitTimestamp` string, google-datetime: The commit timestamp of the transaction that applied this batch. Present if status is OK and the mutation groups were applied, absent otherwise. For mutation groups with conditions, a status=OK and missing commit_timestamp means that the mutation groups were not applied due to the condition not being satisfied after evaluation.
  - `indexes` integer[]: The mutation groups applied in this batch. The values index into the `mutation_groups` field in the corresponding `BatchWriteRequest`.
  - `status` Status: The `Status` type defines a logical error model that is suitable for different programming environments, including REST APIs and RPC APIs. It is used by [gRPC](https://github.com/grpc). Each `Status` message contains three pieces of data: error code, error message, and error details. You can find out more about this error model and how to work with it in the [API Design Guide](https://cloud.google.com/apis/design/errors).
    - `code` integer: The status code, which should be an enum value of google.rpc.Code.
    - `details` object[]: A list of messages that carry the error details. There is a common set of message types for APIs to use.
    - `message` string: A developer-facing error message, which should be in English. Any user-facing error message should be localized and sent in the google.rpc.Status.details field, or localized by the client.

## Changes

- **2026-12-05** `a7213b86b5d7`: 4 info
  - the security scope `https://www.googleapis.com/auth/cloud-platform` was added to the endpoint's security scheme `Oauth2`
  - the security scope `https://www.googleapis.com/auth/cloud-platform` was added to the endpoint's security scheme `Oauth2c`
  - the security scope `https://www.googleapis.com/auth/spanner.data` was removed from the endpoint's security scheme `Oauth2`
  - the security scope `https://www.googleapis.com/auth/spanner.data` was removed from the endpoint's security scheme `Oauth2c`
- **2026-11-20** `54a0040f5251`: 4 info
  - the security scope `https://www.googleapis.com/auth/cloud-platform` was added to the endpoint's security scheme `Oauth2`
  - the security scope `https://www.googleapis.com/auth/cloud-platform` was added to the endpoint's security scheme `Oauth2c`
  - the security scope `https://www.googleapis.com/auth/spanner.data` was removed from the endpoint's security scheme `Oauth2`
  - the security scope `https://www.googleapis.com/auth/spanner.data` was removed from the endpoint's security scheme `Oauth2c`

[Operation history](https://skmtc.dev/google/apis/spanner/changes/v1/projects/:projectsId/instances/:instancesId/databases/:databasesId/sessions/:sessionsId:batchWrite/post.md)

---

[API](https://skmtc.dev/google/apis/spanner.md) - [All operations](https://skmtc.dev/google/apis/spanner/llms.txt) - [OpenAPI document](https://skmtc.dev/google/apis/spanner/revisions/a7213b86b5d7?raw)
