1

I'm currently working on an application in which we could create teams from customize template and delete them simply. I picked Azure function to create my teams as it is more flexible. So I do a POST with Graph SDK of C# for creating my new team by cloning the templates in our database. But, if we want to delete a team, we need to have the id of the team. So I want to get the response of the response of the my POST which let me create my new team.

So how can I get it? Here you are my POST for cloning my new team.

await graphClient.Teams[teamIDToCopy]
                        .Clone(visibility,partsToClone,displayName,description,mailNickname,null)
                        .Request()
                        .PostAsync();

Any help appreciated, thanks in advance.

yucongzhao
  • 15
  • 5

2 Answers2

1

From MS Graph REST API documentation:

Cloning is a long-running operation. After the POST clone returns, you need to GET the operation returned by the Location: header to see if it's "running" or "succeeded" or "failed". [...]

Response
The following is an example of the response. Note: The response object shown here might be shortened for readability.

HTTP/1.1 202 Accepted
Location: /teams({id})/operations({opId})
Content-Type: text/plain
Content-Length: 0

So in order to get the id of the newly created team, you need to grab that information from the response header.

You could try something like this (Inspired by this answer)

var message = graphClient.Teams[teamIDToCopy]
    .Clone(visibility,partsToClone,displayName,description,mailNickname,null)
    .Request()
    .GetHttpRequestMessage();

message.Method = HttpMethod.Post;
//[...]
var response = graphClient.HttpProvider.SendAsync(message).Result;
var location = response.Headers.Location;

(Unfortunately, I could not test this yet.)

Stephan Bauer
  • 9,120
  • 5
  • 36
  • 58
  • Thanks in advance for your help. In fact, in the example of the File copy (https://stackoverflow.com/a/62603155/314334), we have the "new DriveItemCopyRequestBody" to give our POST a request body, but in our case, I don't know what I should use exactly for adding a body to my POST request. So do you know what I could use to give my POST request a body, please? – yucongzhao Jul 20 '21 at 08:27
0

When clonning a team API call initiates, it returns '202 Accepted' response code and the 'Location' header contains the operation ID.

Location: /teams({id})/operations({opId})

This graph API call transcends the lifetime of a single API request. So, once the operation ID is available, to get the new team ID, we need to periodically call following GET API mentioning the operation ID:

/teamID/operationID

Here, teamID: The team ID to be clone operationID: The value from header 'Location'. Each periodic API call of above API will return a result containing 'status' property. We need to call the above API until we get the 'status' property value as 'succeeded'. Once, the API status value is succeeded, the API response contains the value for 'targetResourceId' which the GUID of cloned team ID.

Prasad-MSFT
  • 660
  • 1
  • 3
  • 7