0

When I try sending the request I get an "Internal Error" exception, so I want to know if the problem is in my specific request, or if there is an issue beyond that.

The cUrl request looks like this:

curl https://(canvas_api_url)?access_token=(access-token)

-X POST

-F 'enrollment[user_id]=241'

-F 'enrollment[type]=StudentEnrollment'

My request looks like this:

HttpWebRequest req = WebRequest.Create("https://<canvas_api_url>?access_token=<access-token>");

req.Method = "POST";
req.ContentType = " application/json; charset=utf-8";
req.UseDefaultCredentials = true;
req.PreAuthenticate = true;
req.Credentials = CredentialCache.DefaultCredential;

using (var streamWriter = new StreamWriter(req.GetRequestStream())
{
     string json = "{\"enrollment\" : 
     [\"user_id\" : \"241\", \"type\" : \"StudentEnrollment\"]}";
     streamWriter.Write(json);
}

HttpWebResponse response = req.GetResponse();

Is there something wrong with my request?

Hila Raveh
  • 13
  • 6

1 Answers1

0

I see this post is pretty old, but here's some thoughts based on a quick look at it. You don't say what you're trying to accomplish, so there's a couple potential mistakes here:

  1. If you're requesting an existing enrollment, you should be using GET instead of POST.
  2. If you're trying to create a new enrollment, you haven't structured the endpoint right - you need to specify a course (/api/v1/courses/:course_id/enrollments) and then you can include the user_id and the type.

The specifics are listed in the docs here: https://canvas.instructure.com/doc/api/enrollments.html