Problem when POSTing (C# ASP.NET)

chris_bampton
Community Novice

I'm trying to use the Canvas API through C# to create some courses

I set the Authorization header to Bearer ########API KEY########

Content-Type: application/json

Encoding is UTF-8

Request Body:

{"sis_course_id":"AC1001 16/17 S1","name":"Introduction to Archaeology: 16/17 (S1)","course_code":"AC1001","workflow_state":"unpublished","enrollment_term_id":67}

And POST to https://winchester.test.instructure.com/api/v1/accounts/1/courses

It comes back with a 200, and the JSON of a new course.

However, the new course is always 'Unnamed' and doesn't reflect any of the JSON I've sent.

Any ideas?  I'm pretty stumped as it's not throwing any error messages.

Code:

  using (WebClient client = new WebClient())

            {

                client.Encoding = Encoding.UTF8;

                client.Headers[HttpRequestHeader.Authorization] = "Bearer " + token;

                client.Headers[HttpRequestHeader.ContentType] = "application/json";

  string data = "{"sis_course_id":"AC1001 16/17 S1","name":"Introduction to Archaeology: 16/17  S1)","course_code":"AC1001","workflow_state":"unpublished","enrollment_term_id":67}"

                string response = client.UploadString(rootUrl + "/api/v1/accounts/1/courses", "POST", data);

  }

Thanks for any help!

0 Likes