Office 365:如何查询各类项目ID的最大长度
Office 365 Item ID Maximum Lengths: Official Details & Programmatic Checks
Great question—this is a common frustration since many Microsoft Graph API resources don’t explicitly document ID field limits. Let’s break down what we know and how to get concrete answers:
1. Implicit & Documented ID Length Constraints
While most official docs skip explicit max length callouts, some resources have predictable limits based on their format:
- DirectoryObject (Users, Groups, Roles, etc.): IDs are standard GUIDs, so they’re fixed at 36 characters (including hyphens). Azure AD uses GUIDs universally for all directory object identifiers, which is an unstated but consistent rule.
- Exchange Online Mailbox IDs: Two common formats apply:
- UPN-based IDs: Follow the UPN standard limit of 113 total characters (64 for the local username part, 1 for the
@, 48 for the domain). - Exchange-specific GUID IDs: Also 36 characters, matching Azure AD’s GUID format.
- UPN-based IDs: Follow the UPN standard limit of 113 total characters (64 for the local username part, 1 for the
- Drive & DriveItem: OneDrive/SharePoint IDs use a proprietary hybrid format (e.g.,
b!abc123XYZ...for drives,01ABCDEFG...for items). Official docs don’t specify a hard max, but real-world testing across tenants shows lengths typically fall between 40–60 characters. - Teams & Channel IDs:
- Team IDs are GUIDs (36 characters), same as other directory objects.
- Channel IDs follow the format
19:xxxxxx@thread.tacv2, with observed lengths ranging from 30–40 characters.
2. Programmatic Methods to Confirm Max Lengths
If you need precise, environment-specific values, these approaches work:
- Bulk Query & Analyze: Use Microsoft Graph API to pull a large sample of resources and calculate the maximum ID length for each type. Example endpoints (use
$select=idto minimize payload size):- Fetch users:
GET /users?$select=id - Fetch site drives:
GET /sites/{siteId}/drives?$select=id - Fetch team channels:
GET /teams/{teamId}/channels?$select=id
Iterate through the returned items and track theid.lengthvalue to find the maximum for each resource type.
- Fetch users:
- Inspect Graph API Metadata: Check the Graph API metadata endpoint (path:
https://graph.microsoft.com/v1.0/$metadata) to view schema definitions. While max lengths aren’t always listed, you can confirm data types (most IDs are defined asEdm.String) and spot any hidden constraints. - Safe Storage Best Practice: Since Microsoft may extend ID lengths in future updates, a foolproof approach is to allocate 255 characters for storing any Office 365 resource ID. This ensures you won’t hit truncation issues even if IDs grow over time.
内容的提问来源于stack exchange,提问作者user13260866
相关产品推荐
相关产品推荐

