I know, the question sounds a bit strange, because according to OData documentation if you would like to select a single entity you should use request like /Endpoint('entityID')
However, I need to work with Dynamics365 Finance and Operations and need to work with Security roles.
If I need to select all role mappings I can use:
/data/SecurityUserRoles
That gives result like:
{
"@odata.context": "https://****.dynamics.com/data/$metadata#SecurityUserRoles",
"value": [
{
"@odata.etag": "W/\"JzEsNTYzNzc2NjQwNSc=\"",
"UserId": "UserIDValue",
"SecurityRoleIdentifier": "11111111-1111-1111-1111-C3C8BC7DB911",
"AssignmentStatus": "Enabled",
"AssignmentMode": "Manual",
"SecurityRoleName": "Some Role Name",
"UserLicenseType": "Enterprise"
} ]
}
There is no ID of the mapping, so if I would like to get a single mapping I can use request like:
/data/SecurityUserRoles?$filter=UserId eq 'UserIDValue' and SecurityRoleIdentifier eq '11111111-1111-1111-1111-C3C8BC7DB911'
It works good. However it returns data in the same format, like response above - and 'value' contains array of records, even though it is a single record. Everything would be fine, but I need to PATCH or DELETE this mapping. And the pitfall is that if I run PATCH or DELETE request using the same filter - I would get error:
More than one resource was found when selecting for update.
This is clear, because 'value' contains array, after using filter. Is there any way to return single entity using filter, so 'value' would not contain array, but just an object? Or maybe there are some other way to reference such objects without knowing ID?
Thanks in advance
So here is solution if someone is looking for the same:
You don't need to use filter. You can get particular entity by using request like:
/data/SecurityUserRoleAssociations(UserId ='UserIDValue',SecurityRoleIdentifier='11111111-1111-1111-1111-C3C8BC7DB911')
This request will return single entity (not array) and you can do everything you need with this entity - like PATCH, DELETE.