> 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/point-balances/batch
Content-Type: application/json

批次覆蓋多個客戶的點數餘額，逐筆結果互不影響。balance 是絕對餘額，不是增減量——每一筆送出的都是「這個客戶現在總共有多少點」，把異動量當成這個欄位送出會直接把餘額蓋成錯誤的值，這是使用這支端點最需要注意的地方。客戶用 companyCode（貴端的客戶代碼）指定，不是 OrderUp 的內部序號。送出空陣列或沒有 body 會在受理前被拒絕，回傳 400 empty_batch；已受理的請求一律回傳 HTTP 200，逐筆的處理結果放在回應 body 的 items 裡，單筆失敗不會讓其他筆一起失敗。逐筆狀態是小寫的 ok 或 failed，與商品／規格批次端點的 created／updated／failed 不同——餘額同步是絕對值覆寫，沒有新增與更新之分，這點與庫存批次端點相同。

Reference: https://docs.orderupb2b.com/api-reference/point-balances/batch-sync-point-balances

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

### Body (application/json)

This endpoint expects a list of object.

- `list of object`
  - `companyCode` (string, optional, nullable) — 貴端系統的客戶代碼，對應客戶主檔的 outerSysCode。這支端點只認代碼、不收 OrderUp 的內部客戶序號。代碼查無對應客戶時，這一筆回報 failed 並帶 company_not_found；同一個代碼對應到多筆客戶時回報 failed 並帶 company_code_ambiguous，OrderUp 不會替你在其中挑一筆——挑錯就等於把甲客戶的點數寫到乙客戶頭上。
  - `balance` (double, optional) — 這個客戶當下的絕對點數餘額，不是增減量。必須大於或等於 0，負值會讓該筆回報 failed 並帶 invalid_balance。

## Response

### 200

OK

- `items` (list of object, optional, nullable) — 逐筆的處理結果，順序與送出的陣列相同，一筆對一筆。
  - `companyCode` (string, optional, nullable) — 原樣回傳你送進來的客戶代碼，用來比對是哪一筆。
  - `status` (string, optional, nullable) — 這一筆的處理結果，小寫的 ok 或 failed。與商品／規格批次端點的 created／updated／failed 不同，兩者不可混用。
  - `error` (string, optional, nullable) — 失敗原因代碼，成功時為 null。可能的值：company_code_required（沒有帶 companyCode）、company_not_found（查無此代碼的有效客戶）、company_code_ambiguous（同一代碼對應到多筆客戶，OrderUp 不會替你挑）、invalid_balance（餘額為負）、sync_failed（寫入時發生非預期錯誤）。

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

**Request**

```json
[
  {}
]
```

**Response**

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

**SDK Code**

```python
import requests

url = "https://api.example.com/v1/point-balances/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/point-balances/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/point-balances/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/point-balances/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/point-balances/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/point-balances/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/point-balances/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/point-balances/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()
```