Reputation: 283
I am using the API to add multiple users to a team in 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.
Here is the documentation I am going off of in 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:
['85927c2e-52e6-e511-80e7-0050569e0d14', 'ebb0ec50-733f-e811-a964-000d3a34edeb',
'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. A 'PrimitiveValue' node was expected.\r\n at 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.
Upvotes: 3
Views: 1102
Reputation: 22836
The payload should look like this, look at the Json array of users. 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"
}]
}
Upvotes: 1