Developer-friendly & type-safe Typescript SDK specifically catered to leverage oneroster API.
OneRoster API: # Authentication
All endpoints require authentication using the Authorization: Bearer <token>
header.
The token can be obtained with:
curl -X POST https://alpha-auth-development-idp.auth.us-west-2.amazoncognito.com/oauth2/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials&client_id=<your-client-id>&client_secret=<your-client-secret>"
Use the correct IDP server depending on the environment you're using:
-
Production Server:
https://alpha-auth-production-idp.auth.us-west-2.amazoncognito.com
-
Staging Server:
https://alpha-auth-development-idp.auth.us-west-2.amazoncognito.com
Reach out to the platform team to get a client/secret pair for your application.
Our API uses offset pagination for list endpoints. Paginated responses include the following fields:
offset
: Offset for the next page of resultslimit
: Number of items per page (default: 100)
Example request:
GET /ims/oneroster/rostering/v1p2/users?offset=20&limit=20
All listing endpoints support offset pagination.
All listing endpoints support filtering using the filter
query parameter, following 1EdTech's filtering specification.
The filter should be a string with the following format:
?filter=[field][operator][value]
Example request:
GET /ims/oneroster/rostering/v1p2/users?filter=status='active'
Example request with multiple filters:
GET /ims/oneroster/rostering/v1p2/users?filter=status='active' AND name='John'
Filtering by nested relations is not supported.
All listing endpoints support sorting using the sort
and orderBy
query parameters, following 1EdTech's sorting specification
Example request:
GET /ims/oneroster/rostering/v1p2/users?sort=lastName&orderBy=asc
The SDK can be installed with either npm, pnpm, bun or yarn package managers.
npm add @superbuilders/oneroster
pnpm add @superbuilders/oneroster
bun add @superbuilders/oneroster
yarn add @superbuilders/oneroster zod
# Note that Yarn does not install peer dependencies automatically. You will need
# to install zod as shown above.
Note
This package is published with CommonJS and ES Modules (ESM) support.
This SDK is also an installable MCP server where the various SDK methods are exposed as tools that can be invoked by AI applications.
Node.js v20 or greater is required to run the MCP server from npm.
Claude installation steps
Add the following server definition to your claude_desktop_config.json
file:
{
"mcpServers": {
"OneRoster": {
"command": "npx",
"args": [
"-y", "--package", "@superbuilders/oneroster",
"--",
"mcp", "start",
"--client-id", "...",
"--client-secret", "...",
"--token-url", "..."
]
}
}
}
Cursor installation steps
Create a .cursor/mcp.json
file in your project root with the following content:
{
"mcpServers": {
"OneRoster": {
"command": "npx",
"args": [
"-y", "--package", "@superbuilders/oneroster",
"--",
"mcp", "start",
"--client-id", "...",
"--client-secret", "...",
"--token-url", "..."
]
}
}
}
You can also run MCP servers as a standalone binary with no additional dependencies. You must pull these binaries from available Github releases:
curl -L -o mcp-server \
https://github.com/{org}/{repo}/releases/download/{tag}/mcp-server-bun-darwin-arm64 && \
chmod +x mcp-server
If the repo is a private repo you must add your Github PAT to download a release -H "Authorization: Bearer {GITHUB_PAT}"
.
{
"mcpServers": {
"Todos": {
"command": "./DOWNLOAD/PATH/mcp-server",
"args": [
"start"
]
}
}
}
For a full list of server arguments, run:
npx -y --package @superbuilders/oneroster -- mcp start --help
For supported JavaScript runtimes, please consult RUNTIMES.md.
import { OneRoster } from "@superbuilders/oneroster";
const oneRoster = new OneRoster({
security: {
clientID: process.env["ONEROSTER_CLIENT_ID"] ?? "",
clientSecret: process.env["ONEROSTER_CLIENT_SECRET"] ?? "",
},
});
async function run() {
const result = await oneRoster.scoreScalesManagement.getAllScoreScales({
fields: "sourcedId,name",
filter: "status='active'",
});
for await (const page of result) {
// Handle the page
console.log(page);
}
}
run();
This SDK supports the following security scheme globally:
Name | Type | Scheme | Environment Variable |
---|---|---|---|
clientID clientSecret |
oauth2 | OAuth2 Client Credentials Flow | ONEROSTER_CLIENT_ID ONEROSTER_CLIENT_SECRET ONEROSTER_TOKEN_URL |
You can set the security parameters through the security
optional parameter when initializing the SDK client instance. For example:
import { OneRoster } from "@superbuilders/oneroster";
const oneRoster = new OneRoster({
security: {
clientID: process.env["ONEROSTER_CLIENT_ID"] ?? "",
clientSecret: process.env["ONEROSTER_CLIENT_SECRET"] ?? "",
},
});
async function run() {
const result = await oneRoster.scoreScalesManagement.getAllScoreScales({
fields: "sourcedId,name",
filter: "status='active'",
});
for await (const page of result) {
// Handle the page
console.log(page);
}
}
run();
Available methods
- getAllAcademicSessions - Get all Academic Sessions
- postAcademicSession - Create an Academic Session
- getAcademicSession - Get a specific Academic Session
- putAcademicSession - Update an Academic Session
- deleteAcademicSession - Delete an Academic Session
- getAllAssessmentLineItems - Get all Assessment Line Items
- createAssessmentLineItem - Create an Assessment Line Item
- getAssessmentLineItem - Get an Assessment Line Item
- updateAssessmentLineItem - Update an Assessment Line Item
- deleteAssessmentLineItem - Delete an Assessment Line Item
- getAllAssessmentResults - Get all Assessment Results
- createAssessmentResult - Create an Assessment Result
- getAssessmentResult - Get an Assessment Result
- updateAssessmentResult - Update an Assessment Result
- deleteAssessmentResult - Delete an Assessment Result
- getAllCategories - Get all Categories
- createCategory - Create a Category
- getCategory - Get a Category
- updateCategory - Update a Category
- deleteCategory - Delete a Category
- postResultsForAcademicSessionForClass - Create Results for an Academic Session for a Class
- getResultsForLineItemForClass - Get Results for a Line Item for a Class
- getResultsForStudentForClass - Get Results for a Student for a Class
- getCategoriesForClass - Get Categories for a Class
- getLineItemsForClass - Get Line Items for a Class
- getResultsForClass - Get Results for a Class
- getScoreScalesForClass - Get Score Scales for a Class
- getAllClasses - Get all Classes
- createClass - Create a new Class
- getClass - Get a specific class
- updateClass - Update a Class
- deleteClass - Delete a Class
- getClassesForSchool - Get all Classes for a School
- getClassesForUser - Get Classes for a User
- getClassesForTerm - Get Classes for a Term
- getTeachersForClass - Get teachers for a Class
- addTeacherToClass - Add a teacher to a Class
- getClassesForTeacher - Get Classes for a Teacher
- getStudentsForClass - Get students for a Class
- addStudentToClass - Add a student to a Class
- getClassesForStudent - Get Classes for a Student
- createComponentResource - Create Component Resource
- getAllComponentResources - Get all Component Resources
- getComponentResource - Get a specific Component Resource
- putComponentResource - Update a Component Resource
- deleteComponentResource - Delete a Component Resource
- createCourseComponent - Create Course Component
- getAllCourseComponents - Get all Course Components
- getCourseComponent - Get a specific Course Component
- putCourseComponent - Update a Course Component
- deleteCourseComponent - Delete a Course Component
- getAllCourses - Get All Courses
- createCourse - Create a Course
- getClassesForCourse - Get Classes for a Course
- getCourse - Get a specific Course
- putCourse - Update a Course
- deleteCourse - Delete a Course
- createComponentResource - Create Component Resource
- getAllComponentResources - Get all Component Resources
- getComponentResource - Get a specific Component Resource
- putComponentResource - Update a Component Resource
- deleteComponentResource - Delete a Component Resource
- createCourseComponent - Create Course Component
- getAllCourseComponents - Get all Course Components
- getCourseComponent - Get a specific Course Component
- putCourseComponent - Update a Course Component
- deleteCourseComponent - Delete a Course Component
- getCoursesForSchool - Get all Courses for a School
- getAllDemographics - Get all Demographic records
- postDemographics - Create a new Demographic record
- getDemographics - Get a specific Demographic record
- putDemographics - Update a Demographic record
- deleteDemographics - Delete a Demographic record
- getAllEnrollments - Get all Enrollments
- createEnrollment - Create a new Enrollment
- getEnrollment - Get a specific Enrollment
- updateEnrollment - Update an Enrollment
- deleteEnrollment - Delete an Enrollment
- getEnrollmentsForClassInSchool - Get Enrollments for a specific Class in a School
- getEnrollmentsForSchool - Get all Enrollments for a School
- getAllGradingPeriods - Get all Grading Periods
- createGradingPeriod - Create a new Grading Period
- getGradingPeriod - Get a specific Grading Period
- updateGradingPeriod - Update a Grading Period
- deleteGradingPeriod - Delete a Grading Period
- getGradingPeriodsForTerm - Get Grading Periods for a Term
- createGradingPeriodForTerm - Create a new Grading Period for a Term
- getAllLineItems - Get all Line Items
- createLineItem - Create a Line Item
- getLineItem - Get a Line Item
- updateLineItem - Update a Line Item
- deleteLineItem - Delete a Line Item
- createResultForLineItem - Create a Result for a Line Item
- getLineItemsForSchool - Get Line Items for a School
- createLineItemsForSchool - Create Line Items for a School
- getAllOrgs - Get all Organizations
- createOrg - Create an Organization
- getOrg - Get a specific Organization
- updateOrg - Update an Organization
- deleteOrg - Delete an Organization
- getResourcesForClass - Get resources for a class
- assignResourceToClass - Assign a resource to a class
- removeResourceFromClass - Remove a resource from a class
- getResourcesForCourse - Get resources for a course
- assignResourceToCourse - Assign a resource to a course
- removeResourceFromCourse - Remove a resource from a course
- getAllResources - Get all Resources
- createResource - Create a new Resource
- getResource - Get a specific Resource
- updateResource - Update an existing Resource
- deleteResource - Delete a resource
- getResourcesForUser - Get resources for a user
- assignResourceToUser - Assign a resource to a user
- removeResourceFromUser - Remove a resource from a user
- getAllResults - Get all Results
- createResult - Create a Result
- getResult - Get a Result
- updateResult - Update a Result
- deleteResult - Delete a Result
- getScoreScalesForSchool - Get Score Scales for a School
- getAllSchools - Get all Schools
- createSchool - Create a new School
- getSchool - Get a specific School
- updateSchool - Update a School
- deleteSchool - Delete a School
- getLineItemsForSchool - Get Line Items for a School
- createLineItemsForSchool - Create Line Items for a School
- getClassesForSchool - Get all Classes for a School
- getTermsForSchool - Get all Terms for a School
- getTeachersForClassInSchool - Get Teachers for a specific Class in a School
- getTeachersForSchool - Get all teachers for a school
- getStudentsForClassInSchool - Get Students for a specific Class in a School
- getStudentsForSchool - Get all Students for a School
- getEnrollmentsForClassInSchool - Get Enrollments for a specific Class in a School
- getEnrollmentsForSchool - Get all Enrollments for a School
- getCoursesForSchool - Get all Courses for a School
- getAllScoreScales - Get all Score Scales
- createScoreScale - Create a Score Scale
- getScoreScale - Get a Score Scale
- updateScoreScale - Update a Score Scale
- deleteScoreScale - Delete a Score Scale
- getScoreScalesForSchool - Get Score Scales for a School
- getStudentsForClass - Get students for a Class
- addStudentToClass - Add a student to a Class
- getStudentsForClassInSchool - Get Students for a specific Class in a School
- getStudentsForSchool - Get all Students for a School
- getAllStudents - Get all Students
- getStudent - Get a specific Student
- getClassesForStudent - Get Classes for a Student
- getTeachersForClass - Get teachers for a Class
- addTeacherToClass - Add a teacher to a Class
- getTeachersForClassInSchool - Get Teachers for a specific Class in a School
- getTeachersForSchool - Get all teachers for a school
- getAllTeachers - Get all Teachers
- getTeacher - Get a specific Teacher
- getClassesForTeacher - Get Classes for a Teacher
- getTermsForSchool - Get all Terms for a School
- getAllTerms - Get all Terms
- getTerm - Get a specific Term
- getClassesForTerm - Get Classes for a Term
- getGradingPeriodsForTerm - Get Grading Periods for a Term
- createGradingPeriodForTerm - Create a new Grading Period for a Term
- getAllUsers - Get all Users
- createUser - Create a new User
- getUser - Get a specific User
- updateUser - Update an existing User
- deleteUser - Delete a User
- getClassesForUser - Get Classes for a User
All the methods listed above are available as standalone functions. These functions are ideal for use in applications running in the browser, serverless runtimes or other environments where application bundle size is a primary concern. When using a bundler to build your application, all unused functionality will be either excluded from the final bundle or tree-shaken away.
To read more about standalone functions, check FUNCTIONS.md.
Available standalone functions
academicSessionsManagementDeleteAcademicSession
- Delete an Academic SessionacademicSessionsManagementGetAcademicSession
- Get a specific Academic SessionacademicSessionsManagementGetAllAcademicSessions
- Get all Academic SessionsacademicSessionsManagementPostAcademicSession
- Create an Academic SessionacademicSessionsManagementPutAcademicSession
- Update an Academic SessionassessmentLineItemsManagementCreateAssessmentLineItem
- Create an Assessment Line ItemassessmentLineItemsManagementDeleteAssessmentLineItem
- Delete an Assessment Line ItemassessmentLineItemsManagementGetAllAssessmentLineItems
- Get all Assessment Line ItemsassessmentLineItemsManagementGetAssessmentLineItem
- Get an Assessment Line ItemassessmentLineItemsManagementUpdateAssessmentLineItem
- Update an Assessment Line ItemassessmentResultsManagementCreateAssessmentResult
- Create an Assessment ResultassessmentResultsManagementDeleteAssessmentResult
- Delete an Assessment ResultassessmentResultsManagementGetAllAssessmentResults
- Get all Assessment ResultsassessmentResultsManagementGetAssessmentResult
- Get an Assessment ResultassessmentResultsManagementUpdateAssessmentResult
- Update an Assessment ResultcategoriesManagementCreateCategory
- Create a CategorycategoriesManagementDeleteCategory
- Delete a CategorycategoriesManagementGetAllCategories
- Get all CategoriescategoriesManagementGetCategory
- Get a CategorycategoriesManagementUpdateCategory
- Update a CategoryclassesManagementAddStudentToClass
- Add a student to a ClassclassesManagementAddTeacherToClass
- Add a teacher to a ClassclassesManagementCreateClass
- Create a new ClassclassesManagementDeleteClass
- Delete a ClassclassesManagementGetAllClasses
- Get all ClassesclassesManagementGetCategoriesForClass
- Get Categories for a ClassclassesManagementGetClass
- Get a specific classclassesManagementGetClassesForSchool
- Get all Classes for a SchoolclassesManagementGetClassesForStudent
- Get Classes for a StudentclassesManagementGetClassesForTeacher
- Get Classes for a TeacherclassesManagementGetClassesForTerm
- Get Classes for a TermclassesManagementGetClassesForUser
- Get Classes for a UserclassesManagementGetLineItemsForClass
- Get Line Items for a ClassclassesManagementGetResultsForClass
- Get Results for a ClassclassesManagementGetResultsForLineItemForClass
- Get Results for a Line Item for a ClassclassesManagementGetResultsForStudentForClass
- Get Results for a Student for a ClassclassesManagementGetScoreScalesForClass
- Get Score Scales for a ClassclassesManagementGetStudentsForClass
- Get students for a ClassclassesManagementGetTeachersForClass
- Get teachers for a ClassclassesManagementPostResultsForAcademicSessionForClass
- Create Results for an Academic Session for a ClassclassesManagementUpdateClass
- Update a ClasscourseComponentResourcesManagementCreateComponentResource
- Create Component ResourcecourseComponentResourcesManagementDeleteComponentResource
- Delete a Component ResourcecourseComponentResourcesManagementGetAllComponentResources
- Get all Component ResourcescourseComponentResourcesManagementGetComponentResource
- Get a specific Component ResourcecourseComponentResourcesManagementPutComponentResource
- Update a Component ResourcecourseComponentsManagementCreateCourseComponent
- Create Course ComponentcourseComponentsManagementDeleteCourseComponent
- Delete a Course ComponentcourseComponentsManagementGetAllCourseComponents
- Get all Course ComponentscourseComponentsManagementGetCourseComponent
- Get a specific Course ComponentcourseComponentsManagementPutCourseComponent
- Update a Course ComponentcoursesManagementCreateComponentResource
- Create Component ResourcecoursesManagementCreateCourse
- Create a CoursecoursesManagementCreateCourseComponent
- Create Course ComponentcoursesManagementDeleteComponentResource
- Delete a Component ResourcecoursesManagementDeleteCourse
- Delete a CoursecoursesManagementDeleteCourseComponent
- Delete a Course ComponentcoursesManagementGetAllComponentResources
- Get all Component ResourcescoursesManagementGetAllCourseComponents
- Get all Course ComponentscoursesManagementGetAllCourses
- Get All CoursescoursesManagementGetClassesForCourse
- Get Classes for a CoursecoursesManagementGetComponentResource
- Get a specific Component ResourcecoursesManagementGetCourse
- Get a specific CoursecoursesManagementGetCourseComponent
- Get a specific Course ComponentcoursesManagementGetCoursesForSchool
- Get all Courses for a SchoolcoursesManagementPutComponentResource
- Update a Component ResourcecoursesManagementPutCourse
- Update a CoursecoursesManagementPutCourseComponent
- Update a Course ComponentdemographicsManagementDeleteDemographics
- Delete a Demographic recorddemographicsManagementGetAllDemographics
- Get all Demographic recordsdemographicsManagementGetDemographics
- Get a specific Demographic recorddemographicsManagementPostDemographics
- Create a new Demographic recorddemographicsManagementPutDemographics
- Update a Demographic recordenrollmentsManagementCreateEnrollment
- Create a new EnrollmentenrollmentsManagementDeleteEnrollment
- Delete an EnrollmentenrollmentsManagementGetAllEnrollments
- Get all EnrollmentsenrollmentsManagementGetEnrollment
- Get a specific EnrollmentenrollmentsManagementGetEnrollmentsForClassInSchool
- Get Enrollments for a specific Class in a SchoolenrollmentsManagementGetEnrollmentsForSchool
- Get all Enrollments for a SchoolenrollmentsManagementUpdateEnrollment
- Update an EnrollmentgradingPeriodsManagementCreateGradingPeriod
- Create a new Grading PeriodgradingPeriodsManagementCreateGradingPeriodForTerm
- Create a new Grading Period for a TermgradingPeriodsManagementDeleteGradingPeriod
- Delete a Grading PeriodgradingPeriodsManagementGetAllGradingPeriods
- Get all Grading PeriodsgradingPeriodsManagementGetGradingPeriod
- Get a specific Grading PeriodgradingPeriodsManagementGetGradingPeriodsForTerm
- Get Grading Periods for a TermgradingPeriodsManagementUpdateGradingPeriod
- Update a Grading PeriodlineItemsManagementCreateLineItem
- Create a Line ItemlineItemsManagementCreateLineItemsForSchool
- Create Line Items for a SchoollineItemsManagementCreateResultForLineItem
- Create a Result for a Line ItemlineItemsManagementDeleteLineItem
- Delete a Line ItemlineItemsManagementGetAllLineItems
- Get all Line ItemslineItemsManagementGetLineItem
- Get a Line ItemlineItemsManagementGetLineItemsForSchool
- Get Line Items for a SchoollineItemsManagementUpdateLineItem
- Update a Line ItemorganizationsManagementCreateOrg
- Create an OrganizationorganizationsManagementDeleteOrg
- Delete an OrganizationorganizationsManagementGetAllOrgs
- Get all OrganizationsorganizationsManagementGetOrg
- Get a specific OrganizationorganizationsManagementUpdateOrg
- Update an OrganizationresourcesClassesManagementAssignResourceToClass
- Assign a resource to a classresourcesClassesManagementGetResourcesForClass
- Get resources for a classresourcesClassesManagementRemoveResourceFromClass
- Remove a resource from a classresourcesCoursesManagementAssignResourceToCourse
- Assign a resource to a courseresourcesCoursesManagementGetResourcesForCourse
- Get resources for a courseresourcesCoursesManagementRemoveResourceFromCourse
- Remove a resource from a courseresourcesManagementCreateResource
- Create a new ResourceresourcesManagementDeleteResource
- Delete a resourceresourcesManagementGetAllResources
- Get all ResourcesresourcesManagementGetResource
- Get a specific ResourceresourcesManagementUpdateResource
- Update an existing ResourceresourcesUsersManagementAssignResourceToUser
- Assign a resource to a userresourcesUsersManagementGetResourcesForUser
- Get resources for a userresourcesUsersManagementRemoveResourceFromUser
- Remove a resource from a userresultsManagementCreateResult
- Create a ResultresultsManagementDeleteResult
- Delete a ResultresultsManagementGetAllResults
- Get all ResultsresultsManagementGetResult
- Get a ResultresultsManagementUpdateResult
- Update a ResultschoolsManagementCreateLineItemsForSchool
- Create Line Items for a SchoolschoolsManagementCreateSchool
- Create a new SchoolschoolsManagementDeleteSchool
- Delete a SchoolschoolsManagementGetAllSchools
- Get all SchoolsschoolsManagementGetClassesForSchool
- Get all Classes for a SchoolschoolsManagementGetCoursesForSchool
- Get all Courses for a SchoolschoolsManagementGetEnrollmentsForClassInSchool
- Get Enrollments for a specific Class in a SchoolschoolsManagementGetEnrollmentsForSchool
- Get all Enrollments for a SchoolschoolsManagementGetLineItemsForSchool
- Get Line Items for a SchoolschoolsManagementGetSchool
- Get a specific SchoolschoolsManagementGetScoreScalesForSchool
- Get Score Scales for a SchoolschoolsManagementGetStudentsForClassInSchool
- Get Students for a specific Class in a SchoolschoolsManagementGetStudentsForSchool
- Get all Students for a SchoolschoolsManagementGetTeachersForClassInSchool
- Get Teachers for a specific Class in a SchoolschoolsManagementGetTeachersForSchool
- Get all teachers for a schoolschoolsManagementGetTermsForSchool
- Get all Terms for a SchoolschoolsManagementUpdateSchool
- Update a SchoolscoreScalesManagementCreateScoreScale
- Create a Score ScalescoreScalesManagementDeleteScoreScale
- Delete a Score ScalescoreScalesManagementGetAllScoreScales
- Get all Score ScalesscoreScalesManagementGetScoreScale
- Get a Score ScalescoreScalesManagementGetScoreScalesForSchool
- Get Score Scales for a SchoolscoreScalesManagementUpdateScoreScale
- Update a Score ScalestudentsManagementAddStudentToClass
- Add a student to a ClassstudentsManagementGetAllStudents
- Get all StudentsstudentsManagementGetClassesForStudent
- Get Classes for a StudentstudentsManagementGetStudent
- Get a specific StudentstudentsManagementGetStudentsForClass
- Get students for a ClassstudentsManagementGetStudentsForClassInSchool
- Get Students for a specific Class in a SchoolstudentsManagementGetStudentsForSchool
- Get all Students for a SchoolteachersManagementAddTeacherToClass
- Add a teacher to a ClassteachersManagementGetAllTeachers
- Get all TeachersteachersManagementGetClassesForTeacher
- Get Classes for a TeacherteachersManagementGetTeacher
- Get a specific TeacherteachersManagementGetTeachersForClass
- Get teachers for a ClassteachersManagementGetTeachersForClassInSchool
- Get Teachers for a specific Class in a SchoolteachersManagementGetTeachersForSchool
- Get all teachers for a schooltermsManagementCreateGradingPeriodForTerm
- Create a new Grading Period for a TermtermsManagementGetAllTerms
- Get all TermstermsManagementGetClassesForTerm
- Get Classes for a TermtermsManagementGetGradingPeriodsForTerm
- Get Grading Periods for a TermtermsManagementGetTerm
- Get a specific TermtermsManagementGetTermsForSchool
- Get all Terms for a SchoolusersManagementCreateUser
- Create a new UserusersManagementDeleteUser
- Delete a UserusersManagementGetAllUsers
- Get all UsersusersManagementGetClassesForUser
- Get Classes for a UserusersManagementGetUser
- Get a specific UserusersManagementUpdateUser
- Update an existing User
Some of the endpoints in this SDK support pagination. To use pagination, you
make your SDK calls as usual, but the returned response object will also be an
async iterable that can be consumed using the for await...of
syntax.
Here's an example of one such pagination call:
import { OneRoster } from "@superbuilders/oneroster";
const oneRoster = new OneRoster({
security: {
clientID: process.env["ONEROSTER_CLIENT_ID"] ?? "",
clientSecret: process.env["ONEROSTER_CLIENT_SECRET"] ?? "",
},
});
async function run() {
const result = await oneRoster.scoreScalesManagement.getAllScoreScales({
fields: "sourcedId,name",
filter: "status='active'",
});
for await (const page of result) {
// Handle the page
console.log(page);
}
}
run();
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:
import { OneRoster } from "@superbuilders/oneroster";
const oneRoster = new OneRoster({
security: {
clientID: process.env["ONEROSTER_CLIENT_ID"] ?? "",
clientSecret: process.env["ONEROSTER_CLIENT_SECRET"] ?? "",
},
});
async function run() {
const result = await oneRoster.scoreScalesManagement.getAllScoreScales({
fields: "sourcedId,name",
filter: "status='active'",
}, {
retries: {
strategy: "backoff",
backoff: {
initialInterval: 1,
maxInterval: 50,
exponent: 1.1,
maxElapsedTime: 100,
},
retryConnectionErrors: false,
},
});
for await (const page of result) {
// Handle the page
console.log(page);
}
}
run();
If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:
import { OneRoster } from "@superbuilders/oneroster";
const oneRoster = new OneRoster({
retryConfig: {
strategy: "backoff",
backoff: {
initialInterval: 1,
maxInterval: 50,
exponent: 1.1,
maxElapsedTime: 100,
},
retryConnectionErrors: false,
},
security: {
clientID: process.env["ONEROSTER_CLIENT_ID"] ?? "",
clientSecret: process.env["ONEROSTER_CLIENT_SECRET"] ?? "",
},
});
async function run() {
const result = await oneRoster.scoreScalesManagement.getAllScoreScales({
fields: "sourcedId,name",
filter: "status='active'",
});
for await (const page of result) {
// Handle the page
console.log(page);
}
}
run();
Some methods specify known errors which can be thrown. All the known errors are enumerated in the models/errors/errors.ts
module. The known errors for a method are documented under the Errors tables in SDK docs. For example, the getAllScoreScales
method may throw the following errors:
Error Type | Status Code | Content Type |
---|---|---|
errors.BadRequestResponseError1 | 400 | application/json |
errors.UnauthorizedRequestResponseError1 | 401 | application/json |
errors.ForbiddenResponseError1 | 403 | application/json |
errors.NotFoundResponseError1 | 404 | application/json |
errors.UnprocessableEntityResponseError1 | 422 | application/json |
errors.TooManyRequestsResponseError1 | 429 | application/json |
errors.InternalServerErrorResponse1 | 500 | application/json |
errors.APIError | 4XX, 5XX | */* |
If the method throws an error and it is not captured by the known errors, it will default to throwing a APIError
.
import { OneRoster } from "@superbuilders/oneroster";
import {
BadRequestResponseError1,
ForbiddenResponseError1,
InternalServerErrorResponse1,
NotFoundResponseError1,
SDKValidationError,
TooManyRequestsResponseError1,
UnauthorizedRequestResponseError1,
UnprocessableEntityResponseError1,
} from "@superbuilders/oneroster/models/errors";
const oneRoster = new OneRoster({
security: {
clientID: process.env["ONEROSTER_CLIENT_ID"] ?? "",
clientSecret: process.env["ONEROSTER_CLIENT_SECRET"] ?? "",
},
});
async function run() {
let result;
try {
result = await oneRoster.scoreScalesManagement.getAllScoreScales({
fields: "sourcedId,name",
filter: "status='active'",
});
for await (const page of result) {
// Handle the page
console.log(page);
}
} catch (err) {
switch (true) {
// The server response does not match the expected SDK schema
case (err instanceof SDKValidationError): {
// Pretty-print will provide a human-readable multi-line error message
console.error(err.pretty());
// Raw value may also be inspected
console.error(err.rawValue);
return;
}
case (err instanceof BadRequestResponseError1): {
// Handle err.data$: BadRequestResponseError1Data
console.error(err);
return;
}
case (err instanceof UnauthorizedRequestResponseError1): {
// Handle err.data$: UnauthorizedRequestResponseError1Data
console.error(err);
return;
}
case (err instanceof ForbiddenResponseError1): {
// Handle err.data$: ForbiddenResponseError1Data
console.error(err);
return;
}
case (err instanceof NotFoundResponseError1): {
// Handle err.data$: NotFoundResponseError1Data
console.error(err);
return;
}
case (err instanceof UnprocessableEntityResponseError1): {
// Handle err.data$: UnprocessableEntityResponseError1Data
console.error(err);
return;
}
case (err instanceof TooManyRequestsResponseError1): {
// Handle err.data$: TooManyRequestsResponseError1Data
console.error(err);
return;
}
case (err instanceof InternalServerErrorResponse1): {
// Handle err.data$: InternalServerErrorResponse1Data
console.error(err);
return;
}
default: {
// Other errors such as network errors, see HTTPClientErrors for more details
throw err;
}
}
}
}
run();
Validation errors can also occur when either method arguments or data returned from the server do not match the expected format. The SDKValidationError
that is thrown as a result will capture the raw value that failed validation in an attribute called rawValue
. Additionally, a pretty()
method is available on this error that can be used to log a nicely formatted multi-line string since validation errors can list many issues and the plain error string may be difficult read when debugging.
In some rare cases, the SDK can fail to get a response from the server or even make the request due to unexpected circumstances such as network conditions. These types of errors are captured in the models/errors/httpclienterrors.ts
module:
HTTP Client Error | Description |
---|---|
RequestAbortedError | HTTP request was aborted by the client |
RequestTimeoutError | HTTP request timed out due to an AbortSignal signal |
ConnectionError | HTTP client was unable to make a request to a server |
InvalidRequestError | Any input used to create a request is invalid |
UnexpectedClientError | Unrecognised or unexpected error |
The default server can be overridden globally by passing a URL to the serverURL: string
optional parameter when initializing the SDK client instance. For example:
import { OneRoster } from "@superbuilders/oneroster";
const oneRoster = new OneRoster({
serverURL: "https://api.staging.alpha-1edtech.com",
security: {
clientID: process.env["ONEROSTER_CLIENT_ID"] ?? "",
clientSecret: process.env["ONEROSTER_CLIENT_SECRET"] ?? "",
},
});
async function run() {
const result = await oneRoster.scoreScalesManagement.getAllScoreScales({
fields: "sourcedId,name",
filter: "status='active'",
});
for await (const page of result) {
// Handle the page
console.log(page);
}
}
run();
The TypeScript SDK makes API calls using an HTTPClient
that wraps the native
Fetch API. This
client is a thin wrapper around fetch
and provides the ability to attach hooks
around the request lifecycle that can be used to modify the request or handle
errors and response.
The HTTPClient
constructor takes an optional fetcher
argument that can be
used to integrate a third-party HTTP client or when writing tests to mock out
the HTTP client and feed in fixtures.
The following example shows how to use the "beforeRequest"
hook to to add a
custom header and a timeout to requests and how to use the "requestError"
hook
to log errors:
import { OneRoster } from "@superbuilders/oneroster";
import { HTTPClient } from "@superbuilders/oneroster/lib/http";
const httpClient = new HTTPClient({
// fetcher takes a function that has the same signature as native `fetch`.
fetcher: (request) => {
return fetch(request);
}
});
httpClient.addHook("beforeRequest", (request) => {
const nextRequest = new Request(request, {
signal: request.signal || AbortSignal.timeout(5000)
});
nextRequest.headers.set("x-custom-header", "custom value");
return nextRequest;
});
httpClient.addHook("requestError", (error, request) => {
console.group("Request Error");
console.log("Reason:", `${error}`);
console.log("Endpoint:", `${request.method} ${request.url}`);
console.groupEnd();
});
const sdk = new OneRoster({ httpClient });
You can setup your SDK to emit debug logs for SDK requests and responses.
You can pass a logger that matches console
's interface as an SDK option.
Warning
Beware that debug logging will reveal secrets, like API tokens in headers, in log messages printed to a console or files. It's recommended to use this feature only during local development and not in production.
import { OneRoster } from "@superbuilders/oneroster";
const sdk = new OneRoster({ debugLogger: console });
You can also enable a default debug logger by setting an environment variable ONEROSTER_DEBUG
to true.
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.