LTI 1.3 submit score throws error

LTI 1.3 submit score throws error

Vitalii Volkov -
回帖数:5
Hi. 

I am having issue when sumbitting scores to moodle using lti 1.3 integration. I am following official imsglobal spec.

In external tool for IMS LTI Assignment and Grade services I have selected "Use this service for grade sync and column management".

Then I make a post request to lineitemurl/scores with token in the header and score in the body like:

{ ActivityProgress = ActivityProgress.Completed, GradingProgress = GradingProgess.FullyGraded, ScoreGiven = scoreReceived, ScoreMaximum = 100, TimeStamp = DateTime.UtcNow, UserId = ltiRequest.UserId }

but getting in reply that score is incorrect:
Error:"Incorrect score received{\"activityProgress\":\"Completed\",\"comment\":null,\"gradingProgress\":\"FullyGraded\",\"scoreGiven\":80.0,\"scoreMaximum\":100.0,\"timestamp\":\"2023-06-21T16:14:31.0469841Z\",\"userId\":\"7\"}"

However mentioned in error score is compliant with imsglobas spec.

Do you know how to fix it? I can't find api logs in moodle interface.
回复Vitalii Volkov

Re: LTI 1.3 submit score throws error

Jake Dallimore -
Core developers的头像 Moodle HQ的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 Plugin developers的头像 Testers的头像
Hi Vitalii,

What stands out here is the backslashes in the body. That's breaking the JSON, and shouldn't be there. If you remove that, the grade should be processed fine.

Hope that helps,
Jake
回复Jake Dallimore

Re: LTI 1.3 submit score throws error

Vitalii Volkov -
Hey, thanks for your help.

I tried what you proposed so now instead of sending string content as I was doing before I am sending json content an before sending it doesn't have any backslashes, i also verified that context is [RFC4627] compatible, but I still get backslashes in the error and I suspect It’s possible that the backslashes are not actually part of the request body that is being sent to the API, but are instead being added by the logging mechanism in Moodle when the error message is generated to escape " character in the string.

I also read this spec http://www.imsglobal.org/sites/default/files/lti/ltiv2p1/model/mediatype/application/vnd/ims/lis/v1/score+json/index.html#_RFC4627_
and added mentioned as mandatory 2 fields: @type and @context.
But I still getting the same error.
Failed:PostingScore:Error:"Incorrect score received{\"@type\":\"Score\",\"@context\":\"http://purl.imsglobal.org/ctx/lis/v2/Score\",\"activityProgress\":\"Completed\",\"comment\":null,\"gradingProgress\":\"FullyGrade

Do you know how can I get more data about what is incorrect, maybe moodle has API logs?

Thank you very much.
回复Vitalii Volkov

Re: LTI 1.3 submit score throws error

Jake Dallimore -
Core developers的头像 Moodle HQ的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 Plugin developers的头像 Testers的头像
Hi Vitalii,

Firstly, I would only be looking at the official AGS 2.0 specification document: https://www.imsglobal.org/spec/lti-ags/v2p0/#score-publish-service (login is required to view). That has all you need there. That spec also links to the OpenAPI spec for score posting: https://www.imsglobal.org/spec/lti-ags/v2p0/openapi/#/default/Scores.POST. Neither of these list those additional @type and @context fields, so definitely remove those.

Re logging, the short answer is no. Moodle has rather poor debugging within LTI and unfortunately this leads to situations like yours, where it's hard to isolate the problem. The only other option would be to manually debug this using a local Moodle install - provided you have access to that. Then I'd be stepping through the code with breakpoints, etc.

You can see the code responsible for this validation here:
https://github.com/moodle/moodle/blob/27cbb5965ea34dc142a519cfa72be8cdab353156/mod/lti/service/gradebookservices/classes/local/resources/scores.php#L173C1-L186

A quick look at your (original) request and my suspicion would fall on:
  1. it can't decode the JSON (due to backslashes). Moodle doesn't add these as part of the exception generation (you can see that here: https://github.com/moodle/moodle/blob/27cbb5965ea34dc142a519cfa72be8cdab353156/mod/lti/service/gradebookservices/classes/local/resources/scores.php#L186), hence my first comment about these being suspect. They could, of course, be added somewhere between Moodle and where you're seeing the error reported in your tool/postman/etc. I can't speak for that.
  2. the is_user_gradable_in_course() check. Make sure the user "7" is in the course and is a student.
Failing those obvious things, I'd be falling back on the 'debug a local Moodle' approach mentioned above. It's just too hard to guess at what it might be otherwise.

Cheers,
回复Jake Dallimore

Re: LTI 1.3 submit score throws error

Vitalii Volkov -
Hi again,

Indeed the problem was because the user was not enrolled on the course and had admin permissions so it was possible to launch the course without being enrolled.

Error saying "invalid score" is quite misleading though, but I am glad you sent me the code responsible for that.

Thank you for your help and useful links.
Cheers.
回复Vitalii Volkov

Re: LTI 1.3 submit score throws error

Jake Dallimore -
Core developers的头像 Moodle HQ的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 Plugin developers的头像 Testers的头像
I couldn't agree more about the need for better debugging. Most of the errors in mod/lti are extremely unhelpful. Glad you got past it in this instance.