POST Submission via API result in 401 Unauthorized
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2016
07:05 PM
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.
POST /v1/courses/{course_id}/assignments/{assignment_id}/submissions/{user_id}/files - The error I am getting is 401 Unauthorized.
Details:
- 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>()
{
{"name", "sampleFile.pdf"},
{"size", fileInfo.Length.ToString()},
{"content_type", "application/pdf"}
};
- 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.
Any suggestions?
Doug
Solved! Go to Solution.
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2016
10:35 AM
I'm assuming that you're trying to post assignments on behalf of another user. If so, you should read the masquerading docs.