-
Notifications
You must be signed in to change notification settings - Fork 263
Description
Hi,
I have a little tool which creates and manages User for me (local Active Directory -> Sync to Azure AD). I can assigne a User to multiple Groups and this worked just fine with Graph api SDK < V5. I Used to do the following:
var directoryObject = new DirectoryObject
{
Id = userid
};
try
{
foreach (String i in groupids)
{
await graphClient.Groups[i].Members.References
.Request()
.AddAsync(directoryObject);
}
}
Now with the new Update to Graph API SDK V5 a lot has changed and i got everythink working (Get Users, Get Groups, Get&Set Licenses, etc...) except this step. To do it for SDK v5 i do the following:
var requestbody = new ReferenceCreate
{
OdataId = graphClient.DirectoryObjects[userid].ToGetRequestInformation().URI.ToString(),
};
foreach (String i in groupids)
{
await graphClient.Groups[i].Members.Ref.PostAsync(requestbody);
}
This always works for ONE! Group. When the Second Group is set, I get the following Error:
an unexpected 'end of input' node was found when reading from the json reader
So i guessed i try doing it in Bulk:
var requestbody = new ReferenceCreate
{
OdataId = graphClient.DirectoryObjects[userid].ToGetRequestInformation().URI.ToString(),
};
try
{
var batchRequestContent = new BatchRequestContentCollection(graphClient);
foreach (String i in groupids)
{
var requestStepId = await batchRequestContent.AddBatchRequestStepAsync(graphClient.Groups[i].Members.Ref.ToPostRequestInformation(requestbody));
}
var batchResponse = await graphClient.Batch.PostAsync(batchRequestContent);
And again, even with the Bulk Method, the User is only added to ONE Group.
If i look inside the Responsemessage from the failing step of the Bulk i got:
Bad Request
yet if i try the same Update with Graph Explorer everything works fine.
What is my error here? The Group-IDs are correct and the User-ID is correct. Is there an easy way to add ONE user to Multiple Groups in Graph API SDK v5? Or am i just missing a hughe Point?