简体   繁体   English

Dynamics 365 API - 操作 AddMembersTeam

[英]Dynamics 365 API - Action AddMembersTeam

I am using the API to add multiple users to a team in Dynamics.我正在使用 API 将多个用户添加到 Dynamics 中的团队。 I have got the code working when I want to add a single users but I need it to work with adding a list of users.当我想添加单个用户时,我已经让代码工作了,但我需要它来添加用户列表。

I am using Python to make these calls.我正在使用 Python 进行这些调用。

Here is the documentation I am going off of in Dynamics 这是我要在 Dynamics 中使用的文档

Here is part of my code:这是我的代码的一部分:

        append_team_url = f"{BASE_DATA_URL}teams({team_guid})/Microsoft.Dynamics.CRM.AddMembersTeam"
    team_data = {
                    "Members": [
                        {
                            "ownerid": users_add
                        }
                    ]
                }
    append_users_response = requests.post(append_team_url, headers=api_headers_no_return, data=json.dumps(team_data))

users_add is a list of GUID's: users_add 是 GUID 的列表:

['85927c2e-52e6-e511-80e7-0050569e0d14', 'ebb0ec50-733f-e811-a964-000d3a34edeb',

'd3d6ec34-df57-e511-80e4-0050569e44e8', '19452bf7-3b57-e511-80e4-0050569e44e8'] 'd3d6ec34-df57-e511-80e4-0050569e44e8', '19452bf7-3b57-e511-80e4-0050569e44e8']

The error I get:我得到的错误:

An error occurred while validating input parameters: Microsoft.OData.ODataException: An unexpected 'StartArray' node was found when reading from the JSON reader.验证输入参数时出错:Microsoft.OData.ODataException:从 JSON 读取器读取时发现意外的“StartArray”节点。 A 'PrimitiveValue' node was expected.\r\n at Microsoft.OData.Json.JsonReaderExtensions.ValidateNodeType(IJsonReader jsonReader, JsonNodeType expectedNodeType)\r\n需要一个“PrimitiveValue”节点。\r\n 在 Microsoft.OData.Json.JsonReaderExtensions.ValidateNodeType(IJsonReader jsonReader, JsonNodeType expectedNodeType)\r\n

Any help would be much appreciated!任何帮助将非常感激!

I know I can just make the call in a loop in Python but based on the wording of the documentation it seems like it's possible to pass multiple users.我知道我可以在 Python 中循环调用,但根据文档的措辞,似乎可以传递多个用户。

The payload should look like this, look at the Json array of users.有效负载应如下所示,查看用户的 Json 数组。 Reference 参考

POST [Organization URI]/api/data/v9.0/teams(team-guid-id)/Microsoft.Dynamics.CRM.AddMembersTeam HTTP/1.1
Accept: application/json
Content-Type: application/json; charset=utf-8
OData-MaxVersion: 4.0
OData-Version: 4.0

{
"Members": [{
"@odata.type": "Microsoft.Dynamics.CRM.systemuser",
"ownerid": "85927c2e-52e6-e511-80e7-0050569e0d14"
},{
"@odata.type": "Microsoft.Dynamics.CRM.systemuser",
"ownerid": "ebb0ec50-733f-e811-a964-000d3a34edeb"
}]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM