Forum Discussion

lvoouiilliot's avatar
lvoouiilliot
Copper Contributor
Dec 02, 2022

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...
  • lvoouiilliot's avatar
    lvoouiilliot
    Dec 02, 2022
    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);

Resources