---
id: UpdateBook
name: Update book
version: 1.0.0
badges:
  - content: Catalog Management
    backgroundColor: green
    textColor: green
summary: Updates an existing book listing, including optional image and catalog relationships.
owners:
  - catalog-experience-team
schemaPath: schema.json
operation:
  method: PUT
  path: /api/v1/books
  statusCodes: ["204", "400", "404"]
sidebar:
  badge: "PUT"
---

`UpdateBook` replaces the full metadata, pricing, relationships, and optional cover image of an existing book in [[service|catalog-api]] (`PUT /catalog/api/v1/books`) from a `multipart/form-data` payload and returns `204 No Content`. Callers can supply an `If-Match` header with the book's `ETag` to enforce optimistic concurrency control.

## Overview

| Property                           | Value                                                                                                                                                                          |
| :--------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Bounded Context**                | Catalog                                                                                                                                                                        |
| **Owner Service**                  | [[service\|catalog-api]]                                                                                                                                                       |
| **Protocol / Format**              | HTTP `PUT`, `multipart/form-data` request, empty response (`204 No Content`)                                                                                                   |
| **Gateway Endpoint**               | `PUT /catalog/api/v1/books` (service path `/api/v1/books`)                                                                                                                     |
| **Authentication & Authorization** | Microsoft Entra ID JWT — `business_user` policy (role `business_user` or `admin` and scopes `catalog_read`, `catalog_write`)                                                   |
| **Idempotency / Concurrency**      | Optional `If-Match` ETag header for optimistic concurrency (`412 Precondition Failed` on mismatch); idempotent when resubmitting identical fields without a new `image` upload |
| **Rate Limit / Caching**           | Global concurrency (`100`) and fixed-window (`30 req/min`) limiters plus per-user token bucket; invalidates book, summary, list, and search caches                             |
| **Contract Version**               | `1.0.0` (`ApiVersions.V1`)                                                                                                                                                     |

:::note
`PUT /catalog/api/v1/books` is a **full replacement**, not a partial patch. Every request requires `id`, `name`, `price`, `categoryId`, `publisherId`, and `authorIds`; omitting optional fields (`description`, `priceSale`) overwrites them with their defaults (`""` and `null`).
:::

## Request & Response Contract

### Request Headers

| Name            | Type     | Required | Constraints                                                                                            | Description                                             |
| :-------------- | :------- | :------- | :----------------------------------------------------------------------------------------------------- | :------------------------------------------------------ |
| `Authorization` | `string` | Yes      | `Bearer <access-token>`                                                                                | Entra ID JWT satisfying the `business_user` policy      |
| `If-Match`      | `string` | No       | Strong (`"<row-version>"`) or weak (`W/"<row-version>"`) unsigned integer ETag from [[query\|GetBook]] | Expected row version for optimistic concurrency control |

### Request Form Fields (`multipart/form-data`)

| Name            | Type                  | Required | Constraints                                                                                                                                      | Description                                                                          |
| :-------------- | :-------------------- | :------- | :----------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------- |
| `id`            | `string` (`uuid`)     | Yes      | Non-empty UUID                                                                                                                                   | Identifier of the book to replace                                                    |
| `name`          | `string`              | Yes      | Non-empty, max `50` characters                                                                                                                   | Book title                                                                           |
| `description`   | `string`              | No       | Default `""`, max `500` characters                                                                                                               | Book summary text; omitting clears the stored description                            |
| `price`         | `number`              | Yes      | Strictly `> 0` (`numeric(18,2)`)                                                                                                                 | Regular catalog price                                                                |
| `priceSale`     | `number \| null`      | No       | When provided: strictly `> 0` and `<= price`                                                                                                     | Optional promotional sale price; omitting clears any existing sale price             |
| `categoryId`    | `string` (`uuid`)     | Yes      | Non-empty UUID; must reference an existing category                                                                                              | Category identifier                                                                  |
| `publisherId`   | `string` (`uuid`)     | Yes      | Non-empty UUID; must reference an existing publisher                                                                                             | Publisher identifier                                                                 |
| `authorIds`     | `string[]` (`uuid[]`) | Yes      | Non-empty array (`>= 1` UUID); repeat `authorIds` form fields for multiple authors                                                               | Complete replacement list of author identifiers                                      |
| `image`         | `string` (`binary`)   | No       | Max `1,048,576` bytes (1 MB); `image/jpeg` (`.jpg`, `.jpeg`), `image/png` (`.png`), or `image/webp` (`.webp`); extension must match content type | Optional cover image upload replacing the stored cover URN                           |
| `isRemoveImage` | `boolean`             | No       | Default `false`                                                                                                                                  | When `true`, clears the stored cover image reference (takes precedence over `image`) |

