Forum Discussion
lvoouiilliot
Dec 02, 2022Copper Contributor
Use SDK for cloning teams, how to get the http response
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 : If you have a...
- Dec 02, 2022In 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
Copper Contributor
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);
//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);
Nivedipa-MSFT
Dec 05, 2022Microsoft
lvoouiilliot
Glad to hear that your issue is resolved. Could you please share your valuable feedback via Microsoft Teams Developer Community Response Feedback.