> ## Documentation Index
> Fetch the complete documentation index at: https://help.dingtalk.io/llms.txt
> Use this file to discover all available pages before exploring further.

# シフトの作成

> 勤怠シフトを作成する API です。シフト名、出勤・退勤の打刻時刻、打刻セクション、休憩時間を設定し、作成したシフト ID を返します。

この API を呼び出して、DingTalk の勤怠シフトを作成します。

## リクエスト

| **基本情報** | |
| - | - |
| HTTP URL | [https://api.dingtalk.io/topapi/attendance/shift/add](https://api.dingtalk.io/topapi/attendance/shift/add) |
| HTTP メソッド | POST |
| 対応アプリタイプ | appType-社内アプリ |
| 必要な権限 | permission-qyapi\_attendance\_group\_manage-勤怠グループ管理権限 |

### クエリパラメータ

| 名前 | タイプ | 必須 | 例 | 説明 |
| - | - | - | - | - |
| access\_token | String | はい | 6d1bxxxx | この API の呼び出しに使用するアプリ認証情報です。[社内アプリの access\_token を取得](https://help.dingtalk.io/ja/open/development/obtain-orgapp-token) API を呼び出して取得します。 |

### リクエストボディ

| 名前 | タイプ | 必須 | 例 | 説明 |
| - | - | - | - | - |
| op\_user\_id | String | はい | user01 | 操作者の userId です。 |
| shift | TopAtClassVo | はい | | シフトです。 |
| owner | String | いいえ | user01 | シフトの所有者です。 |
| class\_group\_name | String | いいえ | def | シフトグループ名です。 |
| corp\_id | String | いいえ | ding23 | 組織 ID（corpId）です。[開発者コンソール](https://open-dev.dingtalk.io/)で確認できます。CorpId |
| name | String | はい | 日勤 | シフト名です。 |
| id | Number | いいえ | 124 | シフト ID です。[シフト概要の取得](https://help.dingtalk.io/ja/open/development/enterprise-shift-query-in-batches.md) API を呼び出して取得します。  **注意**  シフトを新規作成する場合は id を空にします。既存のシフトを変更する場合は id を指定します。 |
| sections | TopAtSectionVo\[] | はい | | 打刻セクションです。 |
| times | TopAtTimeVo\[] | はい | | 打刻情報です。 |
| check\_type | String | はい | OnDuty | 打刻タイプです。   - **OnDuty**：出勤打刻 - **OffDuty**：退勤打刻 |
| across | Number | はい | 0 | 翌日にまたがるかどうかです。   - **0**：当日 - **1**：翌日 |
| end\_min | Number | いいえ | -1 | 打刻可能な最も遅い時刻（分単位）です。-1 は制限なしを表します。 |
| check\_time | Date | はい | 2020-12-02 09:00:00 | 打刻時刻です。 |
| free\_check | Boolean | いいえ | false | 打刻を免除するかどうかです。   - **false**：打刻が必要 - **true**：打刻を免除 |
| begin\_min | Number | いいえ | 30 | 打刻可能な最も早い事前打刻時間（分単位）です。 |
| setting | TopAtClassSettingVo | いいえ | | 設定です。 |
| rest\_begin\_time | TopAtTimeVo | いいえ | | 休憩開始です。 |
| check\_type | String | いいえ | OnDuty | 休憩タイプです。   - **OnDuty**：休憩開始 - **OffDuty**：休憩終了 |
| check\_time | Date | いいえ | 2020-12-02 09:00:00 | 休憩の打刻時刻です。 |
| free\_check | Boolean | いいえ | false | 打刻を免除するかどうかです。   - **true**：打刻を免除 - **false**：打刻が必要 |
| across | Number | いいえ | 0 | 翌日にまたがるかどうかです。翌日にまたがる場合、休憩は翌日になります。   - **0**：当日 - **1**：翌日 |
| class\_id | Number | いいえ | 221 | シフト ID です。[シフト概要の取得](https://help.dingtalk.io/ja/open/development/enterprise-shift-query-in-batches.md) API を呼び出して取得します。 |
| is\_flexible | Boolean | いいえ | false | フレックスシフトかどうかです。   - **true**：フレックス - **false**：フレックスではない |
| corp\_id | String | いいえ | ding121 | 組織 ID（corpId）です。[開発者コンソール](https://open-dev.dingtalk.io/)で確認できます。CorpId |
| is\_deleted | String | いいえ | N | シフトが削除済みかどうかです。   - **N**：はい - **Y**：いいえ |
| rest\_end\_time | TopAtTimeVo | いいえ | | 休憩終了です。 |
| check\_type | String | いいえ | OffDuty | 休憩タイプです。   - **OnDuty**：休憩開始 - **OffDuty**：休憩終了 |
| check\_time | Date | いいえ | 2020-12-02 09:00:00 | 休憩時刻です。 |
| free\_check | Boolean | いいえ | false | 打刻を免除するかどうかです。   - **false**：打刻が必要 - **true**：打刻を免除 |
| across | Number | いいえ | 1 | 翌日にまたがるかどうかです。翌日にまたがる場合、休憩は翌日になります。   - **0**：当日 - **1**：翌日 |
| serious\_late\_minutes | Number | いいえ | 31 | 重度の遅刻・早退とみなす時間（分単位）です。 |
| absenteeism\_late\_minutes | Number | いいえ | 60 | 欠勤とみなす遅刻・早退の時間（分単位）です。  **注意**  この値は重度の遅刻とみなす時間より大きくする必要があります。 |
| extras | Json | いいえ | `{"cause":"{\"type\":\"approve\",\"relatedId\":\"43494469-21a6-4111-953b-7810a709f27f\"}"}` | シフト設定の拡張フィールドです。臨時シフト以外では指定不要です。 |
| tags | String | いいえ | temp:schedule:isv | シフトのタグです。臨時シフト以外では指定不要です。 |

### リクエスト例

```curl theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST "https://api.dingtalk.io/topapi/attendance/shift/add" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'access_token=39cbcxxxx9058' \
-d 'op_user_id=abc' \
-d 'shift=null'
```

Java

```java theme={"theme":{"light":"github-light","dark":"github-dark"}}
DingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/attendance/shift/add");
OapiAttendanceShiftAddRequest request = new OapiAttendanceShiftAddRequest();
TopAtClassVo topAtClassVo = new TopAtClassVo();
topAtClassVo.setOwner("user456");
topAtClassVo.setClassGroupName("テストシフトグループ");
topAtClassVo.setCorpId("dinge8a56572xxxx");
topAtClassVo.setName("A1");
List<TopAtSectionVo> sectionVos = new ArrayList<>();
TopAtSectionVo sectionVo = new TopAtSectionVo();
List<TopAtTimeVo> timeVos = new ArrayList<>();
TopAtTimeVo timeVo = new TopAtTimeVo();
timeVo.setAcross(0L);
timeVo.setBeginMin(0L);
timeVo.setCheckTime(StringUtils.parseDateTime("2020-12-02 09:00:00"));
timeVo.setCheckType("OnDuty");
timeVo.setEndMin(-1L);
timeVo.setFreeCheck(false);
TopAtTimeVo timeVo1 = new TopAtTimeVo();
timeVo1.setAcross(0L);
timeVo1.setEndMin(0L);
timeVo1.setCheckTime(StringUtils.parseDateTime("2020-12-02 18:00:00"));
timeVo1.setCheckType("OffDuty");
timeVo1.setEndMin(-1L);
timeVo1.setFreeCheck(false);
timeVos.add(timeVo);
timeVos.add(timeVo1);
sectionVo.setTimes(timeVos);
sectionVos.add(sectionVo);
topAtClassVo.setSections(sectionVos);
TopAtClassSettingVo settingVo = new TopAtClassSettingVo();
topAtClassVo.setSetting(settingVo);
TopAtTimeVo restBeginTime = new TopAtTimeVo();
settingVo.setRestBeginTime(restBeginTime);
restBeginTime.setFreeCheck(false);
restBeginTime.setAcross(1L);
restBeginTime.setCheckType("OnDuty");
restBeginTime.setFreeCheck(false);
restBeginTime.setCheckTime(StringUtils.parseDateTime("2020-12-02 12:00:00"));
TopAtTimeVo restEndTime = new TopAtTimeVo();
settingVo.setRestEndTime(restEndTime);
restEndTime.setAcross(1L);
restEndTime.setCheckType("OffDuty");
restEndTime.setFreeCheck(false);
restEndTime.setCheckTime(StringUtils.parseDateTime("2020-12-02 13:00:00"));
settingVo.setCorpId("dinge8a56572xxxx");
settingVo.setIsDeleted("N");
settingVo.setAbsenteeismLateMinutes(60L);
settingVo.setIsFlexible(false);
settingVo.setSeriousLateMinutes(30L);
request.setOpUserId("user456");
request.setShift(topAtClassVo);
OapiAttendanceShiftAddResponse response = client.execute(request, access_token);
System.out.println(response.getBody());
```

Python

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import dingtalk.api

req=dingtalk.api.OapiAttendanceShiftAddRequest("https://api.dingtalk.io/topapi/attendance/shift/add")

req.op_user_id="abc"
req.shift=""
try:
  resp= req.getResponse(access_token)
  print(resp)
except Exception,e:
  print(e)
```

PHP

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
include "TopSdk.php";
date_default_timezone_set('Asia/Shanghai');
$c = new DingTalkClient(DingTalkConstant::$CALL_TYPE_OAPI, DingTalkConstant::$METHOD_POST , DingTalkConstant::$FORMAT_JSON);
$req = new OapiAttendanceShiftAddRequest;
$req->setOpUserId("abc");
$shift = new TopAtClassVo;
$shift->owner="abc";
$shift->class_group_name="def";
$shift->corp_id="ding23";
$shift->name="日勤";
$sections = new TopAtSectionVo;
$times = new TopAtTimeVo;
$times->check_type="OnDuty";
$times->across="0";
$times->end_min="-1";
$times->check_time="2020-03-17 12:00:00";
$times->free_check="false";
$times->begin_min="30";
$sections->times = array($times);
$shift->sections = array($sections);
$setting = new TopAtClassSettingVo;
$rest_begin_time = new TopAtTimeVo;
$rest_begin_time->check_type="OnDuty";
$rest_begin_time->check_time="2020-03-17 12:00:00";
$rest_begin_time->free_check="false";
$rest_begin_time->across="0";
$setting->rest_begin_time = $rest_begin_time;
$setting->is_flexible="false";
$setting->corp_id="ding121";
$setting->is_deleted="N";
$rest_end_time = new TopAtTimeVo;
$rest_end_time->check_type="OffDuty";
$rest_end_time->check_time="2020-03-17 13:00:00";
$rest_end_time->free_check="false";
$rest_end_time->across="1";
$setting->rest_end_time = $rest_end_time;
$setting->serious_late_minutes="31";
$setting->absenteeism_late_minutes="60";
$shift->setting = $setting;
$req->setShift($shift);
$resp = $c->execute($req, $access_token, "https://api.dingtalk.io/topapi/attendance/shift/add");
```

C#

```csharp theme={"theme":{"light":"github-light","dark":"github-dark"}}
IDingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/attendance/shift/add");
OapiAttendanceShiftAddRequest req = new OapiAttendanceShiftAddRequest();
req.OpUserId = "abc";
OapiAttendanceShiftAddRequest.TopAtClassVoDomain obj1 = new OapiAttendanceShiftAddRequest.TopAtClassVoDomain();
obj1.Owner = "abc";
obj1.ClassGroupName = "def";
obj1.CorpId = "ding23";
obj1.Name = "日勤";
List<OapiAttendanceShiftAddRequest.TopAtSectionVoDomain> list3 = new List<OapiAttendanceShiftAddRequest.TopAtSectionVoDomain>();
OapiAttendanceShiftAddRequest.TopAtSectionVoDomain obj4 = new OapiAttendanceShiftAddRequest.TopAtSectionVoDomain();
list3.Add(obj4);
List<OapiAttendanceShiftAddRequest.TopAtTimeVoDomain> list6 = new List<OapiAttendanceShiftAddRequest.TopAtTimeVoDomain>();
OapiAttendanceShiftAddRequest.TopAtTimeVoDomain obj7 = new OapiAttendanceShiftAddRequest.TopAtTimeVoDomain();
list6.Add(obj7);
obj7.CheckType = "OnDuty";
obj7.Across = 0L;
obj7.EndMin = -1L;
obj7.CheckTime = DateTime.Parse("2020-03-17 12:00:00");
obj7.FreeCheck = false;
obj7.BeginMin = 30L;
obj4.Times= list6;
obj1.Sections= list3;
OapiAttendanceShiftAddRequest.TopAtClassSettingVoDomain obj8 = new OapiAttendanceShiftAddRequest.TopAtClassSettingVoDomain();
OapiAttendanceShiftAddRequest.TopAtTimeVoDomain obj9 = new OapiAttendanceShiftAddRequest.TopAtTimeVoDomain();
obj9.CheckType = "OnDuty";
obj9.CheckTime = DateTime.Parse("2020-03-17 12:00:00");
obj9.FreeCheck = false;
obj9.Across = 0L;
obj8.RestBeginTime= obj9;
obj8.IsFlexible = false;
obj8.CorpId = "ding121";
obj8.IsDeleted = "N";
OapiAttendanceShiftAddRequest.TopAtTimeVoDomain obj10 = new OapiAttendanceShiftAddRequest.TopAtTimeVoDomain();
obj10.CheckType = "OffDuty";
obj10.CheckTime = DateTime.Parse("2020-03-17 13:00:00");
obj10.FreeCheck = false;
obj10.Across = 1L;
obj8.RestEndTime= obj10;
obj8.SeriousLateMinutes = 31L;
obj8.AbsenteeismLateMinutes = 60L;
obj1.Setting= obj8;
req.Shift_ = obj1;
OapiAttendanceShiftAddResponse rsp = client.Execute(req, access_token);
Console.WriteLine(rsp.Body);
```

## レスポンス

### レスポンスボディ

| 名前 | タイプ | 例 | 説明 |
| - | - | - | - |
| result | TopAtClassVo | | シフト情報です。 |
| id | Number | 706715401 | シフト ID です。 |
| name | String | A1 | シフト名です。 |
| errmsg | String | ok | リターンコードの説明です。 |
| errcode | Number | 0 | リターンコードです。 |
| success | Boolean | true | 呼び出しに成功したかどうかです。   - **true**：成功 - **false**：失敗 |
| request\_id | String | wp2oh4e4vlbu | リクエスト ID です。 |

### レスポンスボディの例

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "errcode": 0,
  "errmsg":"ok",
  "result": {
    "id": 706715401,
    "name": "A1"
  },
  "success": true,
  "request_id": "wp2oh4e4vlbu"
}
```

### エラーコード

API の呼び出しでエラーが返された場合は、エラーメッセージをもとに[グローバルエラーコード](https://help.dingtalk.io/ja/open/development/server-api-error-codes-1.md)ドキュメントで解決方法を確認してください。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.