📘

GitHub

Click here to go to GitHub

Setup

Insert OneClick.js with the package.json into your project and run "npm install" from the command line.

npm install

Usage

First, import index.js.

const OneClick = require('./index.js');

Next, you need to create a new instance of OneClick with the client_key and client_secret.

OneClick.setConfig({
  clientId: "cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",       
  clientSecret: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
});

Generate Bearer Token

getCodeURL(scope, redirectUri, cb)

Following that, you will need to generate the url for you to sign in and retrieve your code, which will be used to get the access token. This is done with the method GetCodeURL(scope, redirectUri, cb).

The scope can be:

  • profile - Access to user identiy and user specific information
  • oneroster - Access to oneroster info and classes
  • full - Access to all public apis

Scope will be defaulted to profile if not included.

The redirectUri is the url that you will be redirected to upon login. It defaults to https://localhost:8080/code.

The callback will take in error and the url.

You can use curl or get the code from the url bar after signing in.

// Prints the url for the code
OneClick.getCodeUrl("full", function(error, url) {
 if (error) throw new Error(error);
 console.log(url); 
});

getToken(code, cb)

After getting the code from the url, you need to generate the bearer token that will be used for all the requests. This will be generated using the getToken(code, cb) method.

// Uses the code received after signing in and returns the bearer token 
OneClick.getToken("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", function(error, token) {
  if (error) throw new Error(error);
    console.log(token);
});

Accessing the Endpoints

Now that you have your bearer token, you can access the endpoints. This can be done through a number of methods. The first method, getInfo(bearer, endpoint, extractNode, cb), allows the user to specify what endpoint they want to hit and what field to return. The rest of the methods will make requests to specific endpoints for specific information.

getInfo(bearer, endpoint, extractNode, cb)

The main method used to make a request to an endpoint is getInfo(bearer, endpoint, extractNode, cb). It takes in the bearer token, the url of the endpoint (excluding the hostname), and an optional extractNode, which will return this specific field if is included in the method call.
The callback will take in an error and the JSON response.

// Prints the JSON response from the request to the endpoint
OneClick.getInfo("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "/path/info", function(error, data) {
  if (error) throw new Error(error);
  console.log(data);
});

getUserInfo(bearer, cb)

This method will take in the bearer token and return a JSON containing all of the available user info

// Prints user info as JSON
OneClick.getUserInfo("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", function(error, data) {
  if (error) throw new Error(error);
  console.log(data);
});

getUserDistrict(bearer, cb)

This method will get the district associated with the user

// Prints the district as JSON
OneClick.getUserDistrict("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", function(error, data) {
  if (error) throw new Error(error);
  console.log(data);
});

getUserProfiles(bearer, cb)

This method will get info on the user's profiles.

// Prints info on the user's profiles as JSON
OneClick.getUserProfiles("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", function(error, data) {
  if (error) throw new Error(error);
  console.log(data);
});

getUserChildren(bearer, cb)

If theuser is a parent registered for ClassLink, this will return a list of linked student accounts (their children)

// Prints children info
OneClick.getUserChildren("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", function(error, data) {
  if (error) throw new Error(error);
  console.log(data);
});

getUserGroups(bearer, cb)

Get a list of all groups that the user is a part of

// Prints a list of all groups that the user is a part of
OneClick.getUserGroups("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", function(error, data) {
  if (error) throw new Error(error);
  console.log(data);
});

getUserOneRosterInfo(bearer, cb)

Get all the OneRoster info about the user
Note: Only available for districts with OneRoster enabled.

// Print the oneroster info about the User
OneClick.getUserOneRosterInfo("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", function(error, data) {
  if (error) throw new Error(error);
  console.log(data);
});

getUserOneRosterClasses(bearer, cb)

Get all the OneRoster classes the user is enrolled in.
Note: Only available for districts with OneRoster enabled.
Info

// Print the oneroster info about user's classes
OneClick.getUserOneRosterClasses("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", function(error, data) {
  if (error) throw new Error(error);
  console.log(data);
});

getUserOneRosterClassTeachers(bearer, classSourcedId, cb)

Get info on the teacher of the class represented by the unique sourcedId.
Note: Only available for districts with OneRoster enabled.
Info

// Print the oneroster info on the teacher of the class
OneClick.getUserOneRosterClassTeachers("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "classSourcedId", function(error, data) {
  if (error) throw new Error(error);
  console.log(data);
});

getUserOneRosterClassStudents(bearer, classSourcedId, cb)

Get info on the students of the class represented by the unique sourcedId.
Note: Only available for districts with OneRoster enabled.
Info

// Print the oneroster info the students of the class
OneClick.getUserOneRosterClassStudents("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "classSourcedId", function(error, data) {
  if (error) throw new Error(error);
  console.log(data);
});