Namespace: microsoft.graph
Importante
As APIs na versão /beta no Microsoft Graph estão sujeitas a alterações. Não há suporte para o uso dessas APIs em aplicativos de produção. Para determinar se uma API está disponível na v1.0, use o seletor Versão.
Crie um novo objeto workPlanOccurrence no seu próprio plano de trabalho. Apenas as ocorrências de tempo limite podem ser criadas diretamente.
WorkLocationType tem de ser definido como timeOff. Outras ocorrências são geradas automaticamente a partir de periodicidades.
Esta API está disponível nas seguintes implementações de cloud nacionais.
| Serviço global |
US Government L4 |
US Government L5 (DOD) |
China operada pela 21Vianet |
| ✅ |
❌ |
❌ |
❌ |
Permissões
Escolha a permissão ou permissões marcadas como menos privilegiadas para esta API. Utilize uma permissão ou permissões com privilégios mais elevados apenas se a sua aplicação o exigir. Para obter detalhes sobre as permissões delegadas e de aplicação, veja Tipos de permissão. Para saber mais sobre estas permissões, veja a referência de permissões.
| Tipo de permissão |
Permissões com menos privilégios |
Permissões com privilégios superiores |
| Delegado (conta corporativa ou de estudante) |
Calendars.ReadWrite |
Indisponível. |
| Delegado (conta pessoal da Microsoft) |
Sem suporte. |
Sem suporte. |
| Aplicativo |
Sem suporte. |
Sem suporte. |
Solicitação HTTP
POST /me/settings/workHoursAndLocations/occurrences
Observação
Chamar o ponto de extremidade /me exige um usuário conectado e, portanto, uma permissão delegada. As permissões de aplicação não são suportadas ao utilizar o /me ponto final.
Ao utilizar o /users/{id} ponto final, o ID tem de ser o seu próprio ID de utilizador.
POST /users/{id | userPrincipalName}/settings/workHoursAndLocations/occurrences
| Nome |
Descrição |
| Autorização |
{token} de portador. Obrigatório. Saiba mais sobre autenticação e autorização. |
| Content-Type |
application/json. Obrigatório. |
Corpo da solicitação
No corpo do pedido, forneça uma representação JSON de um objeto workPlanOccurrence .
WorkLocationType tem de ser definido como timeOff.
Resposta
Se for bem-sucedido, este método devolve um 201 Created código de resposta e um objeto workPlanOccurrence no corpo da resposta.
Exemplos
Solicitação
O exemplo a seguir mostra uma solicitação.
POST https://graph.microsoft.com/beta/me/settings/workHoursAndLocations/occurrences
Content-type: application/json
{
"start": {
"dateTime": "2025-12-15T00:00:00.0000000",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2025-12-15T23:59:59.0000000",
"timeZone": "Pacific Standard Time"
},
"workLocationType": "timeOff",
"timeOffDetails": {
"subject": "Personal Day",
"isAllDay": false
}
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new WorkPlanOccurrence
{
Start = new DateTimeTimeZone
{
DateTime = "2025-12-15T00:00:00.0000000",
TimeZone = "Pacific Standard Time",
},
End = new DateTimeTimeZone
{
DateTime = "2025-12-15T23:59:59.0000000",
TimeZone = "Pacific Standard Time",
},
WorkLocationType = WorkLocationType.TimeOff,
TimeOffDetails = new TimeOffDetails
{
Subject = "Personal Day",
IsAllDay = false,
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Me.Settings.WorkHoursAndLocations.Occurrences.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.NewWorkPlanOccurrence()
start := graphmodels.NewDateTimeTimeZone()
dateTime := "2025-12-15T00:00:00.0000000"
start.SetDateTime(&dateTime)
timeZone := "Pacific Standard Time"
start.SetTimeZone(&timeZone)
requestBody.SetStart(start)
end := graphmodels.NewDateTimeTimeZone()
dateTime := "2025-12-15T23:59:59.0000000"
end.SetDateTime(&dateTime)
timeZone := "Pacific Standard Time"
end.SetTimeZone(&timeZone)
requestBody.SetEnd(end)
workLocationType := graphmodels.TIMEOFF_WORKLOCATIONTYPE
requestBody.SetWorkLocationType(&workLocationType)
timeOffDetails := graphmodels.NewTimeOffDetails()
subject := "Personal Day"
timeOffDetails.SetSubject(&subject)
isAllDay := false
timeOffDetails.SetIsAllDay(&isAllDay)
requestBody.SetTimeOffDetails(timeOffDetails)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
occurrences, err := graphClient.Me().Settings().WorkHoursAndLocations().Occurrences().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
WorkPlanOccurrence workPlanOccurrence = new WorkPlanOccurrence();
DateTimeTimeZone start = new DateTimeTimeZone();
start.setDateTime("2025-12-15T00:00:00.0000000");
start.setTimeZone("Pacific Standard Time");
workPlanOccurrence.setStart(start);
DateTimeTimeZone end = new DateTimeTimeZone();
end.setDateTime("2025-12-15T23:59:59.0000000");
end.setTimeZone("Pacific Standard Time");
workPlanOccurrence.setEnd(end);
workPlanOccurrence.setWorkLocationType(WorkLocationType.TimeOff);
TimeOffDetails timeOffDetails = new TimeOffDetails();
timeOffDetails.setSubject("Personal Day");
timeOffDetails.setIsAllDay(false);
workPlanOccurrence.setTimeOffDetails(timeOffDetails);
WorkPlanOccurrence result = graphClient.me().settings().workHoursAndLocations().occurrences().post(workPlanOccurrence);
const options = {
authProvider,
};
const client = Client.init(options);
const workPlanOccurrence = {
start: {
dateTime: '2025-12-15T00:00:00.0000000',
timeZone: 'Pacific Standard Time'
},
end: {
dateTime: '2025-12-15T23:59:59.0000000',
timeZone: 'Pacific Standard Time'
},
workLocationType: 'timeOff',
timeOffDetails: {
subject: 'Personal Day',
isAllDay: false
}
};
await client.api('/me/settings/workHoursAndLocations/occurrences')
.version('beta')
.post(workPlanOccurrence);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\WorkPlanOccurrence;
use Microsoft\Graph\Beta\Generated\Models\DateTimeTimeZone;
use Microsoft\Graph\Beta\Generated\Models\WorkLocationType;
use Microsoft\Graph\Beta\Generated\Models\TimeOffDetails;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new WorkPlanOccurrence();
$start = new DateTimeTimeZone();
$start->setDateTime('2025-12-15T00:00:00.0000000');
$start->setTimeZone('Pacific Standard Time');
$requestBody->setStart($start);
$end = new DateTimeTimeZone();
$end->setDateTime('2025-12-15T23:59:59.0000000');
$end->setTimeZone('Pacific Standard Time');
$requestBody->setEnd($end);
$requestBody->setWorkLocationType(new WorkLocationType('timeOff'));
$timeOffDetails = new TimeOffDetails();
$timeOffDetails->setSubject('Personal Day');
$timeOffDetails->setIsAllDay(false);
$requestBody->setTimeOffDetails($timeOffDetails);
$result = $graphServiceClient->me()->settings()->workHoursAndLocations()->occurrences()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Users
$params = @{
start = @{
dateTime = "2025-12-15T00:00:00.0000000"
timeZone = "Pacific Standard Time"
}
end = @{
dateTime = "2025-12-15T23:59:59.0000000"
timeZone = "Pacific Standard Time"
}
workLocationType = "timeOff"
timeOffDetails = @{
subject = "Personal Day"
isAllDay = $false
}
}
# A UPN can also be used as -UserId.
New-MgBetaUserSettingWorkHourAndLocationOccurrence -UserId $userId -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.work_plan_occurrence import WorkPlanOccurrence
from msgraph_beta.generated.models.date_time_time_zone import DateTimeTimeZone
from msgraph_beta.generated.models.work_location_type import WorkLocationType
from msgraph_beta.generated.models.time_off_details import TimeOffDetails
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = WorkPlanOccurrence(
start = DateTimeTimeZone(
date_time = "2025-12-15T00:00:00.0000000",
time_zone = "Pacific Standard Time",
),
end = DateTimeTimeZone(
date_time = "2025-12-15T23:59:59.0000000",
time_zone = "Pacific Standard Time",
),
work_location_type = WorkLocationType.TimeOff,
time_off_details = TimeOffDetails(
subject = "Personal Day",
is_all_day = False,
),
)
result = await graph_client.me.settings.work_hours_and_locations.occurrences.post(request_body)
Resposta
O exemplo a seguir mostra a resposta.
Observação: o objeto de resposta mostrado aqui pode ser encurtado para legibilidade.
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#users('12345678-1234-1234-1234-123456789012')/settings/workHoursAndLocations/occurrences/$entity",
"id": "AAMkADljNDFhMDJjLTA2ZDItNDY2Mi04YjcxLTIzZTI4YjUyMDA0ZgBGAAAAAAAB5FC96H6HQLms31sjXiKjBwDraVMWVv9mR6-bY0mUztIzAAAAAAENAADraVMWVv9mR6-bY0mUztIzAAPENZYpAAA=",
"recurrenceId": null,
"workLocationType": "timeOff",
"placeId": null,
"start": {
"dateTime": "2025-12-15T00:00:00.0000000",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2025-12-15T23:59:59.0000000",
"timeZone": "Pacific Standard Time"
},
"timeOffDetails": {
"subject": "Personal Day",
"isAllDay": false
}
}