Score API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024
05:21 AM
Hello.
I'm trying to send the grade and a file back from LTI 1.3 to canvas. The grade is successfully being updated but the file isn't being shown. There is no file attachment and its "No preview available" in the speedgrader for teacher.
I'm using ltijs library..please check the code- it's "/grade" demo endpoint which sends score to canvas..
// Grading route
router.post('/grade', async (req, res) => {
try {
const idtoken = res.locals.token // IdToken
const score = req.body.grade // User numeric score sent in the body
// Creating Grade object
const gradeObj = {
userId: idtoken.user,
scoreGiven: score,
scoreMaximum: 100,
activityProgress: 'Completed',
gradingProgress: 'FullyGraded',
{
"type": "file",
"title": "Submission File",
"media_type": "application/pdf"
}
]
}
// Selecting linetItem ID
let lineItemId = idtoken.platformContext.endpoint.lineitem // Attempting to retrieve it from idtoken
if (!lineItemId) {
console.log("inside if");
const response = await lti.Grade.getLineItems(idtoken, { resourceLinkId: true })
// console.log(response);
const lineItems = response.lineItems
if (lineItems.length === 0) {
// Creating line item if there is none
console.log('Creating new line item')
const newLineItem = {
scoreMaximum: 100,
label: 'Grade',
tag: 'grade',
resourceLinkId: idtoken.platformContext.resource.id,
}
console.log("lineItem");
const lineItem = await lti.Grade.createLineItem(idtoken, newLineItem)
console.log(lineItem);
// const lineItem = await lti.Grade.createLineItem(idtoken, newLineItem)
console.log("after creting lineItem");
lineItemId = lineItem.id
} else lineItemId = lineItems[0].id
}
console.log("before sending grade");
// Sending Grade
const responseGrade = await lti.Grade.submitScore(idtoken, lineItemId, gradeObj)
return res.send(responseGrade)
} catch (err) {
console.log(err.message)
return res.status(500).send({ err: err.message })
}
})