> 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.

# 查詢商品分類樹

GET https://api.example.com/v1/product-categories

唯讀端點，列出完整的商品分類樹，用於在建立或更新商品前取得有效的 productCategoryId。分頁是以「根分類」為單位：data 最多回傳 pageSize 個根分類，每個根分類底下帶著它的全部子分類，子分類不會被拆到下一頁；totalCount 計算的是根分類的數量，不是分類總數。isAssignable 只有子分類會是 true，商品只能被歸類到子分類，不能歸類到根分類。分類樹只有兩層、根分類數十個，預設分頁通常一次就能取回整棵樹，建議查一次後在你端快取，不需要每次建立商品前都重新查詢。

Reference: https://docs.orderupb2b.com/api-reference/product-categories/list-product-categories

## 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 排查步驟，請參閱「驗證與簽章」。

## Request

### Query parameters

- `Page` (integer, optional) — 頁碼，從 1 起算，省略時預設 1。這支端點的一頁是一頁根分類，不是一頁節點。小於 1 回傳 400 invalid_page；頁碼大到讓內部位移量溢位時同樣回傳 400 invalid_page。
- `PageSize` (integer, optional) — 每頁的根分類筆數上限，範圍 1 至 100，省略時預設 100。每個根分類底下的子分類會跟著一起回傳，不佔用這個額度，所以一頁實際回傳的節點數會比這個數字多。超出範圍一律回傳 400 invalid_page_size，不會自動夾限成合法值。

## Response

### 200

OK

- `data` (list of object, optional, nullable) — 本頁的根分類，每一筆為一個 ProductCategoryResponse，底下已帶著全部子分類。
  - `id` (long, optional) — 分類序號。
  - `name` (string, optional, nullable) — 分類名稱。
  - `isAssignable` (boolean, optional) — 是否可以指派給商品：只有子分類為 true，根分類一律為 false（即使該根分類目前沒有任何子分類）。建立或更新商品時，productCategoryId 只接受這裡標示為 true 的 id。
  - `children` (list of object, optional, nullable) — 這個節點底下的全部子分類。分頁只切根分類，不會把子分類拆頁，所以這裡永遠是完整清單。
- `totalCount` (integer, optional) — 符合條件的根分類總數，不是分類總數，也不受目前頁碼影響。
- `currentPage` (integer, optional) — 目前頁碼，即請求帶入的 page，從 1 起算。
- `pageSize` (integer, optional) — 目前頁面的根分類筆數上限，即請求帶入的 pageSize；實際回傳的節點數會因為子分類而更多。
- `totalPages` (integer, optional) — 總頁數，等於 totalCount（根分類數）除以 pageSize 後無條件進位；沒有符合的資料時為 0。

## 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) — 對應的錯誤說明文字。

## Examples

**Response**

```json
{
  "data": [
    {
      "id": 1,
      "name": "string",
      "isAssignable": true,
      "children": [
        null
      ]
    }
  ],
  "totalCount": 1,
  "currentPage": 1,
  "pageSize": 1,
  "totalPages": 1
}
```

**SDK Code**

```python
import requests

url = "https://api.example.com/v1/product-categories"

headers = {"X-Signature": "<apiKey>"}

response = requests.get(url, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.example.com/v1/product-categories';
const options = {method: 'GET', headers: {'X-Signature': '<apiKey>'}};

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"
	"net/http"
	"io"
)

func main() {

	url := "https://api.example.com/v1/product-categories"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("X-Signature", "<apiKey>")

	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/product-categories")

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

request = Net::HTTP::Get.new(url)
request["X-Signature"] = '<apiKey>'

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.get("https://api.example.com/v1/product-categories")
  .header("X-Signature", "<apiKey>")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://api.example.com/v1/product-categories', [
  'headers' => [
    'X-Signature' => '<apiKey>',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.example.com/v1/product-categories");
var request = new RestRequest(Method.GET);
request.AddHeader("X-Signature", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["X-Signature": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/v1/product-categories")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

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()
```