Namespace: microsoft.graph
Important
APIs under the /beta
version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported. To determine whether an API is available in v1.0, use the Version selector.
Create a new shift instance in a schedule.
The duration of a shift cannot be less than 1 minute or longer than 24 hours.
This API is available in the following national cloud deployments.
Global service |
US Government L4 |
US Government L5 (DOD) |
China operated by 21Vianet |
✅ |
❌ |
❌ |
❌ |
Permissions
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions.
Permission type |
Permissions (from least to most privileged) |
Delegated (work or school account) |
Group.ReadWrite.All |
Delegated (personal Microsoft account) |
Not supported. |
Application |
Schedule.ReadWrite.All* |
HTTP request
POST /teams/{teamId}/schedule/shifts
Header |
Value |
Authorization |
Bearer {token}. Required. Learn more about authentication and authorization. |
Content-Type |
application/json. Required. |
MS-APP-ACTS-AS (deprecated) |
A user ID (GUID). Required only if the authorization token is an application token; otherwise, optional. The MS-APP-ACTS-AS header is deprecated and no longer required with application tokens. |
Response
If successful, this method returns a 201 Created
response code and a shift object in the response body.
Example
Request
The following example shows a request.
POST https://graph.microsoft.com/beta/teams/{teamId}/schedule/shifts
Content-type: application/json
{
"id": "SHFT_577b75d2-a927-48c0-a5d1-dc984894e7b8",
"userId": "c5d0c76b-80c4-481c-be50-923cd8d680a1",
"schedulingGroupId": "TAG_228940ed-ff84-4e25-b129-1b395cf78be0",
"sharedShift": {
"displayName": "Day shift",
"notes": "Please do inventory as part of your shift.",
"startDateTime": "2019-03-11T15:00:00Z",
"endDateTime": "2019-03-12T00:00:00Z",
"theme": "blue",
"activities": [
{
"isPaid": true,
"startDateTime": "2019-03-11T15:00:00Z",
"endDateTime": "2019-03-11T15:15:00Z",
"code": "",
"displayName": "Lunch"
}
]
},
"draftShift": {
"displayName": "Day shift",
"notes": "Please do inventory as part of your shift.",
"startDateTime": "2019-03-11T15:00:00Z",
"endDateTime": "2019-03-12T00:00:00Z",
"theme": "blue",
"activities": [
{
"isPaid": true,
"startDateTime": "2019-03-11T15:00:00Z",
"endDateTime": "2019-03-11T15:30:00Z",
"code": "",
"displayName": "Lunch"
}
]
}
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new Shift
{
Id = "SHFT_577b75d2-a927-48c0-a5d1-dc984894e7b8",
UserId = "c5d0c76b-80c4-481c-be50-923cd8d680a1",
SchedulingGroupId = "TAG_228940ed-ff84-4e25-b129-1b395cf78be0",
SharedShift = new ShiftItem
{
DisplayName = "Day shift",
Notes = "Please do inventory as part of your shift.",
StartDateTime = DateTimeOffset.Parse("2019-03-11T15:00:00Z"),
EndDateTime = DateTimeOffset.Parse("2019-03-12T00:00:00Z"),
Theme = ScheduleEntityTheme.Blue,
Activities = new List<ShiftActivity>
{
new ShiftActivity
{
IsPaid = true,
StartDateTime = DateTimeOffset.Parse("2019-03-11T15:00:00Z"),
EndDateTime = DateTimeOffset.Parse("2019-03-11T15:15:00Z"),
Code = "",
DisplayName = "Lunch",
},
},
},
DraftShift = new ShiftItem
{
DisplayName = "Day shift",
Notes = "Please do inventory as part of your shift.",
StartDateTime = DateTimeOffset.Parse("2019-03-11T15:00:00Z"),
EndDateTime = DateTimeOffset.Parse("2019-03-12T00:00:00Z"),
Theme = ScheduleEntityTheme.Blue,
Activities = new List<ShiftActivity>
{
new ShiftActivity
{
IsPaid = true,
StartDateTime = DateTimeOffset.Parse("2019-03-11T15:00:00Z"),
EndDateTime = DateTimeOffset.Parse("2019-03-11T15:30:00Z"),
Code = "",
DisplayName = "Lunch",
},
},
},
};
// 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.Shifts.PostAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewShift()
id := "SHFT_577b75d2-a927-48c0-a5d1-dc984894e7b8"
requestBody.SetId(&id)
userId := "c5d0c76b-80c4-481c-be50-923cd8d680a1"
requestBody.SetUserId(&userId)
schedulingGroupId := "TAG_228940ed-ff84-4e25-b129-1b395cf78be0"
requestBody.SetSchedulingGroupId(&schedulingGroupId)
sharedShift := graphmodels.NewShiftItem()
displayName := "Day shift"
sharedShift.SetDisplayName(&displayName)
notes := "Please do inventory as part of your shift."
sharedShift.SetNotes(¬es)
startDateTime , err := time.Parse(time.RFC3339, "2019-03-11T15:00:00Z")
sharedShift.SetStartDateTime(&startDateTime)
endDateTime , err := time.Parse(time.RFC3339, "2019-03-12T00:00:00Z")
sharedShift.SetEndDateTime(&endDateTime)
theme := graphmodels.BLUE_SCHEDULEENTITYTHEME
sharedShift.SetTheme(&theme)
shiftActivity := graphmodels.NewShiftActivity()
isPaid := true
shiftActivity.SetIsPaid(&isPaid)
startDateTime , err := time.Parse(time.RFC3339, "2019-03-11T15:00:00Z")
shiftActivity.SetStartDateTime(&startDateTime)
endDateTime , err := time.Parse(time.RFC3339, "2019-03-11T15:15:00Z")
shiftActivity.SetEndDateTime(&endDateTime)
code := ""
shiftActivity.SetCode(&code)
displayName := "Lunch"
shiftActivity.SetDisplayName(&displayName)
activities := []graphmodels.ShiftActivityable {
shiftActivity,
}
sharedShift.SetActivities(activities)
requestBody.SetSharedShift(sharedShift)
draftShift := graphmodels.NewShiftItem()
displayName := "Day shift"
draftShift.SetDisplayName(&displayName)
notes := "Please do inventory as part of your shift."
draftShift.SetNotes(¬es)
startDateTime , err := time.Parse(time.RFC3339, "2019-03-11T15:00:00Z")
draftShift.SetStartDateTime(&startDateTime)
endDateTime , err := time.Parse(time.RFC3339, "2019-03-12T00:00:00Z")
draftShift.SetEndDateTime(&endDateTime)
theme := graphmodels.BLUE_SCHEDULEENTITYTHEME
draftShift.SetTheme(&theme)
shiftActivity := graphmodels.NewShiftActivity()
isPaid := true
shiftActivity.SetIsPaid(&isPaid)
startDateTime , err := time.Parse(time.RFC3339, "2019-03-11T15:00:00Z")
shiftActivity.SetStartDateTime(&startDateTime)
endDateTime , err := time.Parse(time.RFC3339, "2019-03-11T15:30:00Z")
shiftActivity.SetEndDateTime(&endDateTime)
code := ""
shiftActivity.SetCode(&code)
displayName := "Lunch"
shiftActivity.SetDisplayName(&displayName)
activities := []graphmodels.ShiftActivityable {
shiftActivity,
}
draftShift.SetActivities(activities)
requestBody.SetDraftShift(draftShift)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
shifts, err := graphClient.Teams().ByTeamId("team-id").Schedule().Shifts().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Shift shift = new Shift();
shift.setId("SHFT_577b75d2-a927-48c0-a5d1-dc984894e7b8");
shift.setUserId("c5d0c76b-80c4-481c-be50-923cd8d680a1");
shift.setSchedulingGroupId("TAG_228940ed-ff84-4e25-b129-1b395cf78be0");
ShiftItem sharedShift = new ShiftItem();
sharedShift.setDisplayName("Day shift");
sharedShift.setNotes("Please do inventory as part of your shift.");
OffsetDateTime startDateTime = OffsetDateTime.parse("2019-03-11T15:00:00Z");
sharedShift.setStartDateTime(startDateTime);
OffsetDateTime endDateTime = OffsetDateTime.parse("2019-03-12T00:00:00Z");
sharedShift.setEndDateTime(endDateTime);
sharedShift.setTheme(ScheduleEntityTheme.Blue);
LinkedList<ShiftActivity> activities = new LinkedList<ShiftActivity>();
ShiftActivity shiftActivity = new ShiftActivity();
shiftActivity.setIsPaid(true);
OffsetDateTime startDateTime1 = OffsetDateTime.parse("2019-03-11T15:00:00Z");
shiftActivity.setStartDateTime(startDateTime1);
OffsetDateTime endDateTime1 = OffsetDateTime.parse("2019-03-11T15:15:00Z");
shiftActivity.setEndDateTime(endDateTime1);
shiftActivity.setCode("");
shiftActivity.setDisplayName("Lunch");
activities.add(shiftActivity);
sharedShift.setActivities(activities);
shift.setSharedShift(sharedShift);
ShiftItem draftShift = new ShiftItem();
draftShift.setDisplayName("Day shift");
draftShift.setNotes("Please do inventory as part of your shift.");
OffsetDateTime startDateTime2 = OffsetDateTime.parse("2019-03-11T15:00:00Z");
draftShift.setStartDateTime(startDateTime2);
OffsetDateTime endDateTime2 = OffsetDateTime.parse("2019-03-12T00:00:00Z");
draftShift.setEndDateTime(endDateTime2);
draftShift.setTheme(ScheduleEntityTheme.Blue);
LinkedList<ShiftActivity> activities1 = new LinkedList<ShiftActivity>();
ShiftActivity shiftActivity1 = new ShiftActivity();
shiftActivity1.setIsPaid(true);
OffsetDateTime startDateTime3 = OffsetDateTime.parse("2019-03-11T15:00:00Z");
shiftActivity1.setStartDateTime(startDateTime3);
OffsetDateTime endDateTime3 = OffsetDateTime.parse("2019-03-11T15:30:00Z");
shiftActivity1.setEndDateTime(endDateTime3);
shiftActivity1.setCode("");
shiftActivity1.setDisplayName("Lunch");
activities1.add(shiftActivity1);
draftShift.setActivities(activities1);
shift.setDraftShift(draftShift);
Shift result = graphClient.teams().byTeamId("{team-id}").schedule().shifts().post(shift);
const options = {
authProvider,
};
const client = Client.init(options);
const shift = {
id: 'SHFT_577b75d2-a927-48c0-a5d1-dc984894e7b8',
userId: 'c5d0c76b-80c4-481c-be50-923cd8d680a1',
schedulingGroupId: 'TAG_228940ed-ff84-4e25-b129-1b395cf78be0',
sharedShift: {
displayName: 'Day shift',
notes: 'Please do inventory as part of your shift.',
startDateTime: '2019-03-11T15:00:00Z',
endDateTime: '2019-03-12T00:00:00Z',
theme: 'blue',
activities: [
{
isPaid: true,
startDateTime: '2019-03-11T15:00:00Z',
endDateTime: '2019-03-11T15:15:00Z',
code: '',
displayName: 'Lunch'
}
]
},
draftShift: {
displayName: 'Day shift',
notes: 'Please do inventory as part of your shift.',
startDateTime: '2019-03-11T15:00:00Z',
endDateTime: '2019-03-12T00:00:00Z',
theme: 'blue',
activities: [
{
isPaid: true,
startDateTime: '2019-03-11T15:00:00Z',
endDateTime: '2019-03-11T15:30:00Z',
code: '',
displayName: 'Lunch'
}
]
}
};
await client.api('/teams/{teamId}/schedule/shifts')
.version('beta')
.post(shift);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\Shift;
use Microsoft\Graph\Beta\Generated\Models\ShiftItem;
use Microsoft\Graph\Beta\Generated\Models\ScheduleEntityTheme;
use Microsoft\Graph\Beta\Generated\Models\ShiftActivity;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Shift();
$requestBody->setId('SHFT_577b75d2-a927-48c0-a5d1-dc984894e7b8');
$requestBody->setUserId('c5d0c76b-80c4-481c-be50-923cd8d680a1');
$requestBody->setSchedulingGroupId('TAG_228940ed-ff84-4e25-b129-1b395cf78be0');
$sharedShift = new ShiftItem();
$sharedShift->setDisplayName('Day shift');
$sharedShift->setNotes('Please do inventory as part of your shift.');
$sharedShift->setStartDateTime(new \DateTime('2019-03-11T15:00:00Z'));
$sharedShift->setEndDateTime(new \DateTime('2019-03-12T00:00:00Z'));
$sharedShift->setTheme(new ScheduleEntityTheme('blue'));
$activitiesShiftActivity1 = new ShiftActivity();
$activitiesShiftActivity1->setIsPaid(true);
$activitiesShiftActivity1->setStartDateTime(new \DateTime('2019-03-11T15:00:00Z'));
$activitiesShiftActivity1->setEndDateTime(new \DateTime('2019-03-11T15:15:00Z'));
$activitiesShiftActivity1->setCode('');
$activitiesShiftActivity1->setDisplayName('Lunch');
$activitiesArray []= $activitiesShiftActivity1;
$sharedShift->setActivities($activitiesArray);
$requestBody->setSharedShift($sharedShift);
$draftShift = new ShiftItem();
$draftShift->setDisplayName('Day shift');
$draftShift->setNotes('Please do inventory as part of your shift.');
$draftShift->setStartDateTime(new \DateTime('2019-03-11T15:00:00Z'));
$draftShift->setEndDateTime(new \DateTime('2019-03-12T00:00:00Z'));
$draftShift->setTheme(new ScheduleEntityTheme('blue'));
$activitiesShiftActivity1 = new ShiftActivity();
$activitiesShiftActivity1->setIsPaid(true);
$activitiesShiftActivity1->setStartDateTime(new \DateTime('2019-03-11T15:00:00Z'));
$activitiesShiftActivity1->setEndDateTime(new \DateTime('2019-03-11T15:30:00Z'));
$activitiesShiftActivity1->setCode('');
$activitiesShiftActivity1->setDisplayName('Lunch');
$activitiesArray []= $activitiesShiftActivity1;
$draftShift->setActivities($activitiesArray);
$requestBody->setDraftShift($draftShift);
$result = $graphServiceClient->teams()->byTeamId('team-id')->schedule()->shifts()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Teams
$params = @{
id = "SHFT_577b75d2-a927-48c0-a5d1-dc984894e7b8"
userId = "c5d0c76b-80c4-481c-be50-923cd8d680a1"
schedulingGroupId = "TAG_228940ed-ff84-4e25-b129-1b395cf78be0"
sharedShift = @{
displayName = "Day shift"
notes = "Please do inventory as part of your shift."
startDateTime = [System.DateTime]::Parse("2019-03-11T15:00:00Z")
endDateTime = [System.DateTime]::Parse("2019-03-12T00:00:00Z")
theme = "blue"
activities = @(
@{
isPaid = $true
startDateTime = [System.DateTime]::Parse("2019-03-11T15:00:00Z")
endDateTime = [System.DateTime]::Parse("2019-03-11T15:15:00Z")
code = ""
displayName = "Lunch"
}
)
}
draftShift = @{
displayName = "Day shift"
notes = "Please do inventory as part of your shift."
startDateTime = [System.DateTime]::Parse("2019-03-11T15:00:00Z")
endDateTime = [System.DateTime]::Parse("2019-03-12T00:00:00Z")
theme = "blue"
activities = @(
@{
isPaid = $true
startDateTime = [System.DateTime]::Parse("2019-03-11T15:00:00Z")
endDateTime = [System.DateTime]::Parse("2019-03-11T15:30:00Z")
code = ""
displayName = "Lunch"
}
)
}
}
New-MgBetaTeamScheduleShift -TeamId $teamId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.shift import Shift
from msgraph_beta.generated.models.shift_item import ShiftItem
from msgraph_beta.generated.models.schedule_entity_theme import ScheduleEntityTheme
from msgraph_beta.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 = Shift(
id = "SHFT_577b75d2-a927-48c0-a5d1-dc984894e7b8",
user_id = "c5d0c76b-80c4-481c-be50-923cd8d680a1",
scheduling_group_id = "TAG_228940ed-ff84-4e25-b129-1b395cf78be0",
shared_shift = ShiftItem(
display_name = "Day shift",
notes = "Please do inventory as part of your shift.",
start_date_time = "2019-03-11T15:00:00Z",
end_date_time = "2019-03-12T00:00:00Z",
theme = ScheduleEntityTheme.Blue,
activities = [
ShiftActivity(
is_paid = True,
start_date_time = "2019-03-11T15:00:00Z",
end_date_time = "2019-03-11T15:15:00Z",
code = "",
display_name = "Lunch",
),
],
),
draft_shift = ShiftItem(
display_name = "Day shift",
notes = "Please do inventory as part of your shift.",
start_date_time = "2019-03-11T15:00:00Z",
end_date_time = "2019-03-12T00:00:00Z",
theme = ScheduleEntityTheme.Blue,
activities = [
ShiftActivity(
is_paid = True,
start_date_time = "2019-03-11T15:00:00Z",
end_date_time = "2019-03-11T15:30:00Z",
code = "",
display_name = "Lunch",
),
],
),
)
result = await graph_client.teams.by_team_id('team-id').schedule.shifts.post(request_body)
Response
The following example shows the response.
Note: The response object shown here might be shortened for readability.
HTTP/1.1 201 Created
Content-type: application/json
{
"id": "SHFT_577b75d2-a927-48c0-a5d1-dc984894e7b8",
"createdDateTime": "2019-03-14T04:32:51.451Z",
"lastModifiedDateTime": "2019-03-14T05:32:51.451Z",
"userId": "c5d0c76b-80c4-481c-be50-923cd8d680a1",
"schedulingGroupId": "TAG_228940ed-ff84-4e25-b129-1b395cf78be0",
"lastModifiedBy": {
"application": null,
"device": null,
"conversation": null,
"user": {
"id": "366c0b19-49b1-41b5-a03f-9f3887bd0ed8",
"displayName": "John Doe"
}
},
"sharedShift": {
"displayName": "Day shift",
"notes": "Please do inventory as part of your shift.",
"startDateTime": "2019-03-11T15:00:00Z",
"endDateTime": "2019-03-12T00:00:00Z",
"theme": "blue",
"activities": [
{
"isPaid": true,
"startDateTime": "2019-03-11T15:00:00Z",
"endDateTime": "2019-03-11T15:15:00Z",
"code": "",
"displayName": "Lunch"
}
]
},
"draftShift": {
"displayName": "Day shift",
"notes": "Please do inventory as part of your shift.",
"startDateTime": "2019-03-11T15:00:00Z",
"endDateTime": "2019-03-12T00:00:00Z",
"theme": "blue",
"activities": [
{
"isPaid": true,
"startDateTime": "2019-03-11T15:00:00Z",
"endDateTime": "2019-03-11T15:30:00Z",
"code": "",
"displayName": "Lunch"
}
]
}
}