Skip to content
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

V5 Clone Team method doesn't have a return result #1778

Closed
idealser opened this issue Mar 28, 2023 · 5 comments
Closed

V5 Clone Team method doesn't have a return result #1778

idealser opened this issue Mar 28, 2023 · 5 comments

Comments

@idealser
Copy link
Contributor

idealser commented Mar 28, 2023

I'm migrating from V4. Previously to clone a Team we could use this code:

var response =  GraphClient.Teams[team.Id].Clone(...params).Request().PostResponseAsync();
var location = response.HttpHeaders.Location.ToString();
// get the result from location URL

In V5 it's something like this:

var body = new Microsoft.Graph.Teams.Item.Clone.ClonePostRequestBody
{
// params
};
await GraphClient.Teams[team.Id].Clone.PostAsync(body);

The new V5 Clone method doesn't have a return result. By the fact, Create team request which also worked on V4 with location URL now returns us an instance of created Team. Clone request for some reason doesn't.

What is the recommended approach to get the cloned team in V5?

@ghost ghost added the Needs: Triage label Mar 28, 2023
@idealser idealser changed the title V5 Clone Team action doesn't have a result V5 Clone Team method doesn't have a return result Mar 28, 2023
@andrueastman
Copy link
Member

Thanks for raising this @idealser

Any chance this works out for you?
https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/dev/docs/upgrade-to-v5.md#native-response-object

        var nativeResponseHandler = new NativeResponseHandler();
        var body = new Microsoft.Graph.Teams.Item.Clone.ClonePostRequestBody
        {
            // params
        };
        await graphClient.Teams["team-id"].Clone.PostAsync(body, requestConfiguration => requestConfiguration.Options.Add(new ResponseHandlerOption() { ResponseHandler = nativeResponseHandler }));

        var responseMessage = nativeResponseHandler.Value as HttpResponseMessage;
        var locationheader = responseMessage.Headers.Location.OriginalString;

@idealser
Copy link
Contributor Author

Thank you @andrueastman, it works. By the way, is there any plan to change the Clone behaviour to return the created team, like it works now with Create?

@andrueastman
Copy link
Member

Thanks for confirming.
As the API response does not return an object at the moment, but an operation there is plans to add an long running operation handler at microsoftgraph/msgraph-sdk-design#83

https://learn.microsoft.com/en-us/graph/api/team-clone?view=graph-rest-1.0&tabs=http#response-1

@idealser
Copy link
Contributor Author

But what about Create Team API? It is also async but now SDK wraps the operation result somehow. Why is it different for Clone for ex?

https://learn.microsoft.com/en-us/graph/api/team-post?view=graph-rest-1.0&tabs=csharp

@idealser
Copy link
Contributor Author

Thanks for raising this @idealser

Any chance this works out for you? https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/dev/docs/upgrade-to-v5.md#native-response-object

        var nativeResponseHandler = new NativeResponseHandler();
        var body = new Microsoft.Graph.Teams.Item.Clone.ClonePostRequestBody
        {
            // params
        };
        await graphClient.Teams["team-id"].Clone.PostAsync(body, requestConfiguration => requestConfiguration.Options.Add(new ResponseHandlerOption() { ResponseHandler = nativeResponseHandler }));

        var responseMessage = nativeResponseHandler.Value as HttpResponseMessage;
        var locationheader = responseMessage.Headers.Location.OriginalString;

Also, in case you have a 400 error during the Post call, responseMessage.Headers.Location.will be null, and you will get an ObjectReference exception. So there is a need to add hadling of unsuccessful results since PostAsync won't throw you any error because we have a custom response handler

@ghost ghost locked as resolved and limited conversation to collaborators Apr 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants