AnsweredAssumed Answered

POST Submission via API result in 401 Unauthorized

Question asked by Douglas Tan on Aug 17, 2016
Latest reply on Aug 18, 2016 by Cameron Moore

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




  • 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?