Integration: Create Microsoft Team via Microsoft Graph API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago - last edited a month ago
Objective
Enable automated creation of Microsoft Teams from ServiceNow using Microsoft Graph API. This document covers the end-to-end process for calling Microsoft Graph, handling asynchronous responses, and extracting the teamId from response headers for further operations.
Prerequisites
- Entra ID Application Registration with the following API permissions:
- Team.Create
- Group.ReadWrite.All
- Microsoft Graph Access Token OAuth Credentials in ServiceNow.
- REST Message Setup in ServiceNow with OAuth Profile
Step 1: Create REST Message in ServiceNow
Field | Value |
Method | POST |
Endpoint | |
Headers | Content-Type: application/json |
Request Body:
{
"template@odata.bind": "https://graph.microsoft.com/v1.0/teamsTemplates('standard')",
"displayName": "${team_name}",
"description": "${description}",
"members": [
{
"@odata.type": "#microsoft.graph.aadUserConversationMember",
"roles": ["owner"],
"user@odata.bind": "https://graph.microsoft.com/v1.0/users('${user_id}')"
}
]
}
- ${team_name}, ${description}, ${user_id} → Replace dynamically based on your flow/script.
Step 2: Understanding API Response
Aspect | Details |
Status Code | 202 Accepted |
Headers Returned | Location or Content-Location |
Body | Mostly empty; Team creation is asynchronous |
Important Notes:
- Microsoft Graph does not immediately return Team details.
- The teamId is present inside the Location or Content-Location header.
- You must extract the teamId from headers for downstream use.
Step 3: Extract Team ID from Headers
Use a post-processing script (Action Step, Script Include, or Integration Hub Script Step) to extract the teamId.
Sample Code for Post-Processing:
var header = response.getHeader('Location');
gs.log("Location Header: " + header);
var teamId = null;
if (header) {
var match = header.match(/teams\('([a-f0-9-]+)'\)/i);
if (match && match[1]) {
teamId = match[1];
gs.log("Extracted Team ID: " + teamId);
} else {
gs.log("Could not extract Team ID from Location header.");
}
} else {
gs.log("Location header is empty, no Team ID available.");
}
Explanation:
- Extracts the Team ID cleanly from headers.
- Logs all key events using gs.log().
- teamId can be used in downstream steps (like channel creation).
Outcome
- Microsoft Team is created asynchronously in Microsoft Teams.
- teamId is extracted and logged.
- The process is fully automated from ServiceNow using REST API.
Step 4: Create Channel Under Team
After successfully creating the Team and extracting the teamId, the next step is to create a channel within the newly created: Microsoft Team.
API Endpoint :
Field | Value |
Method | POST |
Endpoint | |
Content-Type | application/json |
Request Body
{
"displayName": "${display_name}",
"description": "${descripton}",
"membershipType": "standard"
}
Note:
- displayName: Channel name (dynamic as required).
- description: Purpose or description of the channel.
- membershipType:
- "standard" for public within the Team,
- "private" for private channels (requires additional logic).
Important Notes:
- The teamId obtained from the Team creation step is used in the URL path.
- A successful response returns 201 Created.
- No need to extract headers for channel creation; the response body contains details if needed.
- Channels are created synchronously — you receive confirmation immediately.
Official Document from MS Graph : Creating a Team, Creating a Channel
- 1,058 Views