创建 openShift
本文内容
命名空间:microsoft.graph
创建 openShift 对象的实例。
此 API 可用于以下国家级云部署 。
全局服务
美国政府 L4
美国政府 L5 (DOD)
由世纪互联运营的中国
✅
❌
❌
❌
权限
为此 API 选择标记为最低特权的权限。
只有在应用需要它时 ,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型 。 要了解有关这些权限的详细信息,请参阅 权限参考 。
权限类型
最低特权权限
更高特权权限
委派(工作或学校帐户)
Schedule.ReadWrite.All
Group.Read.All、Group.ReadWrite.All
委派(个人 Microsoft 帐户)
不支持。
不支持。
应用程序
Schedule.ReadWrite.All
不可用。
注意 :此 API 支持管理员权限。 具有管理员角色的用户可以访问他们不是其成员的组。
HTTP 请求
POST /teams/{id}/schedule/openShifts
名称
说明
Authorization
持有者 {token}。 必填。 详细了解 身份验证和授权 。
Content-type
application/json. 必需。
MS-APP-ACTS-AS
GUID) (用户 ID。 仅当授权令牌是应用程序令牌时才需要;否则为可选。
请求正文
在请求正文中,提供修改后的 openShift 对象的 JSON 表示形式。
下表列出了在创建 openShift 对象时可以使用的属性。
属性
类型
说明
draftOpenShift
openShiftItem
openShift 中的草稿更改仅在共享 之前对经理可见。
draftOpenShift 或 sharedOpenShift 应为 null
。
isStagedForDeletion
布尔值
openShift 标记为要删除,这是共享 计划时完成的过程。 可选。
schedulingGroupId
String
包含 openShift 的 schedulingGroup 的 ID。
sharedOpenShift
openShiftItem
此 openShift 的共享版本,可由员工和经理查看。
draftOpenShift 或 sharedOpenShift 应为 null
。
响应
如果成功,此方法在响应正文中返回响应 200 OK
代码和创建的 openShift 对象。
示例
请求
以下示例显示了一个请求。
POST https://graph.microsoft.com/v1.0/teams/788b75d2-a911-48c0-a5e2-dc98480457e3/schedule/openShifts
Authorization: Bearer {token}
Content-type: application/json
{
"schedulingGroupId": "TAG_4ab7d329-1f7e-4eaf-ba93-63f1ff3f3c4a",
"sharedOpenShift": {
"displayName": "Dayshift",
"startDateTime": "2024-11-04T20:00:00Z",
"endDateTime": "2024-11-04T21:00:00Z",
"theme": "blue",
"notes": "InventoryManagement",
"openSlotCount": 1,
"activities": []
},
"draftTimeOff": null,
"isStagedForDeletion": false
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new OpenShift
{
SchedulingGroupId = "TAG_4ab7d329-1f7e-4eaf-ba93-63f1ff3f3c4a",
SharedOpenShift = new OpenShiftItem
{
DisplayName = "Dayshift",
StartDateTime = DateTimeOffset.Parse("2024-11-04T20:00:00Z"),
EndDateTime = DateTimeOffset.Parse("2024-11-04T21:00:00Z"),
Theme = ScheduleEntityTheme.Blue,
Notes = "InventoryManagement",
OpenSlotCount = 1,
Activities = new List<ShiftActivity>
{
},
},
IsStagedForDeletion = false,
AdditionalData = new Dictionary<string, object>
{
{
"draftTimeOff" , null
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Teams["{team-id}"].Schedule.OpenShifts.PostAsync(requestBody, (requestConfiguration) =>
{
requestConfiguration.Headers.Add("Authorization", "Bearer {token}");
});
有关如何将 SDK 添加 到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档 。
mgc teams schedule open-shifts create --team-id {team-id} --body '{\
"schedulingGroupId": "TAG_4ab7d329-1f7e-4eaf-ba93-63f1ff3f3c4a",\
"sharedOpenShift": {\
"displayName": "Dayshift",\
"startDateTime": "2024-11-04T20:00:00Z",\
"endDateTime": "2024-11-04T21:00:00Z",\
"theme": "blue",\
"notes": "InventoryManagement",\
"openSlotCount": 1,\
"activities": []\
},\
"draftTimeOff": null,\
"isStagedForDeletion": false\
}\
'
有关如何将 SDK 添加 到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档 。
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
abstractions "github.com/microsoft/kiota-abstractions-go"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
graphteams "github.com/microsoftgraph/msgraph-sdk-go/teams"
//other-imports
)
headers := abstractions.NewRequestHeaders()
headers.Add("Authorization", "Bearer {token}")
configuration := &graphteams.ItemScheduleOpenShiftsRequestBuilderPostRequestConfiguration{
Headers: headers,
}
requestBody := graphmodels.NewOpenShift()
schedulingGroupId := "TAG_4ab7d329-1f7e-4eaf-ba93-63f1ff3f3c4a"
requestBody.SetSchedulingGroupId(&schedulingGroupId)
sharedOpenShift := graphmodels.NewOpenShiftItem()
displayName := "Dayshift"
sharedOpenShift.SetDisplayName(&displayName)
startDateTime , err := time.Parse(time.RFC3339, "2024-11-04T20:00:00Z")
sharedOpenShift.SetStartDateTime(&startDateTime)
endDateTime , err := time.Parse(time.RFC3339, "2024-11-04T21:00:00Z")
sharedOpenShift.SetEndDateTime(&endDateTime)
theme := graphmodels.BLUE_SCHEDULEENTITYTHEME
sharedOpenShift.SetTheme(&theme)
notes := "InventoryManagement"
sharedOpenShift.SetNotes(¬es)
openSlotCount := int32(1)
sharedOpenShift.SetOpenSlotCount(&openSlotCount)
activities := []graphmodels.ShiftActivityable {
}
sharedOpenShift.SetActivities(activities)
requestBody.SetSharedOpenShift(sharedOpenShift)
isStagedForDeletion := false
requestBody.SetIsStagedForDeletion(&isStagedForDeletion)
additionalData := map[string]interface{}{
draftTimeOff := null
requestBody.SetDraftTimeOff(&draftTimeOff)
}
requestBody.SetAdditionalData(additionalData)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
openShifts, err := graphClient.Teams().ByTeamId("team-id").Schedule().OpenShifts().Post(context.Background(), requestBody, configuration)
有关如何将 SDK 添加 到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档 。
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
OpenShift openShift = new OpenShift();
openShift.setSchedulingGroupId("TAG_4ab7d329-1f7e-4eaf-ba93-63f1ff3f3c4a");
OpenShiftItem sharedOpenShift = new OpenShiftItem();
sharedOpenShift.setDisplayName("Dayshift");
OffsetDateTime startDateTime = OffsetDateTime.parse("2024-11-04T20:00:00Z");
sharedOpenShift.setStartDateTime(startDateTime);
OffsetDateTime endDateTime = OffsetDateTime.parse("2024-11-04T21:00:00Z");
sharedOpenShift.setEndDateTime(endDateTime);
sharedOpenShift.setTheme(ScheduleEntityTheme.Blue);
sharedOpenShift.setNotes("InventoryManagement");
sharedOpenShift.setOpenSlotCount(1);
LinkedList<ShiftActivity> activities = new LinkedList<ShiftActivity>();
sharedOpenShift.setActivities(activities);
openShift.setSharedOpenShift(sharedOpenShift);
openShift.setIsStagedForDeletion(false);
HashMap<String, Object> additionalData = new HashMap<String, Object>();
additionalData.put("draftTimeOff", null);
openShift.setAdditionalData(additionalData);
OpenShift result = graphClient.teams().byTeamId("{team-id}").schedule().openShifts().post(openShift, requestConfiguration -> {
requestConfiguration.headers.add("Authorization", "Bearer {token}");
});
有关如何将 SDK 添加 到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档 。
const options = {
authProvider,
};
const client = Client.init(options);
const openShift = {
schedulingGroupId: 'TAG_4ab7d329-1f7e-4eaf-ba93-63f1ff3f3c4a',
sharedOpenShift: {
displayName: 'Dayshift',
startDateTime: '2024-11-04T20:00:00Z',
endDateTime: '2024-11-04T21:00:00Z',
theme: 'blue',
notes: 'InventoryManagement',
openSlotCount: 1,
activities: []
},
draftTimeOff: null,
isStagedForDeletion: false
};
await client.api('/teams/788b75d2-a911-48c0-a5e2-dc98480457e3/schedule/openShifts')
.post(openShift);
有关如何将 SDK 添加 到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档 。
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Teams\Item\Schedule\OpenShifts\OpenShiftsRequestBuilderPostRequestConfiguration;
use Microsoft\Graph\Generated\Models\OpenShift;
use Microsoft\Graph\Generated\Models\OpenShiftItem;
use Microsoft\Graph\Generated\Models\ScheduleEntityTheme;
use Microsoft\Graph\Generated\Models\ShiftActivity;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new OpenShift();
$requestBody->setSchedulingGroupId('TAG_4ab7d329-1f7e-4eaf-ba93-63f1ff3f3c4a');
$sharedOpenShift = new OpenShiftItem();
$sharedOpenShift->setDisplayName('Dayshift');
$sharedOpenShift->setStartDateTime(new \DateTime('2024-11-04T20:00:00Z'));
$sharedOpenShift->setEndDateTime(new \DateTime('2024-11-04T21:00:00Z'));
$sharedOpenShift->setTheme(new ScheduleEntityTheme('blue'));
$sharedOpenShift->setNotes('InventoryManagement');
$sharedOpenShift->setOpenSlotCount(1);
$sharedOpenShift->setActivities([ ]);
$requestBody->setSharedOpenShift($sharedOpenShift);
$requestBody->setIsStagedForDeletion(false);
$additionalData = [
'draftTimeOff' => null,
];
$requestBody->setAdditionalData($additionalData);
$requestConfiguration = new OpenShiftsRequestBuilderPostRequestConfiguration();
$headers = [
'Authorization' => 'Bearer {token}',
];
$requestConfiguration->headers = $headers;
$result = $graphServiceClient->teams()->byTeamId('team-id')->schedule()->openShifts()->post($requestBody, $requestConfiguration)->wait();
有关如何将 SDK 添加 到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档 。
Import-Module Microsoft.Graph.Teams
$params = @{
schedulingGroupId = "TAG_4ab7d329-1f7e-4eaf-ba93-63f1ff3f3c4a"
sharedOpenShift = @{
displayName = "Dayshift"
startDateTime = [System.DateTime]::Parse("2024-11-04T20:00:00Z")
endDateTime = [System.DateTime]::Parse("2024-11-04T21:00:00Z")
theme = "blue"
notes = "InventoryManagement"
openSlotCount = 1
activities = @(
)
}
draftTimeOff = $null
isStagedForDeletion = $false
}
New-MgTeamScheduleOpenShift -TeamId $teamId -BodyParameter $params
有关如何将 SDK 添加 到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档 。
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.teams.item.schedule.open_shifts.open_shifts_request_builder import OpenShiftsRequestBuilder
from kiota_abstractions.base_request_configuration import RequestConfiguration
from msgraph.generated.models.open_shift import OpenShift
from msgraph.generated.models.open_shift_item import OpenShiftItem
from msgraph.generated.models.schedule_entity_theme import ScheduleEntityTheme
from msgraph.generated.models.shift_activity import ShiftActivity
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = OpenShift(
scheduling_group_id = "TAG_4ab7d329-1f7e-4eaf-ba93-63f1ff3f3c4a",
shared_open_shift = OpenShiftItem(
display_name = "Dayshift",
start_date_time = "2024-11-04T20:00:00Z",
end_date_time = "2024-11-04T21:00:00Z",
theme = ScheduleEntityTheme.Blue,
notes = "InventoryManagement",
open_slot_count = 1,
activities = [
],
),
is_staged_for_deletion = False,
additional_data = {
"draft_time_off" : None,
}
)
request_configuration = RequestConfiguration()
request_configuration.headers.add("Authorization", "Bearer {token}")
result = await graph_client.teams.by_team_id('team-id').schedule.open_shifts.post(request_body, request_configuration = request_configuration)
有关如何将 SDK 添加 到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档 。
响应
以下示例显示了相应的响应。
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 200 OK
Content-Type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#teams('48ba9e52-8d25-41c7-bbe7-5ee6346eec0d')/schedule/openShifts/$entity",
"@odata.etag": "\"4002def0-0000-0c00-0000-672ea2ff0000\"",
"id": "OPNSHFT_6f5e1d7c-3ebe-449f-abfc-d677d26f0b5c",
"createdDateTime": "2024-11-08T23:47:11.605Z",
"lastModifiedDateTime": "2024-11-08T23:47:11.605Z",
"schedulingGroupId": "TAG_4ab7d329-1f7e-4eaf-ba93-63f1ff3f3c4a",
"draftOpenShift": null,
"lastModifiedBy": {
"application": null,
"device": null,
"user": {
"id": "366c0b19-49b1-41b5-a03f-9f3887bd0ed8",
"displayName": "John Doe",
"userIdentityType": "aadUser",
"tenantId": null
}
},
"sharedOpenShift": {
"displayName": null,
"startDateTime": "2024-11-04T20:00:00Z",
"endDateTime": "2024-11-04T21:00:00Z",
"theme": "blue",
"notes": null,
"openSlotCount": 1,
"activities": []
},
"isStagedForDeletion": false
}