celtic-project / LTI-PHP

PHP class library for building LTI integrations
GNU Lesser General Public License v3.0
47 stars 37 forks source link

Troubleshooting AGS ResourceLink->doOutcomesService() #63

Closed danhammari closed 11 months ago

danhammari commented 11 months ago

Hi Stephen,

I have been trying to send grades over to the Schoology LMS using the Assignment and Grades Services (AGS) protocol, and am having trouble with the ResourceLink class doOutcomesService() method. Though I enter the method, the logic cannot determine which outcomes service to use from the collection of variables. I added this logic so I could review the collected variables:

var_dump([
    'urlAGS' => $urlAGS,
    'urlLTI11' => $urlLTI11,
    'urlExt' => $urlExt,
    'has_configured_outcomes_service_hook' => $this->hasConfiguredApiHook(self::$OUTCOMES_SERVICE_HOOK, $this->getPlatform()->getFamilyCode(), $this),
]);
die(__FILE__ . __LINE__);

And this is the outcome I receive:

array(4) {
    ["urlAGS"]=> string(0) ""
    ["urlLTI11"]=> string(0) ""
    ["urlExt"]=> string(0) ""
    ["has_configured_outcomes_service_hook"]=> bool(false)
}
/online-api/vendor/celtic/lti/src/ResourceLink.php729

These values maye it so I don't hit on any of the if statements that trigger the various outcomes services options. I had expected to trigger the first option, AGS, but the urlAGS variable is populated with this statement:

$urlAGS = $sourceResourceLink->getSetting('custom_lineitem_url');

However, the custom_lineitem_url variable seems to be missing from the data that I received from Schoology:

{
    "custom_lineitems_url":"https://lti-service.svc.schoology.com/lti-service/tool/6372124883/services/assignment-grade/v2p0/sections/6882476228/lineitems",
    "custom_ags_scopes":"
        https://purl.imsglobal.org/spec/lti-ags/scope/lineitem,
        https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly,
        https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly,
        https://purl.imsglobal.org/spec/lti-ags/scope/score",
    "custom_assignment_id":"1048",
    "custom_publication_id":"61",
    "custom_deeplink_type":"assignment",
    "custom_week_id":"2071",
    "custom_unit_id":"96",
    "custom_username":"dan.hammari"
}

It appears that I am receiving custom_lineitems_url while the code is looking for custom_lineitem_url. From the LTI documentation, it appears that both may be considered valid options: https://www.imsglobal.org/spec/lti-ags/v2p0/#assignment-and-grade-service-claim

The claim defines the following properties:

lineitems: the endpoint URL for accessing the line item container for the current context. May be omitted if the tool has no permissions to access this endpoint.
lineitem: when an LTI message is launching a resource associated to one and only one lineitem, the claim must include the endpoint URL for accessing the associated line item; in all other cases, this property must be either blank or not included in the claim.

It seems that the custom_lineitem_url variable is optional. Should we look for custom_lineitems_url instead?

spvickers commented 11 months ago

If you are not given a custom_lineitem_url by the LTI platform then you will need to request a list of existing line items (or create your own line item) using the Line Item service, in order to get an endpoint to which you can send a score.

danhammari commented 11 months ago

Thanks. I'll give that a try.