AnsweredAssumed Answered

How to Pass Body parameters to delete enrollment using ASP.Net?

Question asked by Ramadevi chinthala on Oct 12, 2018
Latest reply on Oct 16, 2018 by Ramadevi chinthala

Hi,


I would like to delete the enrollment by passing enrollmentID using ASP.Net.

 

Example Request:

curl https://<canvas>/api/v1/courses/:course_id/enrollments/:enrollment_id \

  -X DELETE \

  -F 'task=delete’


Could you please help me how to pass the body parameters(task=delete) in the below code?

I tried to attach to the urlcommand(/api/v1/courses/:course_id/enrolments/:enrolment_id/task=delete) but it throws the error.

  protected static async Task<HttpResponseMessage> httpDELETE(string baseUrl, string urlCommand,      string accessToken)     
   {         
   HttpResponseMessage response = null;

 

            try           
                 {

 

                      HttpClientHandler handler = new HttpClientHandler(); 

                      handler.AllowAutoRedirect = false;

 

                     using (HttpClient client = new HttpClient(handler, true))              
                       {                                     
                          client.BaseAddress = new Uri(baseUrl);     

                          client.DefaultRequestHeaders.Accept.Clear();   

                          client.DefaultRequestHeaders.Authorization =             new    AuthenticationHeaderValue("Bearer", accessToken);
                    

                   response = client.DeleteAsync(urlCommand).Result;   
                        }            
                  }           
 catch (Exception err)          
  {           
  }           
        return response;    
    }

Thanks,
Devi.

Outcomes