cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Surveyor

POST Submission via API result in 401 Unauthorized

Jump to solution

I am trying to develop a C# program that will post files as student assignment submissions into Canvas via Canvas API.

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

Labels (1)
1 Solution

Accepted Solutions
Highlighted
Community Member

I'm assuming that you're trying to post assignments on behalf of another user.  If so, you should read the masquerading docs.

View solution in original post

1 Reply
Highlighted
Community Member

I'm assuming that you're trying to post assignments on behalf of another user.  If so, you should read the masquerading docs.

View solution in original post