如何使用Microsoft Graph删除属性值



我想删除已经存储的属性。
例如,由于有些用户具有"姓氏",

GET https://graph.microsoft.com/v1.0/users/test01@test.onmicrosoft.com?$select=id,userPrincipalName,surname  
response:
{  
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(id,userPrincipalName,surname)/$entity",  
    "id": "8e05e09b-c195-4404-87c1-2325767b66cd",  
    "userPrincipalName": "test01@test.onmicrosoft.com",  
    "surname": "ABCDEF"  
}  

在这种情况下,我想删除"姓氏"。
当更新为null时也不会删除,该值不会更改。

PATCH https://graph.microsoft.com/v1.0/users/test01@test.onmicrosoft.com
{
    "surname": null
}

在"中更新是错误的。

PATCH https://graph.microsoft.com/v1.0/users/test01@test.onmicrosoft.com
{
    "surname": ""
}
response:
{
    "error": {
        "code": "Request_BadRequest",
        "message": "Invalid value specified for property 'surname' of resource 'User'.",
        "innerError": {
            "request-id": "159ef469-f527-4768-b1bd-99ffc3446e5c",
            "date": "2016-06-22T14:35:18"
        }
    }
}

请告诉我如何删除。

目前,Microsoft Graph REST API无法删除 surname 或将此属性设置为 null

作为解决方法,我们可以创建一个未指定此属性的新用户。其余的是您的参考:

POST:https://graph.microsoft.com/v1.0/users
authorization: bearer {token}
{

"accountEnabled": true,
"displayName":"displayName",
"mailNickname":"mailNickname",
"passwordProfile":
{"forceChangePasswordNextSignIn":false,"password":"Password@-1234"},
  "businessPhones": [
    "businessPhones-value"
  ],
"userPrincipalName":"test@tenant.onmicrosoft.com"
}

,如果您希望Microsoft Graph支持此功能,则可以从此处提交反馈。

截至2016年7月28日,Microsoft Graph现在尊重通过'null'来删除属性值,因此

PATCH https://graph.microsoft.com/v1.0/users/test01@test.onmicrosoft.com
{
    "surname": null
}

应该工作。

最新更新