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

# Apply Staff Salary Template

POST https://api.salaryboxapp.com/v2/customer/v1/payroll/template/apply
Content-Type: application/json

Works out each staff member's salary from a salary template and saves it. This is not a preview, and it changes what the staff are paid. Shared rules: see [Writing data](/conventions#writing-data). Needs Payroll on your plan.

- `template_name` is the exact name of a salary template, either the company's own or a built-in one, as listed by the salary templates endpoint under payroll config (`/payroll/config/templates`).
- `salarybox_ids` has at max 50 SalaryBox IDs of active staff with no repeats. If any is unknown the result is `400` and nothing changes.
- `from_date` is `YYYY-MM-DD` and the first day of a month. It is not before the joining month and not in a finalised month.
- `ctc_amount` is the same for every staff member in the call.
- The template sets PF, ESI and allowances, replacing the staff member's for that structure. A structure already on `from_date` is overwritten, otherwise a new one starts. PT and LWF carry over from the staff member's current structure.
- Saving recalculates each staff member's unfinalised payroll from `from_date`.
- A `200` does not mean everyone changed. Always check each entry in `data.staff`: `result` is `applied` or `skipped`, and a skipped entry carries `reason` "Invalid Data" and `errors`. Each staff member is saved separately, so one skip does not undo the others.
- Repeating the request sets the same values.


Reference: https://docs.salarybox.in/api-reference/payroll/template-apply-create

## Authentication

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

## Request

### Body (application/json)

This endpoint expects a PayrollTemplateApplyRequest.

- `template_name` (string, required) — Exact name of a salary template, the company's own or a built-in one, as listed by `/payroll/config/templates`.
- `salarybox_ids` (list of string, required) — SalaryBox IDs of active staff. If any is unknown the result is `400` and nothing changes.
- `from_date` (date, required) — `YYYY-MM-DD`, the first day of a month. Not before the joining month and not in a finalised month.
- `pay_cycle_type` (enum, required)
  - Allowed values: `monthly`, `daily`, `weekly`, `hourly`
- `ctc_amount` (double, required) — Same for all staff in the call.

## Response

### 200

The request was processed. Check `result` for each staff member.

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

## Errors

### 400 Bad Request Error

Validation failed, the template name is unknown, the date is in a finalised month or before joining, or a `salarybox_ids` entry is unknown or inactive. Nothing changes.

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

### 403 Forbidden Error

Your plan does not include payroll.

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

## Types

### PayrollTemplateApplyResponseData

- `template_name` (string, optional)
- `staff` (list of PayrollTemplateApplyResponseDataStaffItems, optional)

### PayrollTemplateApplyResponseDataStaffItems

- `salarybox_id` (string, optional)
- `result` (enum, optional)
  - Allowed values: `applied`, `skipped`
- `from_date` (string, optional) — Present when `result` is `applied`, along with the other structure fields.
- `pay_cycle_type` (string, optional)
- `ctc_amount` (double, optional)
- `basic_amount` (double, optional)
- `allowances` (list of PayrollSalaryItem, optional)
- `deductions` (list of PayrollSalaryItem, optional)
- `reason` (string, optional) — Present when `result` is `skipped`. "Invalid Data".
- `errors` (map from string to any, optional) — Present when `result` is `skipped`. The problems, nested by field.

### PayrollSalaryItem

- `name` (string, required) — Trimmed. Names do not repeat within the list.
- `amount` (double, required) — JSON number with up to 2 decimals.

## Examples

**Request**

```json
{
  "template_name": "Standard Template",
  "salarybox_ids": [
    "SBX1",
    "SBX2"
  ],
  "from_date": "2026-11-01",
  "pay_cycle_type": "monthly",
  "ctc_amount": 25000
}
```

**Response**

```json
{
  "message": "Salary template processed",
  "status": true,
  "data": {
    "template_name": "Standard Template",
    "staff": [
      {
        "salarybox_id": "SBX1",
        "result": "applied",
        "from_date": "2026-11-01",
        "pay_cycle_type": "monthly",
        "ctc_amount": 25000,
        "basic_amount": 12500,
        "allowances": [
          {
            "name": "HRA",
            "amount": 6250
          }
        ],
        "deductions": []
      },
      {
        "salarybox_id": "SBX2",
        "result": "skipped",
        "reason": "Invalid Data",
        "errors": {
          "non_field_errors": [
            "ctc_amount provided is not correct, should be 25000.0"
          ]
        }
      }
    ]
  }
}
```

**SDK Code**

```python Example
import requests

url = "https://api.salaryboxapp.com/v2/customer/v1/payroll/template/apply"

payload = {
    "template_name": "Standard Template",
    "salarybox_ids": ["SBX1", "SBX2"],
    "from_date": "2026-11-01",
    "pay_cycle_type": "monthly",
    "ctc_amount": 25000
}
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/payroll/template/apply';
const options = {
  method: 'POST',
  headers: {Authorization: 'Api-Key  <apiKey>', 'Content-Type': 'application/json'},
  body: '{"template_name":"Standard Template","salarybox_ids":["SBX1","SBX2"],"from_date":"2026-11-01","pay_cycle_type":"monthly","ctc_amount":25000}'
};

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/payroll/template/apply"

	payload := strings.NewReader("{\n  \"template_name\": \"Standard Template\",\n  \"salarybox_ids\": [\n    \"SBX1\",\n    \"SBX2\"\n  ],\n  \"from_date\": \"2026-11-01\",\n  \"pay_cycle_type\": \"monthly\",\n  \"ctc_amount\": 25000\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/payroll/template/apply")

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  \"template_name\": \"Standard Template\",\n  \"salarybox_ids\": [\n    \"SBX1\",\n    \"SBX2\"\n  ],\n  \"from_date\": \"2026-11-01\",\n  \"pay_cycle_type\": \"monthly\",\n  \"ctc_amount\": 25000\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/payroll/template/apply")
  .header("Authorization", "Api-Key  <apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"template_name\": \"Standard Template\",\n  \"salarybox_ids\": [\n    \"SBX1\",\n    \"SBX2\"\n  ],\n  \"from_date\": \"2026-11-01\",\n  \"pay_cycle_type\": \"monthly\",\n  \"ctc_amount\": 25000\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/payroll/template/apply', [
  'body' => '{
  "template_name": "Standard Template",
  "salarybox_ids": [
    "SBX1",
    "SBX2"
  ],
  "from_date": "2026-11-01",
  "pay_cycle_type": "monthly",
  "ctc_amount": 25000
}',
  '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/payroll/template/apply");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Api-Key  <apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"template_name\": \"Standard Template\",\n  \"salarybox_ids\": [\n    \"SBX1\",\n    \"SBX2\"\n  ],\n  \"from_date\": \"2026-11-01\",\n  \"pay_cycle_type\": \"monthly\",\n  \"ctc_amount\": 25000\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Example
import Foundation

let headers = [
  "Authorization": "Api-Key  <apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "template_name": "Standard Template",
  "salarybox_ids": ["SBX1", "SBX2"],
  "from_date": "2026-11-01",
  "pay_cycle_type": "monthly",
  "ctc_amount": 25000
] as [String : Any]

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

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