⚠️

Exciting News!

Our transition to a new website is complete. Click here to seamlessly access the latest version of this article.

Kindly update any bookmarked URLs accordingly. The Development Center will no longer be accessible after April 1, 2024. Thank you for your attention to this matter.

📘

GitHub

Click here to go to GitHub

Setup

Insert OneClick.java into your project.

Or

Create a JAR file to import into your project

Generate your JAR by running the following command in the same directory as OneClick.java.

javac -d ./build OneClick.java

Then go to the build folder and run the following.

jar cvf OneClick.jar *

To import a JAR file into your project in IntelliJ, click File -> Project Structure -> Libraries -> Click the plus sign -> Select the JAR File.

Usage

First import OneClick.

import OneClick;

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

OneClick oc = new OneClick("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");

Generate Bearer Token

getCodeUrl(scope, redirectUri)

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).

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 not included in method call.

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

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

OneClick oc = new OneClick("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
// Prints the url for the code
System.out.println(oc.getCodeUrl("full"));

getToken(code)

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) method.

// Uses the code received after signing in and returns the bearer token 
System.out.println(oc.getToken("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"));

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), 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)

The main method used to make a request to an endpoint is get_info(bearer, endpoint, extractNode). 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 not passed as an empty string.
It will return the info as a JSON response in a string.

// Prints the JSON response from the request to the endpoint
System.out.println(oc.getInfo("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "/path/info", ""));

getUserInfo(bearer)

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

// Prints user info as JSON
System.out.println(oc.getUserInfo("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");

getUserDistrict(bearer)

This method will get the district associated with the user

// Prints the district as JSON
System.out.println(oc.getUserDistrict("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"));

getUserProfiles(bearer)

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

// Prints info on the user's profiles as JSON
System.out.println(oc.getUserProfiles("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"));

getUserChildren(bearer)

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

// Prints children info
System.out.println(oc.getUserChildren("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"));

getUserGroups(bearer)

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
System.out.println(oc.getUserGroups("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"));

getUserOneRosterInfo(bearer)

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

// Print the oneroster info about the User
System.out.println(oc.getUserOneRosterInfo("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"));

getUserOneRosterClasses(bearer)

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
System.out.println(oc.getUserOneRosterClasses("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"));

getUserOneRosterClassTeachers(bearer, sourcedId)

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
System.out.println(oc.getUserOneRosterClassTeachers("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "sourcedId"));

getUserOneRosterClassStudents(bearer, sourcedId)

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
System.out.println(getUserOneRosterClassStudents("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "sourcedId"));