ClassCharts API (JavaScript/TypeScript)
ClassCharts is a UK education classroom management platform. This skill uses the unofficial classcharts-api JS library to fetch homework, behaviour, timetable, detentions, attendance, announcements, badges, and more. Supports both Parent and Student authentication.
Important: The API is unofficial. Never hardcode credentials in prompts, logs, or committed code. Use environment variables or a secure secret store.
Installation
CODEBLOCK0
Requirements: Node.js 20+ or Deno
Authentication
Two client types with different login flows:
Parent Client
Parent logs in with email and password. Access to all linked pupils.
CODEBLOCK1
Student Client
Student logs in with ClassCharts code and date of birth.
CODEBLOCK2
Date formats
| Use case | Format | Example |
|---|
| API options (from, to, date) | INLINECODE0 | INLINECODE1 |
| Student date of birth (login) |
DD/MM/YYYY |
"01/01/2010" |
| getStudentCode dateOfBirth |
YYYY-MM-DD |
"2010-01-01" |
Shared methods (Parent & Student)
All methods require await client.login() first. Session auto-renews after 3 minutes.
| Method | Options | Description |
|---|
| INLINECODE7 | — | Student profile and metadata |
| INLINECODE8 |
Dates
YYYY-MM-DD, optional pagination | Activity feed (paginated) |
|
getFullActivity({ from, to }) | Dates
YYYY-MM-DD | Activity between dates (auto-paginates) |
|
getBehaviour({ from?, to? }) | Dates
YYYY-MM-DD | Behaviour points timeline and reasons |
|
getHomeworks({ from?, to?, displayDate? }) | Dates,
displayDate:
"due_date" \|
"issue_date" | Homework list |
|
getLessons({ date }) |
date:
YYYY-MM-DD | Timetable for a specific date |
|
getBadges() | — | Earned badges |
|
getAnnouncements() | — | School announcements |
|
getDetentions() | — | Detentions |
|
getAttendance({ from, to }) | Dates
YYYY-MM-DD | Attendance records |
|
getPupilFields() | — | Custom pupil fields/stats |
Parent-only methods
| Method | Description |
|---|
| INLINECODE27 | List pupils linked to parent account |
| INLINECODE28 |
Set active pupil for subsequent requests |
|
changePassword(current, new) | Change parent account password |
Student-only methods
| Method | Description |
|---|
| INLINECODE30 | Rewards shop items and balance |
| INLINECODE31 |
Purchase item from rewards shop |
|
getStudentCode({ dateOfBirth }) | Get student code (dateOfBirth:
YYYY-MM-DD) |
Quick examples
CODEBLOCK3
Response shape
Responses follow ClassChartsResponse<Data, Meta>:
CODEBLOCK4
Errors throw if success === 0.
When to use this skill
- - User asks about ClassCharts, school homework, behaviour points, timetable, detentions, attendance, or rewards.
- User wants to script, integrate, or automate ClassCharts data.
- User mentions parent/student portal in the context of UK schools and ClassCharts.
Links
ClassCharts API (JavaScript/TypeScript)
ClassCharts 是英国教育课堂管理平台。本技能使用非官方的 classcharts-api JS 库来获取作业、行为表现、课程表、留校、出勤、公告、徽章等信息。支持家长和学生两种身份认证。
重要提示: 该API为非官方接口。切勿在提示词、日志或提交的代码中硬编码凭据。请使用环境变量或安全密钥存储。
安装
bash
npm install classcharts-api
系统要求: Node.js 20+ 或 Deno
身份认证
两种客户端类型,登录流程不同:
家长客户端
家长使用邮箱和密码登录。可访问所有关联学生。
typescript
import { ParentClient } from classcharts-api;
const client = new ParentClient(
process.env.CLASSCHARTS_EMAIL!,
process.env.CLASSCHARTS_PASSWORD!,
);
await client.login();
// 默认使用第一个学生;可通过 selectPupil 切换
const pupils = client.pupils; // 或 await client.getPupils()
client.selectPupil(pupils[1].id); // 如有多个孩子
学生客户端
学生使用 ClassCharts 代码和出生日期登录。
typescript
import { StudentClient } from classcharts-api;
// 出生日期必须为 DD/MM/YYYY 格式
const client = new StudentClient(
process.env.CLASSCHARTS_CODE!, // 例如 ABCD1234
01/01/2010,
);
await client.login();
日期格式
| 使用场景 | 格式 | 示例 |
|---|
| API 选项(起始、截止、日期) | YYYY-MM-DD | 2024-03-10 |
| 学生出生日期(登录) |
DD/MM/YYYY | 01/01/2010 |
| getStudentCode 的 dateOfBirth | YYYY-MM-DD | 2010-01-01 |
共享方法(家长和学生)
所有方法均需先调用 await client.login()。会话在3分钟后自动续期。
| 方法 | 选项 | 描述 |
|---|
| getStudentInfo() | — | 学生资料和元数据 |
| getActivity({ from, to, last_id? }) |
日期 YYYY-MM-DD,可选分页 | 活动动态(分页) |
| getFullActivity({ from, to }) | 日期 YYYY-MM-DD | 指定日期间的活动(自动分页) |
| getBehaviour({ from?, to? }) | 日期 YYYY-MM-DD | 行为积分时间线和原因 |
| getHomeworks({ from?, to?, displayDate? }) | 日期,displayDate:due
date \| issuedate | 作业列表 |
| getLessons({ date }) | date:YYYY-MM-DD | 指定日期的课程表 |
| getBadges() | — | 已获得的徽章 |
| getAnnouncements() | — | 学校公告 |
| getDetentions() | — | 留校记录 |
| getAttendance({ from, to }) | 日期 YYYY-MM-DD | 出勤记录 |
| getPupilFields() | — | 自定义学生字段/统计 |
家长专属方法
| 方法 | 描述 |
|---|
| getPupils() | 列出关联家长账户的学生 |
| selectPupil(pupilId) |
设置后续请求的活跃学生 |
| changePassword(current, new) | 更改家长账户密码 |
学生专属方法
| 方法 | 描述 |
|---|
| getRewards() | 奖励商店物品和余额 |
| purchaseReward(itemId) |
从奖励商店购买物品 |
| getStudentCode({ dateOfBirth }) | 获取学生代码(dateOfBirth:YYYY-MM-DD) |
快速示例
typescript
// 获取日期范围内的作业
const homeworks = await client.getHomeworks({
from: 2024-03-01,
to: 2024-03-31,
displayDate: due_date,
});
// 获取今日课程表
const today = new Date().toISOString().slice(0, 10); // YYYY-MM-DD
const lessons = await client.getLessons({ date: today });
// 行为表现摘要
const behaviour = await client.getBehaviour({
from: 2024-01-01,
to: 2024-03-10,
});
// 学生:查看奖励商店并购买
const rewards = await client.getRewards();
const purchase = await client.purchaseReward(rewards.data[0].id);
响应结构
响应遵循 ClassChartsResponse 格式:
typescript
{
success: 1,
data: T, // 根据端点不同为数组或对象
meta: M, // 会话ID、日期、计数等
error?: string
}
如果 success === 0,则会抛出错误。
使用场景
- - 用户询问关于 ClassCharts、学校作业、行为积分、课程表、留校、出勤或奖励的问题。
- 用户希望编写脚本、集成或自动化处理 ClassCharts 数据。
- 用户在涉及英国学校和 ClassCharts 的上下文中提到家长/学生门户。
相关链接