Skip to main content
This guide explains how to add the Idempotency-Key header to prevent duplicate book creation in the BookHub Publisher API v2. Including a unique Idempotency-Key is required when creating a book with POST /v2/books. For example, if a network error causes you to resend the same request, the idempotency header ensures only one book is created.

Prerequisites

Before you begin, ensure you meet the following prerequisites:
  • Familiarity with the BookHub Publisher API v2.
  • A valid JWT for authentication.
  • Access to your codebase that integrates with the BookHub Publisher API v2.

Step 1: Add the Idempotency-Key header

When you create a new book using the POST /v2/books endpoint, you must include a unique Idempotency-Key header in your create request. The Idempotency-Key must be a UUID. Generate a new one for each distinct book you create. Store the key with the pending request so you can reuse it if the request needs to be retried after a restart or crash.
Reusing the same Idempotency-Key returns the original result instead of creating a second book — this is what makes retries safe. Sending the same book data with a new key is treated as a new create request, and returns 409 Conflict because the ISBN already exists.

Response

A successful request returns a 201 Created response with the details of the newly created book.
Use a unique Idempotency-Key for each distinct book you create — but reuse the same key when retrying a request that may not have completed. The API retains each key for 24 hours. After a key expires, retrying with it is treated as a new create request — which returns 409 Conflict if the book was already created. Generate a new key only when creating a different book.
For error responses including 400, 401, 409, and 429, see Error codes.

201 Created (new book)

If you send the same request again with the same Idempotency-Key, the API returns a 200 OK response with the existing book details. This is expected behavior — not an error. The API recognizes the duplicate request and returns the existing book rather than creating a new one.

200 OK (duplicate request, same key)

Step 2: Test idempotency behavior

To verify your implementation, send the create request multiple times using the same Idempotency-Key. You should see that the API created only one book, with subsequent create requests returning the existing book details. Send the same request three times using the same Idempotency-Key and book_data:
The output should show one 201 Created response followed by two 200 OK responses with the same book details for the repeated create requests.

Error handling

For full error schemas, see Error codes.

Next steps

Explore related topics:

How-to guides

Reference

  • Code examples — Copy code samples for book creation, sorting by creation date, handling removed title sorting, and tracking performance with hitCount.
  • Release notes — Explore all changes in BookHub Publisher API v2.

Last modified on August 18, 2026