Submit file to assignment via API

juan_londono
Community Novice

Hi

I'm trying to submit an assignment via the API using C#. I have the file uploaded to the user's folder and now I need to link the file (with id =28386) to the assignment (id=1855) but I get a status  code 400 : "Bad Request" because of "No valid file ids given". I think it's the same issue as in https://community.canvaslms.com/thread/12970-submit-assignment-via-api 

This is my code:

Dictionary<string, string> vars = new Dictionary<string, string>();

vars.Add("comment[text_comment]", "My comments here");
vars.Add("submission[submission_type]", "online_upload");
vars.Add("submission[file_ids][]", "28386"); // also tried without the '[]'


var p1Content = new FormUrlEncodedContent(vars.ToArray());
using (HttpResponseMessage response = await httpPOST(baseUrl, "/api/v1/courses/330/assignments/1855/submissions", accessToken, p1Content))
{

}

Many thanks in advanced for your help

Labels (1)