Improve usage of ReferenceCreate
Is your feature request related to a problem? Please describe. While upgrading vom v4 to v5 I wrote the following code to add a member to a group:
await serviceClient.Groups[groupId.ToString()].Members.Ref
.PostAsync(new ReferenceCreate { OdataId = user.Id });
Unfortunately this throws this error message:
{
"error": {
"code": "BadRequest",
"message": "Invalid URL format specified in payload."
}
}
After some search in the documentation the body should look like
{
"@odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/{id}"
}
but the above C# code omits the url (cause it simply takes the raw given string, which is the id only in my case.
Describe the solution you'd like
Unfortunately the ReferenceCreate class can't simply prepend the need directoryObject path, cause this class will be used in different places and the url could also point to /education/user, /user/, /device/ and potentially other types. For this purpose it would be great if the class could maybe get either some kind of derived classes like ReferenceCreateDirectoryObject or some kind of factory method like ReferenceCreate.ForDirectoryObject(string id).
Describe alternatives you've considered My current workaround is to build the url through the service client by using this code:
var referenceCreate = new ReferenceCreate{ OdataId = serviceClient.DirectoryObjects[user.Id].ToGetRequestInformation().URI.ToString() };
But it feels too complicated and should be made easier.