> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.orderupb2b.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.orderupb2b.com/_mcp/server.

# 批次更新組合品庫存

POST https://api.example.com/v1/bundles/stock/batch
Content-Type: application/json

批次覆蓋多個組合品自身的在庫數，一次寫入多筆，逐筆結果互不影響。

⚠️ **`inventoryQuantity` 是絕對的在庫數，不是增減量**，規則與 POST /v1/skus/stock/batch 相同。

每一筆用 `bundleId`（組合 SKU 序號）指定組合品，不接受料號。`inventoryQuantity` 與 `isNegativeStockAllowed` 都是選填，省略的欄位維持現值——**沒帶 `inventoryQuantity` 不會被當成 0**，在庫數不變、也不留異動紀錄。兩個欄位都沒帶時，該筆 failed，error 為 inventoryQuantity or isNegativeStockAllowed is required。

送出空陣列或沒有 body 會在受理前被拒絕，回傳 400 empty_batch；已受理的請求一律回傳 HTTP 200，逐筆結果依請求順序放在 `items`，一筆請求一列。`bundleId` 不存在、屬於其他租戶，或指向一般規格時，該筆回報 failed 並帶 bundle not found，不影響其他筆。逐筆狀態是小寫的 ok 或 failed。

Reference: https://docs.orderupb2b.com/api-規格/bundle-stock/batch-update-bundle-stock

## Authentication

- `X-Signature` header (required) — 每個 /v1 請求都必須帶 `X-Client-Id`、`X-Timestamp`、`X-Nonce` 與 `X-Signature` 四個標頭。`X-Signature` 是以 client secret 對 canonical string 做 HMAC-SHA256 後的 Base64。 canonical string 的組成、可複製的簽章範例與 401 排查步驟，請參閱[「驗證與簽章」](/authentication)。

## Request

### Body (application/json)

This endpoint expects a list of BundleStockUpsertRequest.

- `list of BundleStockUpsertRequest`

## Response

### 200

OK

- `items` (list of BundleStockBatchItemResult, optional, nullable) — 逐筆的處理結果，依請求順序排列，筆數與送出的筆數相同。

## Errors

### 400 Bad Request Error

Bad Request

- `error` (string, optional, nullable) — 錯誤代碼，固定為 snake_case 字串，依代碼判斷失敗原因。

### 401 Unauthorized Error

Unauthorized

- `error` (string, optional, nullable) — 錯誤代碼，固定為 snake_case 字串，依代碼判斷失敗原因。

### 403 Forbidden Error

Forbidden

- `error` (string, optional, nullable) — 錯誤代碼，固定為 snake_case 字串，依代碼判斷失敗原因。

### 500 Internal Server Error

Internal Server Error

- `code` (string, optional, nullable) — 錯誤代碼字串。
- `message` (string, optional, nullable) — 對應的錯誤說明文字。

## Types

### BundleStockUpsertRequest

設定組合品自身庫存的請求內容，是 POST /v1/bundles/stock/batch 陣列中的一筆。inventoryQuantity 是絕對的在庫數，不是增減量；inventoryQuantity 與 isNegativeStockAllowed 至少要帶一個，省略的欄位維持現值。

- `bundleId` (long, optional) — 要設定庫存的組合 SKU 序號。不存在、屬於其他租戶，或指向一般規格時，這一筆回報 failed，error 為 bundle not found。
- `inventoryQuantity` (double, optional, nullable) — 選填。更新後組合品自身的絕對在庫數，不是增減量。省略時在庫數維持現值（不會被當成 0）；與 `isNegativeStockAllowed` 都省略時該筆 failed。
- `isNegativeStockAllowed` (boolean, optional, nullable) — 選填。true 時組合品自身不限量，只看組成規格；false 時組合品自身的可售數用完就不能再下單。省略時維持現值。

### BundleStockBatchItemResult

組合品庫存批次裡一筆的處理結果。

- `bundleId` (long, optional) — 這一筆請求的組合 SKU 序號，原樣帶回。
- `status` (string, optional, nullable) — 這一筆的結果，只有兩種小寫值：ok（成功）或 failed（失敗，原因見 error）。
- `error` (string, optional, nullable) — 失敗時的錯誤說明，例如 bundle not found；成功時為 null。

## Examples

**Request**

```json
[
  {}
]
```

**Response**

```json
{
  "items": [
    {
      "bundleId": 1,
      "status": "string",
      "error": "string"
    }
  ]
}
```

**SDK Code**

```python
import requests

url = "https://api.example.com/v1/bundles/stock/batch"

payload = [{}]
headers = {
    "X-Signature": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.example.com/v1/bundles/stock/batch';
const options = {
  method: 'POST',
  headers: {'X-Signature': '<apiKey>', 'Content-Type': 'application/json'},
  body: '[{}]'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

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

func main() {

	url := "https://api.example.com/v1/bundles/stock/batch"

	payload := strings.NewReader("[\n  {}\n]")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("X-Signature", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.example.com/v1/bundles/stock/batch")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["X-Signature"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "[\n  {}\n]"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.example.com/v1/bundles/stock/batch")
  .header("X-Signature", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("[\n  {}\n]")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.example.com/v1/bundles/stock/batch', [
  'body' => '[
  {}
]',
  'headers' => [
    'Content-Type' => 'application/json',
    'X-Signature' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.example.com/v1/bundles/stock/batch");
var request = new RestRequest(Method.POST);
request.AddHeader("X-Signature", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "[\n  {}\n]", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "X-Signature": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [[]] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/v1/bundles/stock/batch")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```