The Instructure Community will enter a read-only state on November 22, 2025 as we prepare to migrate to our new Community platform in early December.
Read our blog post for more info about this change.
I am trying to add an assignment to an existing course through the Canvas API but I am getting the following message.
Greetings,
I'm not a programmer, however I have used the API to create assignments in Python. The thing that pops out to me is that you put the access token in the URL. I'm not sure if that's allowed or not. I put it in the header.
Also, you can send your payload as JSON which I find to be easier to understand and use. I believe you also have to specify that you are using JSON in the header as well. Here is a sample JSON payload for creating an assignment:
{
"assignment": {
"name": "TEST",
"submission_types": [
"none"
],
"points_possible": 1,
"grading_type": "points",
"due_at": "2015-10-18T00:00:00+01:00",
"muted": "true",
"published": "false"
}
}Here is a screenshot of how I setup my Header using Postman which I use to test out API calls before I write something in Python. You have to have the word "Bearer" in front of the token.
The access token is allowed in the query string, but it's discouraged. Adding the access token to the header keeps it out of the query string, which may get logged, and accidentally disclose the token. In general, mixing query parameters and a body with a post action is normally frowned upon, even if the specification allows it.
The problem here is the format of your post body. You are trying to mix a JSON object with www-url-form-encoded requests. You need to do one or the other.
Matt showed you what it should look like and included the necessary content-type: application/json header. You may also want to include an accept: application/json header to let Canvas know it's okay to send a JSON response.
{ "assignment" : { "name" : "Erik Test", "description" : "TEST" } }
If you want to use the field-style format, then you would need set it up like this:
assignment[name]=Erik%20Test&assignment[description]=TEST
I'd recommend going with the JSON way. I create the entire object separately and then make it the value for the assignment key.
// assignmentObject contains the values needed
{ "assignment" : assignmentObject }
It depends on which REST library you're using as to whether you will need to convert that object to a JSON string before sending it.
Community helpTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign inTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign in
This discussion post is outdated and has been archived. Please use the Community question forums and official documentation for the most current and accurate information.