如何使用Graph API在SharePoint列表中插入用户列?

huangapple go评论72阅读模式
英文:

How do I insert into a user column in a SharePoint list using Graph API?

问题

我正在尝试使用Microsoft Graph API在SharePoint列表中创建一个项目,所有字段都已插入,除非我添加了一个用户列,否则会出现以下错误:

"code": "generalException",
"message": "处理过程中发生常规异常"

根据研究,要插入到用户列,需要用户的LookupId。我的用户列请求体如下:

{
    "fields": {
        "[ColumnName]LookupId": "12"
    }
}

如果有人能指导我哪里做错了,或者是否可以使用用户的电子邮件进行插入,那将更好。

干杯。

英文:

I am trying to create an item in a SharePoint list using Microsoft Graph API and all the fields are inserting except when I add a user column I get the following error:

"code": "generalException",
"message": "General exception while processing".

Based on research, to insert into a user column the user's LookupId is required. My request body for the user column is as follows:

{
    "fields": {
        "[ColumnName]LookupId": "12"
    }
}

If anybody could advise what I'm doing wrong or if I can insert using the user's email that would be better.

Cheers.

答案1

得分: 1

一切都符合您的请求,但这个主体仅适用于“lookup/user”列,其中“允许多个选择”设置为“false”。我猜想在您的情况下是“true”。您可以使用以下端点进行检查:

GET https://graph.microsoft.com/v1.0/sites/{{SiteId}}/lists/{{ListName}}/contentTypes?expand=columns(select=name,type,personOrGroup)

其中,personOrGroup.allowMultipleSelection 将显示标志。

对于允许多选的 userlookup 类型列,使用以下主体(显然,您可以在数组中传递多个值):

{
    "fields": {
        "[columnName]LookupId@odata.type":"Collection(Edm.String)",
        "[columnName]LookupId":["12"] 
    }
}

至于使用电子邮件引用用户字段,我认为使用Graph API不太可能,但您可以检查Sharepoint REST API v1是否支持此功能。

英文:

Everything is good with your request, but this body will work only for lookup/user columns where setting "Allow multiple selections" is false. I guess in your case it's true.
You can check it with the endpoint

GET https://graph.microsoft.com/v1.0/sites/{{SiteId}}/lists/{{ListName}}/contentTypes?expand=columns(select=name,type,personOrGroup)

where personOrGroup.allowMultipleSelection will show the flag.

For user or lookup type column where multiple selection is allowed, use the following body (and obviously you may pass multiple values in array):

{
    "fields": {
        "[columnName]LookupId@odata.type":"Collection(Edm.String)",
        "[columnName]LookupId":["12"] 
    }
}

As for referring to user fields with email, I don't think it's possible with Graph API, but you may check Sharepoint REST API v1 if it supports that

huangapple
  • 本文由 发表于 2023年1月9日 16:43:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75054838.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定