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

# Add Staff Leave Policy

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

Sets how much leave one staff member is given, per leave type. It does **not** change their current balance (use `PUT /leave/balance` for that). Only the leave types sent change. Shared rules: see [Writing data](/conventions#writing-data).

- `salarybox_id` is an active staff member of the company.
- `policies` 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.
- `allocation_cycle` is `MONTHLY` or `ANNUAL`.
- `total_allotted_leaves` is 0-366 with up to 3 decimals; at most 31 when `MONTHLY`.
- `carry_forward_leaves` is optional, 0-366 with up to 3 decimals. Left out, it stays as it is (0 for a new policy).
- Every policy write needs the Leave Carry Forward plan feature, as in the app; otherwise `403` with the plan's upgrade message.
- 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/policy-set

## Authentication

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

## Request

### Body (application/json)

This endpoint expects a LeavePolicySetRequest.

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

## Response

### 200

The leave policy was saved.

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

## Errors

### 400 Bad Request Error

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

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

### 403 Forbidden Error

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

### LeavePolicySetItem

- `leave_type` (string, required) — Exact leave type name. System leave types are refused.
- `allocation_cycle` (enum, required)
  - Allowed values: `MONTHLY`, `ANNUAL`
- `total_allotted_leaves` (double, required) — Up to 3 decimals. At most 31 when `allocation_cycle` is `MONTHLY`.
- `carry_forward_leaves` (double, optional) — Up to 3 decimals. Left out, it stays as it is (0 for a new policy).

### LeavePolicySetResponseData

- `salarybox_id` (string, optional)
- `policies` (list of LeavePolicyItem, optional)

### LeavePolicyItem

- `leave_type` (string, required)
- `allocation_cycle` (string, required, nullable)
- `total_allotted_leaves` (string, required)
- `carry_forward_leaves` (string, required)

## Examples

**Request**

```json
{
  "salarybox_id": "SBX1234567",
  "policies": [
    {
      "leave_type": "Casual Leave",
      "allocation_cycle": "MONTHLY",
      "total_allotted_leaves": 1,
      "carry_forward_leaves": 12
    }
  ]
}
```

**Response**

```json
{
  "message": "Leave policy saved successfully",
  "status": true,
  "data": {
    "salarybox_id": "SBX1234567",
    "policies": [
      {
        "leave_type": "Casual Leave",
        "allocation_cycle": "MONTHLY",
        "total_allotted_leaves": "1.000",
        "carry_forward_leaves": "12.000"
      }
    ]
  }
}
```

**SDK Code**

```python Example
import requests

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

payload = {
    "salarybox_id": "SBX1234567",
    "policies": [
        {
            "leave_type": "Casual Leave",
            "allocation_cycle": "MONTHLY",
            "total_allotted_leaves": 1,
            "carry_forward_leaves": 12
        }
    ]
}
headers = {
    "Authorization": "Api-Key  <apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Example
const url = 'https://api.salaryboxapp.com/v2/customer/v1/leave/policy';
const options = {
  method: 'POST',
  headers: {Authorization: 'Api-Key  <apiKey>', 'Content-Type': 'application/json'},
  body: '{"salarybox_id":"SBX1234567","policies":[{"leave_type":"Casual Leave","allocation_cycle":"MONTHLY","total_allotted_leaves":1,"carry_forward_leaves":12}]}'
};

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/policy"

	payload := strings.NewReader("{\n  \"salarybox_id\": \"SBX1234567\",\n  \"policies\": [\n    {\n      \"leave_type\": \"Casual Leave\",\n      \"allocation_cycle\": \"MONTHLY\",\n      \"total_allotted_leaves\": 1,\n      \"carry_forward_leaves\": 12\n    }\n  ]\n}")

	req, _ := http.NewRequest("POST", 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/policy")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Api-Key  <apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"salarybox_id\": \"SBX1234567\",\n  \"policies\": [\n    {\n      \"leave_type\": \"Casual Leave\",\n      \"allocation_cycle\": \"MONTHLY\",\n      \"total_allotted_leaves\": 1,\n      \"carry_forward_leaves\": 12\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.post("https://api.salaryboxapp.com/v2/customer/v1/leave/policy")
  .header("Authorization", "Api-Key  <apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"salarybox_id\": \"SBX1234567\",\n  \"policies\": [\n    {\n      \"leave_type\": \"Casual Leave\",\n      \"allocation_cycle\": \"MONTHLY\",\n      \"total_allotted_leaves\": 1,\n      \"carry_forward_leaves\": 12\n    }\n  ]\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.salaryboxapp.com/v2/customer/v1/leave/policy', [
  'body' => '{
  "salarybox_id": "SBX1234567",
  "policies": [
    {
      "leave_type": "Casual Leave",
      "allocation_cycle": "MONTHLY",
      "total_allotted_leaves": 1,
      "carry_forward_leaves": 12
    }
  ]
}',
  '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/policy");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Api-Key  <apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"salarybox_id\": \"SBX1234567\",\n  \"policies\": [\n    {\n      \"leave_type\": \"Casual Leave\",\n      \"allocation_cycle\": \"MONTHLY\",\n      \"total_allotted_leaves\": 1,\n      \"carry_forward_leaves\": 12\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",
  "policies": [
    [
      "leave_type": "Casual Leave",
      "allocation_cycle": "MONTHLY",
      "total_allotted_leaves": 1,
      "carry_forward_leaves": 12
    ]
  ]
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.salaryboxapp.com/v2/customer/v1/leave/policy")! 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()
```