SOLVED

Use SDK for cloning teams, how to get the http response

Copper Contributor

Hi, I'm currently developping an azure function in c#, and I wondered, how can I get back the http Rresponse of a request using the SDK, for exemple i have the code below :

 

lvoouiilliot_0-1669970679389.png

 

If you have an idea, don't hesit to reply to this post

3 Replies

@lvoouiilliot - Could you please try the code like below:
Save the result into variable
example: var me = await graphClient.Me.Request().GetAsync();

best response confirmed by lvoouiilliot (Copper Contributor)
Solution
In this case it works because it is not a post request, when you wanna use a post request you can't save the result in a variable because she returns anything but I found how I can get the Result with the code below, I tested and it works:
//Set up the request URL to fetch
string requestUrl = "https://graph.microsoft.com/v1.0/teams/" + teamID + "/clone";
log.LogInformation("requestUrl: " + requestUrl);

//Convert the content of the request in json
var content = JsonConvert.SerializeObject(new { visibility, partsToClone, displayName = name, description, mailNickname = mail });
log.LogInformation("content: " + content);

//Create an HTTP request
var hrm = new HttpRequestMessage(HttpMethod.Post, requestUrl);
hrm.Content = new StringContent(content, Encoding.UTF8, "application/json");

//Set up the auth from graphClient
await graphClient.AuthenticationProvider.AuthenticateRequestAsync(hrm);

//Execute Request and show the Status Code
var response = await graphClient.HttpProvider.SendAsync(hrm);
log.LogInformation("response :" + response.StatusCode);

@lvoouiilliot 
Glad to hear that your issue is resolved. Could you please share your valuable feedback via Microsoft Teams Developer Community Response Feedback.

1 best response

Accepted Solutions
best response confirmed by lvoouiilliot (Copper Contributor)
Solution
In this case it works because it is not a post request, when you wanna use a post request you can't save the result in a variable because she returns anything but I found how I can get the Result with the code below, I tested and it works:
//Set up the request URL to fetch
string requestUrl = "https://graph.microsoft.com/v1.0/teams/" + teamID + "/clone";
log.LogInformation("requestUrl: " + requestUrl);

//Convert the content of the request in json
var content = JsonConvert.SerializeObject(new { visibility, partsToClone, displayName = name, description, mailNickname = mail });
log.LogInformation("content: " + content);

//Create an HTTP request
var hrm = new HttpRequestMessage(HttpMethod.Post, requestUrl);
hrm.Content = new StringContent(content, Encoding.UTF8, "application/json");

//Set up the auth from graphClient
await graphClient.AuthenticationProvider.AuthenticateRequestAsync(hrm);

//Execute Request and show the Status Code
var response = await graphClient.HttpProvider.SendAsync(hrm);
log.LogInformation("response :" + response.StatusCode);

View solution in original post