microsoftgraph / microsoftgraph/msgraph-sdk-dotnet
Improve usage of ReferenceCreate
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 789
- Forks
- 264
- Avg merge
- 15h 17m
- Merged PRs (30d)
- 3
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by inspecting ReferenceCreate and the Groups[groupId].Members.Ref usage shown in the issue, then compare it with the documented group-members request and the DirectoryObjects workaround. Done should provide a simpler, type-safe way to construct directory-object references without breaking references for other resource types, with coverage for the supported construction paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100