Submit Assignment via API

Jump to solution
d_tan
Community Participant


I followed the documentation here to submit a file ...

Uploading Files - Canvas LMS REST API Documentation

The end result is a file added to the user's personal file space, and I got back a file id. I can preview the file and I can download this file.

Then I want to use this file as assignment submission for the same user, which is done by this Canvas API.

Submissions - Canvas LMS REST API Documentation

But I am getting "No valid file ids given" error when calling that API. Can someone point me on the right path?

(code is in C#)

var url = $"https://{CanvasHost}/api/v1/courses/{CanvasCourseId}/assignments/{CanvasAssignmentId}/submissions?as_user_id={CanvasUserId}";

var formData = new Dictionary<string, string>

{

  {"comment[text_comment]", "submitted via FST"},

  {"submission[submission_type]", "online_upload"},

  {"submission[file_ids]", $"{fileSubmissionResult.CanvasFileId}"}

};

Labels (1)
1 Solution
d_tan
Community Participant
Author

I did get it to work, my above code is almost correct, except you need to use this instead.

{"submission[file_ids][]", $"{fileSubmissionResult.CanvasFileId}"}

View solution in original post