I am trying to develop a C# program that will post files as student assignment submissions into Canvas via Canvas API.
- The documentation I am following is here
Uploading Files - Canvas LMS REST API Documentation
- The issue I am having is on the step 1 in that documentation.
- The error I am getting is 401 Unauthorized.
- The token is from an account admin.
- The course is published and so is the assignment.
- The assignment is not due yet.
- Fail on both production Canvas and Test Canvas instance.
- The same code works for other POST method like create a new assignment.
- Form data is
var formData = new Dictionary<string, string>()
- Same error (401) returns from the live api page, but I guess that was not suppose to work there since the form data about the file are missing.
- In addition to token, I also set the following headers
httpWebRequest.Method = "POST";
httpWebRequest.Host = CanvasHost;
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.Accept = "application/json";
httpWebRequest.ContentLength = byteArray.Length;
- the form data is write to the request in bytes that are in UTF8 encoding.