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

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

Adds a new shift to your company. Shared rules: see [Writing data](/conventions#writing-data).

- `name` must be unique in the company, ignoring upper/lower case and outer spaces. A second shift with the same name is refused with `400`, so repeating is harmless.
- `start_time` and `end_time` are 24-hour `HH:MM`. If `end_time` is the same as or earlier than `start_time`, the shift runs overnight (for example 22:00-06:00); this needs the Night Shift plan feature.
- `min_punch_in_minutes` is how many minutes before the shift starts a punch-in is accepted; `max_punch_out_minutes` is how many minutes after it ends a punch-out is accepted. Leave out for no limit. Either needs the Shift Time Limits plan feature.
- `GET /attendance/shift` returns these limits as `min_punch_in_duration` / `max_punch_out_duration` in seconds; writes use minutes.


Reference: https://docs.salarybox.in/api-reference/attendance/shift-create

## Authentication

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

## Request

### Body (application/json)

This endpoint expects an AttendanceShiftCreateRequest.

- `name` (string, required) — Shift name. Unique in the company, ignoring case.
- `start_time` (string, required) — Start time, 24-hour `HH:MM`.
- `end_time` (string, required) — End time, 24-hour `HH:MM`. Same as or earlier than `start_time` means an overnight shift (needs Night Shift).
- `min_punch_in_minutes` (integer, optional) — Minutes before the shift starts that a punch-in is accepted. Leave out for no limit (needs Shift Time Limits).
- `max_punch_out_minutes` (integer, optional) — Minutes after the shift ends that a punch-out is accepted. Leave out for no limit (needs Shift Time Limits).

## Response

### 201

The shift was created.

- `message` (string, required)
- `status` (boolean, required)
- `data` (AttendanceShiftResponseData, required)

## Errors

### 400 Bad Request Error

Validation failed.

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

### 403 Forbidden Error

The plan lacks Night Shift or Shift Time Limits.

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

## Types

### AttendanceShiftResponseData

- `name` (string, required)
- `start_time` (string, required) — 24-hour `HH:MM`.
- `end_time` (string, required) — 24-hour `HH:MM`.
- `is_overnight` (boolean, required)
- `min_punch_in_minutes` (integer, required, nullable) — Minutes before start a punch-in is accepted; `null` means no limit.
- `max_punch_out_minutes` (integer, required, nullable) — Minutes after end a punch-out is accepted; `null` means no limit.

## Examples

### Example

**Response**

```json
{
  "message": "Shift added successfully",
  "status": true,
  "data": {
    "name": "Morning",
    "start_time": "09:00",
    "end_time": "18:00",
    "is_overnight": false,
    "min_punch_in_minutes": 30,
    "max_punch_out_minutes": null
  }
}
```

**SDK Code**

```python Example
import requests

url = "https://api.salaryboxapp.com/v2/customer/v1/attendance/shift"

headers = {"Authorization": "Api-Key  <apiKey>"}

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

print(response.json())
```

```javascript Example
const url = 'https://api.salaryboxapp.com/v2/customer/v1/attendance/shift';
const options = {method: 'POST', headers: {Authorization: 'Api-Key  <apiKey>'}};

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

func main() {

	url := "https://api.salaryboxapp.com/v2/customer/v1/attendance/shift"

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

	req.Header.Add("Authorization", "Api-Key  <apiKey>")

	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/attendance/shift")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Api-Key  <apiKey>'

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/attendance/shift")
  .header("Authorization", "Api-Key  <apiKey>")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.salaryboxapp.com/v2/customer/v1/attendance/shift', [
  'headers' => [
    'Authorization' => 'Api-Key  <apiKey>',
  ],
]);

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

```csharp Example
using RestSharp;

var client = new RestClient("https://api.salaryboxapp.com/v2/customer/v1/attendance/shift");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Api-Key  <apiKey>");
IRestResponse response = client.Execute(request);
```

```swift Example
import Foundation

let headers = ["Authorization": "Api-Key  <apiKey>"]

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

### Day shift that accepts punch-in 30 minutes early

**Request**

```json
{
  "name": "Morning",
  "start_time": "09:00",
  "end_time": "18:00",
  "min_punch_in_minutes": 30
}
```

**Response**

```json
{
  "message": "Shift added successfully",
  "status": true,
  "data": {
    "name": "Morning",
    "start_time": "09:00",
    "end_time": "18:00",
    "is_overnight": false,
    "min_punch_in_minutes": 30,
    "max_punch_out_minutes": null
  }
}
```

**SDK Code**

```python Day shift that accepts punch-in 30 minutes early
import requests

url = "https://api.salaryboxapp.com/v2/customer/v1/attendance/shift"

payload = {
    "name": "Morning",
    "start_time": "09:00",
    "end_time": "18:00",
    "min_punch_in_minutes": 30
}
headers = {
    "Authorization": "Api-Key  <apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Day shift that accepts punch-in 30 minutes early
const url = 'https://api.salaryboxapp.com/v2/customer/v1/attendance/shift';
const options = {
  method: 'POST',
  headers: {Authorization: 'Api-Key  <apiKey>', 'Content-Type': 'application/json'},
  body: '{"name":"Morning","start_time":"09:00","end_time":"18:00","min_punch_in_minutes":30}'
};

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

```go Day shift that accepts punch-in 30 minutes early
package main

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

func main() {

	url := "https://api.salaryboxapp.com/v2/customer/v1/attendance/shift"

	payload := strings.NewReader("{\n  \"name\": \"Morning\",\n  \"start_time\": \"09:00\",\n  \"end_time\": \"18:00\",\n  \"min_punch_in_minutes\": 30\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 Day shift that accepts punch-in 30 minutes early
require 'uri'
require 'net/http'

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

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  \"name\": \"Morning\",\n  \"start_time\": \"09:00\",\n  \"end_time\": \"18:00\",\n  \"min_punch_in_minutes\": 30\n}"

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

```java Day shift that accepts punch-in 30 minutes early
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.salaryboxapp.com/v2/customer/v1/attendance/shift")
  .header("Authorization", "Api-Key  <apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"Morning\",\n  \"start_time\": \"09:00\",\n  \"end_time\": \"18:00\",\n  \"min_punch_in_minutes\": 30\n}")
  .asString();
```

```php Day shift that accepts punch-in 30 minutes early
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.salaryboxapp.com/v2/customer/v1/attendance/shift', [
  'body' => '{
  "name": "Morning",
  "start_time": "09:00",
  "end_time": "18:00",
  "min_punch_in_minutes": 30
}',
  'headers' => [
    'Authorization' => 'Api-Key  <apiKey>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Day shift that accepts punch-in 30 minutes early
using RestSharp;

var client = new RestClient("https://api.salaryboxapp.com/v2/customer/v1/attendance/shift");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Api-Key  <apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"Morning\",\n  \"start_time\": \"09:00\",\n  \"end_time\": \"18:00\",\n  \"min_punch_in_minutes\": 30\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Day shift that accepts punch-in 30 minutes early
import Foundation

let headers = [
  "Authorization": "Api-Key  <apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "Morning",
  "start_time": "09:00",
  "end_time": "18:00",
  "min_punch_in_minutes": 30
] as [String : Any]

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

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

### Overnight shift

**Request**

```json
{
  "name": "Night",
  "start_time": "22:00",
  "end_time": "06:00"
}
```

**Response**

```json
{
  "message": "Shift added successfully",
  "status": true,
  "data": {
    "name": "Morning",
    "start_time": "09:00",
    "end_time": "18:00",
    "is_overnight": false,
    "min_punch_in_minutes": 30,
    "max_punch_out_minutes": null
  }
}
```

**SDK Code**

```python Overnight shift
import requests

url = "https://api.salaryboxapp.com/v2/customer/v1/attendance/shift"

payload = {
    "name": "Night",
    "start_time": "22:00",
    "end_time": "06:00"
}
headers = {
    "Authorization": "Api-Key  <apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Overnight shift
const url = 'https://api.salaryboxapp.com/v2/customer/v1/attendance/shift';
const options = {
  method: 'POST',
  headers: {Authorization: 'Api-Key  <apiKey>', 'Content-Type': 'application/json'},
  body: '{"name":"Night","start_time":"22:00","end_time":"06:00"}'
};

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

```go Overnight shift
package main

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

func main() {

	url := "https://api.salaryboxapp.com/v2/customer/v1/attendance/shift"

	payload := strings.NewReader("{\n  \"name\": \"Night\",\n  \"start_time\": \"22:00\",\n  \"end_time\": \"06:00\"\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 Overnight shift
require 'uri'
require 'net/http'

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

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  \"name\": \"Night\",\n  \"start_time\": \"22:00\",\n  \"end_time\": \"06:00\"\n}"

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

```java Overnight shift
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.salaryboxapp.com/v2/customer/v1/attendance/shift")
  .header("Authorization", "Api-Key  <apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"Night\",\n  \"start_time\": \"22:00\",\n  \"end_time\": \"06:00\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.salaryboxapp.com/v2/customer/v1/attendance/shift', [
  'body' => '{
  "name": "Night",
  "start_time": "22:00",
  "end_time": "06:00"
}',
  'headers' => [
    'Authorization' => 'Api-Key  <apiKey>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Overnight shift
using RestSharp;

var client = new RestClient("https://api.salaryboxapp.com/v2/customer/v1/attendance/shift");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Api-Key  <apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"Night\",\n  \"start_time\": \"22:00\",\n  \"end_time\": \"06:00\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Overnight shift
import Foundation

let headers = [
  "Authorization": "Api-Key  <apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "Night",
  "start_time": "22:00",
  "end_time": "06:00"
] as [String : Any]

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

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