The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Set Out of Office on Microsoft Teams & Outlook via Microsoft Graph API

rathan_now
Tera Contributor

Objective

Automate the process of setting Out of Office (automatic replies) for a user using Microsoft Graph API from ServiceNow. This covers the API setup, payload structure, and response handling.

Prerequisites

  • ENTRA ID Application Registration with the following API permissions:
    • Mail.ReadWrite
    • MailboxSettings.ReadWrite
  • Microsoft Graph OAuth Credentials configured in ServiceNow.
  • REST Message configured in ServiceNow with OAuth 2.0 profile.

 

Step 1: Create REST Message in ServiceNow

 

Field

Value

Method

PATCH

Endpoint

https://graph.microsoft.com/v1.0/users/${user_id}/mailboxSettings/automaticRepliesSetting

Headers

Content-Type: application/json

 

 

Request Body

{
  "status": "scheduled",
  "scheduledStartDateTime": {
    "dateTime": "${start_date_time}",
    "timeZone": "India Standard Time"
  },
  "scheduledEndDateTime": {
    "dateTime": "${end_date_time}",
    "timeZone": "India Standard Time"
  },
  "internalReplyMessage": "${internal_reply}",
  "externalReplyMessage": "${external_reply}",
  "externalAudience": "all"
}

 

Parameter

Purpose

${user_id}

UPN (email) of the user

${start_date_time}

Start time in ISO 8601 format (e.g., 2025-07-17T09:00:00)

${end_date_time}

End time in ISO 8601 format

${internal_reply}

Message shown to internal contacts

${external_reply}

Message shown to external contacts

 

Step 2: Expected API Response

 

Aspect

Details

Status Code

200 OK (Success)

Body

Empty (success confirmation)

Errors

400/403 → Permission issue, invalid payload, or user not found

 

 

Step 3: Handling Response in ServiceNow

 

  • No post-processing script is typically required since successful response is 200 OK.
  • Optional: You can log success/failure using gs.log(), or create a Flow Outcome for success/error tracking.

Extra Case: Out of Office Without Schedule (Always Enabled)

 

If you want to set Out of Office (automatic replies) without any schedule (enabled immediately and continuously), you can modify your request body as shown below.

 

Request Body Example (Always Enabled)

{
  "automaticRepliesSetting": {
    "status": "alwaysEnabled",
    "internalReplyMessage": "${internal_reply}",
    "externalReplyMessage": "${external_reply}"
  }
}

 

 

Parameter

Purpose

status

Set to alwaysEnabled to enable Out of Office without a time window

internalReplyMessage

Message shown to internal contacts

externalReplyMessage

Message shown to external contacts

 

 

Notes:

  • No need to provide scheduledStartDateTime and scheduledEndDateTime.
  • The Out of Office remains active until manually disabled.
  • API Response remains the same (200 OK) upon success.

Outcome

  • User’s Out of Office settings are successfully updated via ServiceNow.
  • Automatic Replies start and end based on the provided schedule.
  • Internal/External messages are dynamically configured.

Official Document from MS Graph : Set Out of Office

If it helps you mark Mark it as HELPFUL.

Thank you : )

0 REPLIES 0