创建用户Create user

命名空间:microsoft.graphNamespace: microsoft.graph

注意: 适用于 Intune 的 Microsoft Graph API 需要适用于租户的活动 Intune 许可证Note: The Microsoft Graph API for Intune requires an active Intune license for the tenant.

创建新的 user 对象。Create a new user object.

先决条件Prerequisites

若要调用此 API,必须有以下权限之一。One of the following permissions is required to call this API. 要了解详细信息(包括如何选择权限),请参阅权限To learn more, including how to choose permissions, see Permissions. 所需的特定权限取决于上下文。The specific permission required depends on the context.

权限类型Permission type 权限(从最高特权到最低特权)Permissions (from most to least privileged)
委派(工作或学校帐户)Delegated (work or school account) 因上下文而异varies by context
  设备管理    Device management DeviceManagementManagedDevices.ReadWrite.AllDeviceManagementManagedDevices.ReadWrite.All
   MAM    MAM DeviceManagementApps.ReadWrite.AllDeviceManagementApps.ReadWrite.All
  载入    Onboarding DeviceManagementServiceConfig.ReadWrite.AllDeviceManagementServiceConfig.ReadWrite.All
  故障排除    Troubleshooting DeviceManagementManagedDevices.ReadWrite.AllDeviceManagementManagedDevices.ReadWrite.All
委派(个人 Microsoft 帐户)Delegated (personal Microsoft account) 不支持。Not supported.
应用程序Application 不支持。Not supported.

HTTP 请求HTTP Request

POST /users

请求标头Request headers

标头Header Value
AuthorizationAuthorization Bearer <token>。必需。Bearer <token> Required.
接受Accept application/jsonapplication/json

请求正文Request body

在请求正文中,提供 user 对象的 JSON 表示形式。In the request body, supply a JSON representation for the user object.

下表显示创建 user 时所需的属性。The following table shows the properties that are required when you create the user.

属性Property 类型Type 说明Description
idid StringString 用户的唯一标识符。Unique identifier of the user.
载入Onboarding
deviceEnrollmentLimitdeviceEnrollmentLimit Int32Int32 允许用户注册的最大设备数的限制。The limit on the maximum number of devices that the user is permitted to enroll. 允许的值为 5 或 1000。Allowed values are 5 or 1000.

请求正文属性支持根据上下文的不同而不同。Request body property support varies according to context.

响应Response

如果成功,此方法会在响应正文中返回 201 Created 响应代码和 user 对象。If successful, this method returns a 201 Created response code and a user object in the response body.

示例Example

请求Request

下面是一个请求示例。Here is an example of the request.

POST https://graph.microsoft.com/v1.0/users
Content-type: application/json
Content-length: 46

{
  "@odata.type": "#microsoft.graph.user"
}

响应Response

下面是一个响应示例。Here is an example of the response. 注意:为简洁起见,可能会截断此处显示的响应对象。Note: The response object shown here may be truncated for brevity. 从实际调用返回的属性根据上下文的不同而不同。Properties returned from an actual call vary according to context.

HTTP/1.1 201 Created
Content-Type: application/json
Content-Length: 95

{
  "@odata.type": "#microsoft.graph.user",
  "id": "d36894ae-94ae-d368-ae94-68d3ae9468d3"
}