> ## Client identification
>
> Requests to this API should include a `Client-Platform` header alongside
> `Authorization`, identifying the application, tool, or model making the
> request. This is used for integration support and analytics.
>
> Use your model or tool name, for example `claude-code` or `chatgpt`.
>
> Example:
>
> ```bash
> curl https://api.salaryboxapp.com/... \
>   -H "Authorization: Api-Key <api-key>" \
>   -H "Client-Platform: claude-code"
> ```

# Update Staff Leave Balance

PUT https://api.salaryboxapp.com/v2/customer/v1/leave/balance
Content-Type: application/json

Sets one staff member's current leave balance, per leave type. Only the leave types sent change. Shared rules: see [Writing data](/conventions#writing-data).

- `salarybox_id` is an active staff member of the company.
- `balances` has at max 50 items, each leave type at most once. `leave_type` is the exact leave type name (case-sensitive) from `GET /leave/balance` or `GET /leave/policy`; system leave types are refused.
- `pending_leaves` is the remaining balance, from -366 to 366 with up to 3 decimals. It **replaces** the current balance, it is not added to it. A negative balance is allowed.
- `carry_forwarded_leaves` is optional, 0-366 with up to 3 decimals. Left out, it stays as it is. Sending a non-zero value needs the Leave Carry Forward plan feature; balances alone work on every plan.
- A leave type that already has a balance must have a leave policy first (`POST /leave/policy`), otherwise `400`. A new balance row on a staff member with no policy gets an ANNUAL policy with 0 allotted.
- Numbers must be JSON numbers, not strings. Repeating the request is safe: it sets the same values.


Reference: https://docs.salarybox.in/api-reference/leave/balance-update

## Authentication

- `Authorization` header (required) (prefixed with ` Api-Key   `) — Format: "Api-Key \{api-key}"

## Request

### Body (application/json)

This endpoint expects a LeaveBalanceSetRequest.

- `salarybox_id` (string, required) — SalaryBox ID of an active staff member.
- `balances` (list of LeaveBalanceSetItem, required) — One item per leave type, each leave type at most once.

## Response

### 200

The leave balance was saved.

- `message` (string, optional)
- `status` (boolean, optional)
- `data` (LeaveBalanceSetResponseData, optional)

## Errors

### 400 Bad Request Error

Validation failed, or an unknown, ambiguous or system leave type.

- `message` (string, required)
- `status` (boolean, required)
- `errors` (map from string to any, optional, nullable)

### 403 Forbidden Error

A non-zero `carry_forwarded_leaves` was sent and the plan lacks Leave Carry Forward.

- `message` (string, required)
- `status` (boolean, required)
- `errors` (map from string to any, optional, nullable)

### 404 Not Found Error

No staff with this `salarybox_id`.

- `message` (string, required)
- `status` (boolean, required)
- `errors` (map from string to any, optional, nullable)

## Types

### LeaveBalanceSetItem

- `leave_type` (string, required) — Exact leave type name. System leave types are refused.
- `pending_leaves` (double, required) — Remaining balance, up to 3 decimals. Replaces the current balance.
- `carry_forwarded_leaves` (double, optional) — Up to 3 decimals. Left out, it stays as it is. A non-zero value needs the Leave Carry Forward plan feature.

### LeaveBalanceSetResponseData

- `salarybox_id` (string, optional)
- `balances` (list of LeaveBalanceSetResponseDataBalancesItems, optional)

### LeaveBalanceSetResponseDataBalancesItems

- `leave_type` (string, optional)
- `pending_leaves` (string, optional)
- `carry_forwarded_leaves` (string, optional)

## Examples

**Request**

```json
{
  "salarybox_id": "SBX1234567",
  "balances": [
    {
      "leave_type": "Casual Leave",
      "pending_leaves": 4.5,
      "carry_forwarded_leaves": 0
    }
  ]
}
```

**Response**

```json
{
  "message": "Leave balance saved successfully",
  "status": true,
  "data": {
    "salarybox_id": "SBX1234567",
    "balances": [
      {
        "leave_type": "Casual Leave",
        "pending_leaves": "4.500",
        "carry_forwarded_leaves": "0.000"
      }
    ]
  }
}
```

**SDK Code**

```python Example
import requests

url = "https://api.salaryboxapp.com/v2/customer/v1/leave/balance"

payload = {
    "salarybox_id": "SBX1234567",
    "balances": [
        {
            "leave_type": "Casual Leave",
            "pending_leaves": 4.5,
            "carry_forwarded_leaves": 0
        }
    ]
}
headers = {
    "Authorization": "Api-Key  <apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Example
const url = 'https://api.salaryboxapp.com/v2/customer/v1/leave/balance';
const options = {
  method: 'PUT',
  headers: {Authorization: 'Api-Key  <apiKey>', 'Content-Type': 'application/json'},
  body: '{"salarybox_id":"SBX1234567","balances":[{"leave_type":"Casual Leave","pending_leaves":4.5,"carry_forwarded_leaves":0}]}'
};

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

```go Example
package main

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

func main() {

	url := "https://api.salaryboxapp.com/v2/customer/v1/leave/balance"

	payload := strings.NewReader("{\n  \"salarybox_id\": \"SBX1234567\",\n  \"balances\": [\n    {\n      \"leave_type\": \"Casual Leave\",\n      \"pending_leaves\": 4.5,\n      \"carry_forwarded_leaves\": 0\n    }\n  ]\n}")

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

	req.Header.Add("Authorization", "Api-Key  <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 Example
require 'uri'
require 'net/http'

url = URI("https://api.salaryboxapp.com/v2/customer/v1/leave/balance")

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

request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Api-Key  <apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"salarybox_id\": \"SBX1234567\",\n  \"balances\": [\n    {\n      \"leave_type\": \"Casual Leave\",\n      \"pending_leaves\": 4.5,\n      \"carry_forwarded_leaves\": 0\n    }\n  ]\n}"

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

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

HttpResponse<String> response = Unirest.put("https://api.salaryboxapp.com/v2/customer/v1/leave/balance")
  .header("Authorization", "Api-Key  <apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"salarybox_id\": \"SBX1234567\",\n  \"balances\": [\n    {\n      \"leave_type\": \"Casual Leave\",\n      \"pending_leaves\": 4.5,\n      \"carry_forwarded_leaves\": 0\n    }\n  ]\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://api.salaryboxapp.com/v2/customer/v1/leave/balance', [
  'body' => '{
  "salarybox_id": "SBX1234567",
  "balances": [
    {
      "leave_type": "Casual Leave",
      "pending_leaves": 4.5,
      "carry_forwarded_leaves": 0
    }
  ]
}',
  'headers' => [
    'Authorization' => 'Api-Key  <apiKey>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Example
using RestSharp;

var client = new RestClient("https://api.salaryboxapp.com/v2/customer/v1/leave/balance");
var request = new RestRequest(Method.PUT);
request.AddHeader("Authorization", "Api-Key  <apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"salarybox_id\": \"SBX1234567\",\n  \"balances\": [\n    {\n      \"leave_type\": \"Casual Leave\",\n      \"pending_leaves\": 4.5,\n      \"carry_forwarded_leaves\": 0\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Example
import Foundation

let headers = [
  "Authorization": "Api-Key  <apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "salarybox_id": "SBX1234567",
  "balances": [
    [
      "leave_type": "Casual Leave",
      "pending_leaves": 4.5,
      "carry_forwarded_leaves": 0
    ]
  ]
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.salaryboxapp.com/v2/customer/v1/leave/balance")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
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()
```