$ ./grades
English: 12.34%
Maths: 56.78%
Science: 90.12%
History: --
Same as grades.sh but written in Elvish.
Tested on Elvish v0.17.0 and xh v0.10.0–v0.14.1.
- Get an API token
https://example.instructure.com/profile/settings
→ ‘Approved Integrations’ → ‘New Access Token’
var host = example.instructure.com # replace with actual host
set-env CANVAS_TOKEN '<your API access token>'
Replace <courseId1>
, <courseId2>
etc. with the ids of the courses that you want to get
the grades of. The id of the course can be found by looking at the course’s URL:
https://example.instructure.com/courses/courseId
.
xhs $host/api/graphql Authorization:Bearer' '$E:CANVAS_TOKEN query='{
legacyNode(_id: "'(
xhs $host/api/v1/users/self Authorization:Bearer' '$E:CANVAS_TOKEN |
from-json |
exact-num (one)[id]
)'", type: User) {
...on User {
Subject1: enrollments(courseId: "<courseId1>") { id }
Subject2: enrollments(courseId: "<courseId2>") { id }
}
}
}' |
from-json |
put (one)[data][legacyNode]
The result will be something like this:
▶ [&Subject1=[[&id=<enrollmentId1>]] &Subject2=[[&id=<enrollmentId2>]]]
Use these ids (<enrollmentId1>
, <enrollmentId2>
, etc.) in query.graphql
.