Update shiftPreferences
Article
01/21/2022
3 minutes de lecture
3 contributeurs
Dans cet article
Espace de noms: microsoft.graph
Met à jour les propriétés et les relations d’un objet shiftPreferences.
Autorisations
L’une des autorisations suivantes est nécessaire pour appeler cette API. Pour plus d’informations, notamment sur la façon de choisir les autorisations, voir Autorisations .
Type d’autorisation
Autorisations (de celle qui offre le plus de privilèges à celle qui en offre le moins)
Déléguée (compte professionnel ou scolaire)
User.ReadWrite.All
Déléguée (compte Microsoft personnel)
Non prise en charge.
Application
UserShiftPreferences.ReadWrite.All
Remarque : cet API prend en charge les autorisations d’administrateur. Les administrateurs globaux peuvent accéder aux groupes dont ils ne sont pas membres.
Requête HTTP
PATCH /users/{userId}/settings/shiftPreferences
En-tête
Valeur
Autorisation
Porteur {token}. Obligatoire.
Content-Type
application/json. Obligatoire.
Corps de la demande
Dans le corps de la demande, fournissons une représentation JSON d’un objet shiftPreferences.
Réponse
Si elle réussit, cette méthode renvoie un code de réponse 204 NO CONTENT
.
Exemple
Demande
Voici un exemple de demande.
PATCH https://graph.microsoft.com/v1.0/users/871dbd5c-3a6a-4392-bfe1-042452793a50/settings/shiftPreferences
Content-type: application/json
{
"id": "SHPR_eeab4fb1-20e5-48ca-ad9b-98119d94bee7",
"@odata.etag": "1a371e53-f0a6-4327-a1ee-e3c56e4b38aa",
"availability": [
{
"recurrence": {
"pattern": {
"type": "Weekly",
"daysOfWeek": ["Monday", "Wednesday", "Friday"],
"interval": 1
},
"range": {
"type": "noEnd"
}
},
"timeZone": "Pacific Standard Time",
"timeSlots": null
}
]
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var shiftPreferences = new ShiftPreferences
{
Id = "SHPR_eeab4fb1-20e5-48ca-ad9b-98119d94bee7",
Availability = new List<ShiftAvailability>()
{
new ShiftAvailability
{
Recurrence = new PatternedRecurrence
{
Pattern = new RecurrencePattern
{
Type = RecurrencePatternType.Weekly,
DaysOfWeek = new List<DayOfWeek>()
{
DayOfWeek.Monday,
DayOfWeek.Wednesday,
DayOfWeek.Friday
},
Interval = 1
},
Range = new RecurrenceRange
{
Type = RecurrenceRangeType.NoEnd
}
},
TimeZone = "Pacific Standard Time",
TimeSlots = null
}
},
AdditionalData = new Dictionary<string, object>()
{
{"@odata.etag", "1a371e53-f0a6-4327-a1ee-e3c56e4b38aa"}
}
};
await graphClient.Users["{user-id}"].Settings.ShiftPreferences
.Request()
.UpdateAsync(shiftPreferences);
Lisez la documentation du SDK pour plus d’informations sur l’ajout du SDK à votre projet et la création d’une instance authProvider.
const options = {
authProvider,
};
const client = Client.init(options);
const shiftPreferences = {
id: 'SHPR_eeab4fb1-20e5-48ca-ad9b-98119d94bee7',
'@odata.etag': '1a371e53-f0a6-4327-a1ee-e3c56e4b38aa',
availability: [
{
recurrence: {
pattern: {
type: 'Weekly',
daysOfWeek: ['Monday', 'Wednesday', 'Friday'],
interval: 1
},
range: {
type: 'noEnd'
}
},
timeZone: 'Pacific Standard Time',
timeSlots: null
}
]
};
await client.api('/users/871dbd5c-3a6a-4392-bfe1-042452793a50/settings/shiftPreferences')
.update(shiftPreferences);
Lisez la documentation du SDK pour plus d’informations sur l’ajout du SDK à votre projet et la création d’une instance authProvider.
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/users/871dbd5c-3a6a-4392-bfe1-042452793a50/settings/shiftPreferences"]]];
[urlRequest setHTTPMethod:@"PATCH"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphShiftPreferences *shiftPreferences = [[MSGraphShiftPreferences alloc] init];
[shiftPreferences setId:@"SHPR_eeab4fb1-20e5-48ca-ad9b-98119d94bee7"];
NSMutableArray *availabilityList = [[NSMutableArray alloc] init];
MSGraphShiftAvailability *availability = [[MSGraphShiftAvailability alloc] init];
MSGraphPatternedRecurrence *recurrence = [[MSGraphPatternedRecurrence alloc] init];
MSGraphRecurrencePattern *pattern = [[MSGraphRecurrencePattern alloc] init];
[pattern setType: [MSGraphRecurrencePatternType weekly]];
NSMutableArray *daysOfWeekList = [[NSMutableArray alloc] init];
[daysOfWeekList addObject: @"Monday"];
[daysOfWeekList addObject: @"Wednesday"];
[daysOfWeekList addObject: @"Friday"];
[pattern setDaysOfWeek:daysOfWeekList];
[pattern setInterval: 1];
[recurrence setPattern:pattern];
MSGraphRecurrenceRange *range = [[MSGraphRecurrenceRange alloc] init];
[range setType: [MSGraphRecurrenceRangeType noEnd]];
[recurrence setRange:range];
[availability setRecurrence:recurrence];
[availability setTimeZone:@"Pacific Standard Time"];
[availability setTimeSlots: null];
[availabilityList addObject: availability];
[shiftPreferences setAvailability:availabilityList];
NSError *error;
NSData *shiftPreferencesData = [shiftPreferences getSerializedDataWithError:&error];
[urlRequest setHTTPBody:shiftPreferencesData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
Lisez la documentation du SDK pour plus d’informations sur l’ajout du SDK à votre projet et la création d’une instance authProvider.
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
ShiftPreferences shiftPreferences = new ShiftPreferences();
shiftPreferences.id = "SHPR_eeab4fb1-20e5-48ca-ad9b-98119d94bee7";
shiftPreferences.additionalDataManager().put("@odata.etag", new JsonPrimitive("1a371e53-f0a6-4327-a1ee-e3c56e4b38aa"));
LinkedList<ShiftAvailability> availabilityList = new LinkedList<ShiftAvailability>();
ShiftAvailability availability = new ShiftAvailability();
PatternedRecurrence recurrence = new PatternedRecurrence();
RecurrencePattern pattern = new RecurrencePattern();
pattern.type = RecurrencePatternType.WEEKLY;
LinkedList<DayOfWeek> daysOfWeekList = new LinkedList<DayOfWeek>();
daysOfWeekList.add(DayOfWeek.MONDAY);
daysOfWeekList.add(DayOfWeek.WEDNESDAY);
daysOfWeekList.add(DayOfWeek.FRIDAY);
pattern.daysOfWeek = daysOfWeekList;
pattern.interval = 1;
recurrence.pattern = pattern;
RecurrenceRange range = new RecurrenceRange();
range.type = RecurrenceRangeType.NO_END;
recurrence.range = range;
availability.recurrence = recurrence;
availability.timeZone = "Pacific Standard Time";
availability.timeSlots = null;
availabilityList.add(availability);
shiftPreferences.availability = availabilityList;
graphClient.users("871dbd5c-3a6a-4392-bfe1-042452793a50").settings().shiftPreferences()
.buildRequest()
.patch(shiftPreferences);
Lisez la documentation du SDK pour plus d’informations sur l’ajout du SDK à votre projet et la création d’une instance authProvider.
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewShiftPreferences()
id := "SHPR_eeab4fb1-20e5-48ca-ad9b-98119d94bee7"
requestBody.SetId(&id)
requestBody.SetAvailability( []ShiftAvailability {
msgraphsdk.NewShiftAvailability(),
SetAdditionalData(map[string]interface{}{
"timeZone": "Pacific Standard Time",
"timeSlots": nil,
}
}
requestBody.SetAdditionalData(map[string]interface{}{
"@odata.etag": "1a371e53-f0a6-4327-a1ee-e3c56e4b38aa",
}
userId := "user-id"
graphClient.UsersById(&userId).Settings().ShiftPreferences().Patch(requestBody)
Lisez la documentation du SDK pour plus d’informations sur l’ajout du SDK à votre projet et la création d’une instance authProvider.
Import-Module Microsoft.Graph.Users
$params = @{
Id = "SHPR_eeab4fb1-20e5-48ca-ad9b-98119d94bee7"
"@odata.etag" = "1a371e53-f0a6-4327-a1ee-e3c56e4b38aa"
Availability = @(
@{
Recurrence = @{
Pattern = @{
Type = "Weekly"
DaysOfWeek = @(
"Monday"
"Wednesday"
"Friday"
)
Interval = 1
}
Range = @{
Type = "noEnd"
}
}
TimeZone = "Pacific Standard Time"
TimeSlots = $null
}
)
}
Update-MgUserSettingShiftPreference -UserId $userId -BodyParameter $params
Lisez la documentation du SDK pour plus d’informations sur l’ajout du SDK à votre projet et la création d’une instance authProvider.
Réponse
Voici un exemple de réponse.
HTTP/1.1 204 NO CONTENT