-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EmployeeExperience.Communities.PostAsync does not return any response #785
Comments
The community creation API is asynchronous so it requires some additional work, not sure if there is a better way, but in the meantime you can try this: First create the community, this will start a long running operation that creates the community asynchronously. var community = new Community
{
DisplayName = displayName,
Description = description,
Privacy = CommunityPrivacy.Public
};
var nativeResponseHandler = new NativeResponseHandler();
await _graphServiceClient.EmployeeExperience.Communities.PostAsync(community, requestConfiguration => requestConfiguration.Options.Add(new ResponseHandlerOption() { ResponseHandler = nativeResponseHandler }));
using var responseMessage = nativeResponseHandler.Value as HttpResponseMessage;
if (responseMessage == null || responseMessage?.StatusCode != System.Net.HttpStatusCode.Accepted)
{
throw new Exception($"Failed to create community. Status code: {responseMessage?.StatusCode}");
} Now that the operation is started we can retrieve it's id from the
We can now poll the long running operation to wait for the community creation to complete: // Now we need to poll the long running operation for status updates.
string? communityId = null;
var retryCount = 0;
while (communityId == null && retryCount <= 5)
{
retryCount++;
await Task.Delay(5000);
var operation = await _graphServiceClient.EmployeeExperience.EngagementAsyncOperations[operationId].GetAsync();
if (operation == null)
{
continue;
}
if (operation.Status.Value == LongRunningOperationStatus.Failed)
{
throw new Exception($"Failed to create community: {operation.StatusDetail}");
}
if (operation.Status.Value == LongRunningOperationStatus.Succeeded)
{
communityId = operation.ResourceId;
break;
}
} Once it completes successfully, we can get the community: if (communityId == null)
{
throw new Exception($"Failed to create community. Operation timed out.");
}
// Now we have the community id, we can fetch the created community.
return await _graphServiceClient.EmployeeExperience.Communities[communityId].GetAsync(); |
Thanks for the response @timward60 As the documentation higlights, the API response is a 202 response code with no body hence why the returned value is null by the sdk. |
What's the goal?
Create a Viva Engage Community with the EmployeeExperience.Communities.PostAsync method and retrieve the ID of the group.
How is it failing?
Using the below code, I can see that I successfully created the group (via checking the VivaEngage GUI) but the method returns null, so I am unable to tell within the codebase if the group was successfully created and what ID it was assigned.
Checking the Viva Engage GUI, I can see that the group is created and I am the owner but the method still returns null.
I think it may be noteworthy that the method returns a Microsoft.Graph.Beta.Models.Community but the documentation suggests that we would receive a http response indicating a success response.
Below is a screenshot during a breakpoint.

Used for testing:
latest Graph Beta SDK from Nuget (v5.60.0-preview)
Windows 11
.NET 6
The text was updated successfully, but these errors were encountered: