You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
The issue is with ReferenceCreate, you need to create a new instance of ReferenceCreate for each group. The ReferenceCreate and other Graph SDK models implement the backing store that tracks changes in properties. Once the instance of ReferenceCreate is serialized to the body of the first request, it's not serialized in other requests.
foreach (var groupId in groupIds)
{
var referenceCreate = new ReferenceCreate
{
OdataId = $"https://graph.microsoft.com/v1.0/directoryObjects/${userId}"
};
var request = graphClient.Groups[groupId].Members.Ref.ToPostRequestInformation(referenceCreate);
await batchRequestContent.AddBatchRequestStepAsync(request);
}
var returnedResponse = await graphClient.Batch.PostAsync(batchRequestContent);
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:
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:
This always works for ONE! Group. When the Second Group is set, I get the following Error:
So i guessed i try doing it in Bulk:
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:
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?
The text was updated successfully, but these errors were encountered: