Register for InstructureCon25 • Passes include access to all sessions, the expo hall, entertainment and networking events, meals, and extraterrestrial encounters.
Found this content helpful? Log in or sign up to leave a like!
Hi,
I am setting up many assignments across many different courses.
So I have downloaded the 'Postman' API tool to help with this process.
I have set up my authorisation token and used a GET to display basic course data from our Canvas build to test the connection - which was a success.
I then used POST and created a test assignment in one of our courses using the following JSON code:
{
"assignment": {
"name": "Test assessment 1",
"submission_types": [
"none"
],
"points_possible": 1,
"grading_type": "points",
"due_at": "2015-10-18T00:00:00+01:00",
"muted": "true",
"published": "false"
}
}
Which was also a success - so far all good.
As we have quite a few courses each with many different assignments each with different settings such as the 'points_possible', 'due_at' etc.. so I started a spreadsheet and populated it with the headings of 'name','points_possible','due_at','published','submission_type','description' I then set this up in JSON format using CSV To JSON Converter but there are a few different variations of JSON formatting and none have worked. e.g JSON column array or keyed JSON...
Does anyone have any suggestions on how I can transfer this spreadsheet across to postman and through using the canvas API start adding assignments to our multiple online courses?
Thanks!!
Huw
@h_jones I am not aware of any scripting capabilities in Postman.
I know you can string together a sequence of API calls, but not sure you can "program" it to read a spreadsheet.
Someone may be able to correct me on this, let's see if anyone else chimes in.
Here is an article posted by @James showing how to use Google sheets to make a series of API calls to adjust multiple courses:
This might be a good approach to take.
I have also posted a .NET project showing how to leverage the API in c#.
The code is based on an application I wrote to implement many different types of workflows using the API, and would also be a potential approach.
I hope this helps.
You can't "tell" the API to read from a spreadsheet, but you can have a script (i.e.: PowerShell, Python) read from a spreadsheet or some data file, and pass those values to the API.
I am not wanting Postman to directly read the spreadsheet. I am using raw JSON in postman's body field to create the assignments with a POST action.
The problem i am having is correctly formatting the JSON in an error free way so the API can recognise the JSON and create the new assignments.
The initial data is in a spreadsheet, but I am transferring this to JSON using this tool: CSV To JSON Converter
But every attempt to format/re-format the JSON fails - for example when I attempt to POST the following JSON to https://<institution>.instructure.com/api/v1/courses/<courseid>/assignments :
{
"assignment": [
{
"name": "Review of Space I",
"points_possible": "75",
"due_at": "2016-01-31T00:00:00Z",
"published": true,
"submission_type": "on_paper",
"description": "<h4>Please print out and complete these homework assignments</h4>\n<p>Hand in to your mentor at the end of the due date week."
},
{
"name": "Review of Space II",
"points_possible": "75",
"due_at": "2016-02-07T00:00:00Z",
"published": true,
"submission_type": "on_paper",
"description": "<h4>Please print out and complete these homework assignments</h4>\n<p>Hand in to your mentor at the end of the due date week."
},
{
"name": "Motors & Generators I",
"points_possible": "65",
"due_at": "2016-02-14T00:00:00Z",
"published": true,
"submission_type": "on_paper",
"description": "<h4>Please print out and complete these homework assignments</h4>\n<p>Hand in to your mentor at the end of the due date week."
}
]
}
I get the following error:
{
"errors": [
{
"message": "An error occurred.",
"error_code": "internal_server_error"
}
],
"error_report_id": 580
}
I also get other errors when attempting other types of formatting - for example using an array format also provides the error:
{
"assignment": [
{
"name":["Review of Space I","Review of Space II","Motors & Generators I","Motors & Generators II","Motors & Generators III","Motors & Generators IV","Term 1 Exam","Review & M&G Practicals","Ideas to Implementation I","Ideas to Implementation II"],
"points_possible":["75","75","65","65","65","65","100","-","65","65"],
"due_at":["2016-01-31T00:00:00Z","2016-02-07T00:00:00Z","2016-02-14T00:00:00Z","2016-02-21T00:00:00Z","2016-02-28T00:00:00Z","2016-03-06T00:00:00Z","2016-03-13T00:00:00Z","2016-03-20T00:00:00Z","2016-04-03T00:00:00Z","2016-04-10T00:00:00Z"],
"published":[true,true,true,true,true,true,true,true,true,true],
"submission_type":["on_paper","on_paper","on_paper","on_paper","on_paper","on_paper","on_paper","on_paper","on_paper","on_paper"],
"description":["<h4>Please print out and complete these homework assignments</h4>\n<p>Hand in to your mentor at the end of the due date week.","<h4>Please print out and complete these homework assignments</h4>\n<p>Hand in to your mentor at the end of the due date week.","<h4>Please print out and complete these homework assignments</h4>\n<p>Hand in to your mentor at the end of the due date week.","<h4>Please print out and complete these homework assignments</h4>\n<p>Hand in to your mentor at the end of the due date week.","<h4>Please print out and complete these homework assignments</h4>\n<p>Hand in to your mentor at the end of the due date week.","<h4>Please print out and complete these homework assignments</h4>\n<p>Hand in to your mentor at the end of the due date week.","<h4>Please print out and complete these homework assignments</h4>\n<p>Hand in to your mentor at the end of the due date week.","<h4>Please print out and complete these homework assignments</h4>\n<p>Hand in to your mentor at the end of the due date week.","<h4>Please print out and complete these homework assignments</h4>\n<p>Hand in to your mentor at the end of the due date week.","<h4>Please print out and complete these homework assignments</h4>\n<p>Hand in to your mentor at the end of the due date week."]
}
]
}
So far the only format of JSON that has been successful has been this:
{
"assignment": {
"name": "Test assessment 1",
"submission_types": [
"none"
],
"points_possible": 1,
"grading_type": "points",
"due_at": "2015-10-18T00:00:00+01:00",
"muted": "true",
"published": "false"
}
}
But that only creates one assignment, where I need to create many.
Any Ideas?
Thanks again!
@h_jones take a look at the API documentation:
It is not clear to me that the API supports creating multiple assignments with a single call.
"Create a new assignment for this course. The assignment is created in the active state."
When I read this, it implies that a single assignment will be created.
My interpretation seems to match the result you are getting: a single assignment.
The previous responses to your question point you in the direction of writing an algorithm to read your spreadsheet and make mulitple API calls, one for each assignment. I believe that is the approach you will need to take, but I could be wrong.
I am interested to know if you are able to make a single API call work for your scenario, please post back.
Thanks @garth yes I can make a single assignment with a single API call - but it's the creation of multiple assignments with a single API call that is failing. Which makes me think you are right that the API doesn't support creating multiple assignments with a single call.
That spreadsheet tool looks very useful, I can imagine it would have many uses across lots of areas within canvas.
There appears to be a few variations of this spreadsheet tool listed in Github for doing things like listing admins, due dates and discussion forums etc with the core of this particular spreadsheet tool here: canvancement/dueDates.gs at master · jamesjonesmath/canvancement · GitHub
From what I can gather (I have no prior knowledge of the gs filetype - is it a type of javascript?) the part of the .gs script that uses the API to POST to the course is:
if (changes.length > 0) {
var apicalls = {
'assignment' : 'PUT /api/v1/courses/:course_id/assignments/:id',
'quiz' : 'PUT /api/v1/courses/:course_id/quizzes/:id'
};
for (var i = 0; i < changes.length; i++) {
var item = changes[i];
var type = item.type;
delete item.type;
var result = canvasAPI(apicalls[type], item);
}
}
return;
} catch (e) {
Logger.log(e);
return;
}
But I get lost with the rest of the code and don't feel very confident with my dev skills that I could take my existing spreadsheet of assignments and write a gs code that 'PUT's these assignments into the course.
Looking at your .net canvas api implementation document, maybe I can look at using a pipe | to separate the each assignment and it relative settings within the raw JSON I am using... anyway, I will have a look at that and get back to you.
Thanks
Huw
To interact with Panda Bot in the Instructure Community, you need to sign up or log in:
Sign In