## Behavior & Side Effects

- **Optimistic concurrency:** When `If-Match` contains a valid integer ETag, it is checked against the book's current row version; mismatches return `412 Precondition Failed`.
- **Transactional persistence:** Atomically replaces book fields and author associations within a database transaction.
- **Cover image handling:** Uploading `image` stores a new blob in `catalog-blob` and updates the book's image URN; omitting both `image` and `isRemoveImage=true` preserves the existing cover; setting `isRemoveImage=true` clears the stored image reference in PostgreSQL without deleting previously stored blobs.
- **Cache invalidation:** Clears cached book details (`book:{id}`), book summary (`book:summary:{id}`), and invalidates `books:list` and `books:search` cache tags.
- **Vector index queueing:** Database triggers enqueue the book ID for asynchronous Qdrant embedding refresh by [[service|catalog-ingestion]].

## Error Responses

| Status / Code               | Condition                                                                                                                                                                    | Client Recovery Action                                                            |
| :-------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------- |
| `400 Bad Request`           | Validation failure (missing required fields, `price <= 0`, `priceSale <= 0` or `> price`, length exceeded, invalid image size/type/extension) or malformed multipart payload | Fix invalid form fields or file upload; do not retry unchanged input              |
| `401 Unauthorized`          | Missing, expired, or invalid Entra ID JWT                                                                                                                                    | Acquire a valid Entra ID access token and retry                                   |
| `403 Forbidden`             | Token lacks role `business_user` or `admin`, or lacks scopes `catalog_read` and `catalog_write`                                                                              | Request the required Entra ID app role and scopes                                 |
| `404 Not Found`             | No active book exists with the supplied `id`                                                                                                                                 | Verify the book UUID; do not treat `404` as a completed update                    |
| `412 Precondition Failed`   | `If-Match` version does not match the book's current row version                                                                                                             | Fetch the latest book and `ETag` via [[query\|GetBook]], merge changes, and retry |
| `429 Too Many Requests`     | Rate limit quota exceeded (`Retry-After` header included)                                                                                                                    | Wait for the `Retry-After` interval before retrying                               |
| `500 Internal Server Error` | Foreign-key violation, blob storage failure, or unhandled server error (`traceId` included)                                                                                  | Verify referenced IDs exist and inspect service logs using `traceId`              |

## Related Documentation

- [[service|catalog-api]] — Service overview, routing, and authorization policies.
- [[entity|book]] — Book entity model.
- [[command|CreateBook]] — Create a new book listing with multipart upload.
- [[command|DeleteBook]] — Soft-delete an existing book listing.
- [[query|GetBook]] — Retrieve current book details and `ETag`.

<NodeGraph />

<SchemaViewer file="schema.json" title="Update book schema" maxHeight="500" search="true" />


 ## Raw Schema:schema.json

{
	"$schema": "https://json-schema.org/draft/2020-12/schema",
	"title": "UpdateBook",
	"description": "Multipart payload for updating a book listing.",
	"type": "object",
	"additionalProperties": false,
	"required": ["id", "name", "price", "categoryId", "publisherId", "authorIds"],
	"properties": {
		"id": {
			"type": "string",
			"format": "uuid",
			"description": "Book UUID to update."
		},
		"name": {
			"type": "string",
			"minLength": 1
		},
		"description": {
			"type": "string"
		},
		"image": {
			"type": ["string", "null"],
			"contentEncoding": "base64"
		},
		"price": {
			"type": "number",
			"minimum": 0
		},
		"priceSale": {
			"type": ["number", "null"],
			"minimum": 0
		},
		"categoryId": {
			"type": "string",
			"format": "uuid",
			"description": "A UUID identifying the resource."
		},
		"publisherId": {
			"type": "string",
			"format": "uuid",
			"description": "A UUID identifying the resource."
		},
		"authorIds": {
			"type": "array",
			"items": {
				"type": "string",
				"format": "uuid",
				"description": "A UUID identifying the resource."
			}
		},
		"isRemoveImage": {
			"type": "boolean",
			"description": "Remove the existing cover when true."
		}
	}
}
