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.
Update the automatic work location for a user. The automatic layer participates in the standard precedence model:
- Precedence: manual > automatic > scheduled
- Precision (within the same layer): more precise wins (for example, office + building > office)
- If a manual location is set, it overrides both automatic and scheduled settings.
Use this operation from clients or services that automatically detect location (for example, Teams, network and location agents, or OEM docking apps). It doesn't clear manual or scheduled signals.
This API is available in the following national cloud deployments.
| Global service |
US Government L4 |
US Government L5 (DOD) |
China operated by 21Vianet |
| ✅ |
❌ |
❌ |
❌ |
Permissions
Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.
| Permission type |
Least privileged permission |
Higher privileged permissions |
| Delegated (work or school account) |
Presence.ReadWrite |
Not available. |
| Delegated (personal Microsoft account) |
Not supported. |
Not supported. |
| Application |
Not supported. |
Not supported. |
HTTP request
POST /me/presence/setAutomaticLocation
Request body
In the request body, supply a JSON representation of the parameters.
The following table lists the parameters that are required when you call this action.
| Parameter |
Type |
Description |
| placeId |
String |
Identifier of the place, if applicable. |
| workLocationType |
workLocationType |
Semantic type of the location. Supports a subset of the values for workLocationType. The possible values are: office, remote, timeOff. |
Response
If successful, this action returns a 200 OK response code. It doesn't return anything in the response body.
Examples
Request
The following example shows a request.
POST https://graph.microsoft.com/beta/me/presence/setAutomaticLocation
Content-Type: application/json
{
"workLocationType": "office",
"placeId": "eb706f15-137e-4722-b4d1-b601481d9251"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Me.Presence.SetAutomaticLocation;
using Microsoft.Graph.Beta.Models;
var requestBody = new SetAutomaticLocationPostRequestBody
{
WorkLocationType = WorkLocationType.Office,
PlaceId = "eb706f15-137e-4722-b4d1-b601481d9251",
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
await graphClient.Me.Presence.SetAutomaticLocation.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"
graphusers "github.com/microsoftgraph/msgraph-beta-sdk-go/users"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphusers.NewItemSetAutomaticLocationPostRequestBody()
workLocationType := graphmodels.OFFICE_WORKLOCATIONTYPE
requestBody.SetWorkLocationType(&workLocationType)
placeId := "eb706f15-137e-4722-b4d1-b601481d9251"
requestBody.SetPlaceId(&placeId)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
graphClient.Me().Presence().SetAutomaticLocation().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.beta.users.item.presence.setautomaticlocation.SetAutomaticLocationPostRequestBody setAutomaticLocationPostRequestBody = new com.microsoft.graph.beta.users.item.presence.setautomaticlocation.SetAutomaticLocationPostRequestBody();
setAutomaticLocationPostRequestBody.setWorkLocationType(WorkLocationType.Office);
setAutomaticLocationPostRequestBody.setPlaceId("eb706f15-137e-4722-b4d1-b601481d9251");
graphClient.me().presence().setAutomaticLocation().post(setAutomaticLocationPostRequestBody);
const options = {
authProvider,
};
const client = Client.init(options);
const setAutomaticLocation = {
workLocationType: 'office',
placeId: 'eb706f15-137e-4722-b4d1-b601481d9251'
};
await client.api('/me/presence/setAutomaticLocation')
.version('beta')
.post(setAutomaticLocation);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Users\Item\Presence\SetAutomaticLocation\SetAutomaticLocationPostRequestBody;
use Microsoft\Graph\Beta\Generated\Models\WorkLocationType;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new SetAutomaticLocationPostRequestBody();
$requestBody->setWorkLocationType(new WorkLocationType('office'));
$requestBody->setPlaceId('eb706f15-137e-4722-b4d1-b601481d9251');
$graphServiceClient->me()->presence()->setAutomaticLocation()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.CloudCommunications
$params = @{
workLocationType = "office"
placeId = "eb706f15-137e-4722-b4d1-b601481d9251"
}
# A UPN can also be used as -UserId.
Set-MgBetaUserPresenceAutomaticLocation -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.users.item.presence.set_automatic_location.set_automatic_location_post_request_body import SetAutomaticLocationPostRequestBody
from msgraph_beta.generated.models.work_location_type import WorkLocationType
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = SetAutomaticLocationPostRequestBody(
work_location_type = WorkLocationType.Office,
place_id = "eb706f15-137e-4722-b4d1-b601481d9251",
)
await graph_client.me.presence.set_automatic_location.post(request_body)
Response
The following example shows the response.
HTTP/1.1 200 OK