---
title: Update a book
description: Update fields on an existing book.
url: "https://cbotai.shahrear.msf.bd/docs/update-a-book/"
updated: "2026-08-16"
category: Bookstore API (Sample) / Books
---

# Update a book

PUT`/books/{bookid}`

## Code Samples

```curl

                curl --request PUT \
  --url 'https://api.bookstore.example.com/v1/books/{bookid}' \
  --header 'X-API-Key: YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "price": 19.99,
    "in_stock": false
}'

                const response = await fetch('https://api.bookstore.example.com/v1/books/{bookid}', {
  method: 'PUT',
  headers: {
    'X-API-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    "price": 19.99,
    "in_stock": false
})
});

const data = await response.json();
console.log(data);

                import requests

headers = {
    "X-API-Key": "YOUR_API_KEY",
    "Content-Type": "application/json"
}

payload = {
    "price": 19.99,
    "in_stock": false
}

response = requests.put("https://api.bookstore.example.com/v1/books/{bookid}", headers=headers, json=payload)

print(response.json())

                <?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://api.bookstore.example.com/v1/books/{bookid}',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'PUT',
  CURLOPT_HTTPHEADER => [
  'X-API-Key: YOUR_API_KEY',
  'Content-Type: application/json'
  ],
  CURLOPT_POSTFIELDS => '{
    "price": 19.99,
    "in_stock": false
}',
]);

$response = curl_exec($curl);
curl_close($curl);

echo $response;

                using System.Net.Http;
using System.Text;

var client = new HttpClient();
var request = new HttpRequestMessage(new HttpMethod("PUT"), "https://api.bookstore.example.com/v1/books/{bookid}");
request.Headers.Add("X-API-Key", "YOUR_API_KEY");
request.Content = new StringContent(@"{
    ""price"": 19.99,
    ""in_stock"": false
}", Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);

                import java.net.URI;
import java.net.http.*;

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.bookstore.example.com/v1/books/{bookid}"))
    .header("X-API-Key", "YOUR_API_KEY")
    .header("Content-Type", "application/json")
    .method("PUT", HttpRequest.BodyPublishers.ofString("""
{
    "price": 19.99,
    "in_stock": false
}
"""))
    .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

Update fields on an existing book.

## Path Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `bookid` | string | **Required** |  |

## Request Body

Content type: `application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `price` | number | Optional |  |
| `in_stock` | boolean | Optional |  |

```json

                {
    "price": 19.99,
    "in_stock": false
}
```

## Responses

### 200 — Successful response
