### Print All Students' Names Example Source: https://help.classlink.com/s/article/rs-req-lib-python A complete example demonstrating how to fetch, decode, and iterate through student user data. ```python import json # Import OneRoster from oneroster import OneRoster def get_users(url): # Create new OneRoster with the client_id and client_secret oneRoster = OneRoster('XXXXXXXXXXXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXXXXXXXXXXX') # Make the request to the given url and store the dictionary with status_code and response response = oneRoster.make_roster_request(url) # Decode the response decoded = json.loads(response["response"]) # If status_code is 200, create array of users from response, otherwise print message and return None if response["status_code"] == 200: return decoded["users"] elif response["status_code"] == 401: print("Unauthorized Request\n" + response["response"]) elif response["status_code"] == 404: print("Not Found\n" + response["response"]) elif response["status_code"] == 500: print("Server Error\n" + response["response"]) else: print("Something Went Wrong, status code " + response["status_code"] + "\n" + response["response"]) return None users = get_users("https://example.com/users?fields=givenName%2CfamilyName&filter=role%3D'student'"") if users is not None: for user in users: print(user["givenName"] + " " + user["familyName"]) ``` -------------------------------- ### Start NGINX Service Source: https://help.classlink.com/s/article/redirects-linux-nginx Manually start the NGINX service if it does not begin automatically after installation. ```bash sudo service nginx start ``` -------------------------------- ### Install NGINX Source: https://help.classlink.com/s/article/redirects-linux-nginx Use this command to install the NGINX web server on Debian-based Linux systems. It should start automatically after installation. ```bash sudo apt install nginx ``` -------------------------------- ### Example: Print All Students' Names Source: https://help.classlink.com/s/article/rs-req-lib-ruby This example demonstrates how to fetch all students' given and family names from the Roster Server. It includes error handling for common HTTP status codes. ```ruby require 'json' # Import OneRoster require './OneRoster.rb' if __FILE__ == $0 def get_users(url) # Create new OneRoster with the client_id and client_secret oneRoster = OneRoster.new("XXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXX"); # Make the request to the given url and store the Hash with status_code and response response = oneRoster.make_roster_request(url) # Decode the response decoded = JSON.parse(response["response"]) # If status_code is 200, create array of users from response, otherwise print message and return nil case response["status_code"] when 200 return decoded["users"] when 401 puts "Unauthorized Request\n" + response["response"] when 404 puts "Not Found\n" + response["response"] when 500 puts "Server Error\n" + response["response"] else puts "Something Went Wrong, status code " + response["status_code]" + "\n" + response["response"] end return nil; end users = get_users("https://example.com/users?fields=givenName%2CfamilyName&filter=role%3D'student'"") # Print users if not nill if users != nil users.each do |user| puts user["givenName"] + " " + user["familyName"] end end end ``` -------------------------------- ### Example: Print All Students' Names in Java Source: https://help.classlink.com/s/article/rs-req-lib-java This example demonstrates how to fetch a list of users, filter for students, and print their full names. It includes error handling for different HTTP status codes. ```java import com.google.gson.Gson; import java.util.List; import java.util.Map; // Import OneRoster import com.classlink.roster.OneRoster; public class Example { private static List> getUsers(String url) { // Create new OneRoster object with the client_id and client_secret OneRoster oneRoster = new OneRoster("XXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXX"); // Make the request to the given url OneRosterResponse response = rr.makeRosterRequest(url); Gson gson = new Gson(); // If the status code is 200, return Map of users, otherwise print message if (response.getStatusCode() == 200) { Map>> users = gson.fromJson(response.getResponse(), Map.class); return users.get("users"); } switch (response.getStatusCode()) { case 401: System.out.println("Unauthorized Request\n" + response.getResponse()); break; case 404: System.out.println("Not Found\n" + response.getResponse()); break; case 500: System.out.println("Server Error\n" + response.getResponse()); break; default: System.out.println("Something Went Wrong, status code " + response.getStatusCode() + "\n" + response.getResponse()); break; } return null; } public static void main(String[] args) { List> users = getUsers( "https://example.com/users?fields=givenName%2CfamilyName&filter=role%3D'student'""); if (users != null) { for (Map user : users) { System.out.println(user.get("givenName") + " " + user.get("familyName")); } } } } ``` -------------------------------- ### Install OneClick Dependencies Source: https://help.classlink.com/s/article/oc-req-lib-node Run this command in your shell to install the necessary packages after adding OneClick.js and package.json to your project. ```bash npm install ``` -------------------------------- ### Get All User Info Source: https://help.classlink.com/s/article/oc-req-lib-go Retrieve all available user information as a JSON string. ```go // Prints all available user info as JSON fmt.Println(oc.GetUserInfo("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")) ``` -------------------------------- ### Python Setup and Initialization Source: https://help.classlink.com/s/article/oc-req-lib-python Instructions on how to set up the OneClick library and initialize it with your client credentials. ```APIDOC ## Setup Insert OneClick.py into your project. ## Use First, import **OneClick**. ```python import OneClick ``` Next, create a new instance of OneClick with the **client_id** and **client_secret**. ```python oc = OneClick() oc.setConfig("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") ``` ``` -------------------------------- ### OneClick Initialization and Setup Source: https://help.classlink.com/s/article/oc-req-lib-ruby Instructions on how to import the OneClick library and initialize it with your client credentials. ```APIDOC ## Setup Insert OneClick.rb into your project. ## Use First, import the **OneClick** package. ```ruby require './OneClick.rb' ``` Next, create a new instance of OneClick with the **client_id** and **client_secret**. ```ruby oc = OneClick.new("cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") ``` ``` -------------------------------- ### GET /v2/my/info with JavaScript Source: https://help.classlink.com/s/article/v2-my-info This JavaScript example uses XMLHttpRequest to get user information from the /v2/my/info endpoint. It logs the response text when the request is complete. Replace {bearer_token} with your token. ```javascript var data = null; var xhr = new XMLHttpRequest(); xhr.addEventListener("readystatechange", function () { if (this.readyState === this.DONE) { console.log(this.responseText); } }); xhr.open("GET", "https://nodeapi.classlink.com/v2/my/info""); xhr.setRequestHeader("authorization", "Bearer {bearer_token}"); xhr.send(data); ``` -------------------------------- ### OneClick Java Library Setup Source: https://help.classlink.com/s/article/oc-req-lib-java Instructions on how to set up the OneClick Java library in your project, either by inserting the source file or creating and importing a JAR file. ```APIDOC ## Setup Insert `OneClick.java` into your project. OR Create a JAR file to import into your project. Generate your JAR by running the following shell command in the same directory as `OneClick.java`: ``` javac -d ./build OneClick.java ``` Run the following in the `build` folder: ``` jar cvf OneClick.jar * ``` To import a JAR file into your project in IntelliJ: 1. Click **File**. 2. Select **Project Structure**, then click **Libraries**. 3. Click the **plus sign +**, then select the **JAR file**. ``` -------------------------------- ### GET /v2/my/info with cURL Source: https://help.classlink.com/s/article/v2-my-info Use this cURL command to make a GET request to the /v2/my/info endpoint. Ensure you replace {bearer_token} with your actual authentication token. ```bash curl --request GET \ --url https://nodeapi.classlink.com/v2/my/info \ --header 'authorization: Bearer {bearer_token}' ``` -------------------------------- ### Print All Students' Names Source: https://help.classlink.com/s/article/rs-req-lib-node A complete example demonstrating how to fetch, parse, and iterate through student data. ```javascript // Import the OneRoster module const OneRoster = require('./OneRoster'); function getUsers(url) { // Create new OneRoster object with the client_id and client_secret let oneRoster = new OneRoster('XXXXXXXXXXXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXXXXXXXXXXX'); // Make the request to the given url with the callback that takes in error, the status code, and the response body oneRoster.makeRosterRequest(url, function (error, statusCode, response) { if (error) throw new Error(error); // Decode the response let decoded = JSON.parse(response); // If statusCode is 200, create array of users from response, otherwise print message switch(statusCode) { case 200: printUsers(decoded.users); break; case 401: console.log("Unauthorized Request\n" + response); break; case 404: console.log("Not Found\n" + response); break; case 500: console.log("Server Error\n" + response); break; default: console.log("Something Went Wrong, status code " + response.statusCode + "\n" + response); break; } }); } // Print the users function printUsers(users) { for (let i = 0; i < users.length; i++) { console.log(users[i].givenName + " " + users[i].familyName); } } getUsers("https://example.com/users?fields=givenName%2CfamilyName&filter=role%3D'student'","); ``` -------------------------------- ### Get District Information Source: https://help.classlink.com/s/topic/0TOUs0000000vCnOAI/sso-api-endpoints Retrieves district-specific information. ```APIDOC ## GET /v2/my/district ### Description Retrieves district information. ### Method GET ### Endpoint /v2/my/district ``` -------------------------------- ### Import and Configure OneClick Source: https://help.classlink.com/s/article/oc-req-lib-node Initialize the library by importing the module and setting your client credentials. ```javascript const OneClick = require('./index.js'); ``` ```javascript OneClick.setConfig({ clientId: "cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", clientSecret: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" }); ``` -------------------------------- ### GET /my/groups Source: https://help.classlink.com/s/article/my-groups Retrieves a list of groups for the authenticated user. ```APIDOC ## GET /my/groups ### Description Retrieves a list of groups associated with the authenticated user. ### Method GET ### Endpoint https://nodeapi.classlink.com/my/groups ### Parameters #### Headers - **authorization** (string) - Required - Bearer {bearer_token} ### Response #### Success Response (200) - **name** (string) - Name of the group - **groupid** (integer) - Globally unique ID of the group - **buildingid** (integer) - Globally unique ID of the building to which the group belongs #### Response Example [ { "name": "DemoStudents", "groupid": 9269, "buildingid": 1 }, { "name": "StudentA", "groupid": 12586, "buildingid": 1 }, { "name": "DemoTeachers", "groupid": 9268, "buildingid": 1 } ] ``` -------------------------------- ### Get User Information Source: https://help.classlink.com/s/topic/0TOUs0000000vCnOAI/sso-api-endpoints Retrieves general information about the authenticated user. ```APIDOC ## GET /v2/my/info ### Description Retrieves general user information. ### Method GET ### Endpoint /v2/my/info ``` -------------------------------- ### Get User Groups Source: https://help.classlink.com/s/topic/0TOUs0000000vCnOAI/sso-api-endpoints Retrieves the groups the authenticated user belongs to. ```APIDOC ## GET /my/groups ### Description Retrieves user groups. ### Method GET ### Endpoint /my/groups ``` -------------------------------- ### Retrieve User Profiles via API Source: https://help.classlink.com/s/article/v2-my-profiles Examples for fetching profile data using different programming languages and tools. ```cURL curl --request GET \ --url https://nodeapi.classlink.com/v2/my/profiles \ --header 'authorization: Bearer {bearer_token}' ``` ```Node var request = require("request"); var options = { method: 'GET', url: 'https://nodeapi.classlink.com/v2/my/profiles';, headers: {authorization: 'Bearer {bearer_token}'} }; request(options, function (error, response, body) { if (error) throw new Error(error); console.log(body); }); ``` ```Ruby require 'uri' require 'net/http' require 'openssl' url = URI("https://nodeapi.classlink.com/v2/my/profiles"") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["authorization"] = 'Bearer {bearer_token}' response = http.request(request) puts response.read_body ``` ```JavaScript var data = null; var xhr = new XMLHttpRequest(); xhr.addEventListener("readystatechange", function () { if (this.readyState === this.DONE) { console.log(this.responseText); } }); xhr.open("GET", "https://nodeapi.classlink.com/v2/my/profiles""); xhr.setRequestHeader("authorization", "Bearer {bearer_token}"); xhr.send(data); ``` ```Python import requests url = "https://nodeapi.classlink.com/v2/my/profiles"" headers = {'authorization': 'Bearer {bearer_token}'} response = requests.request("GET", url, headers=headers) print(response.text) ``` -------------------------------- ### GET /v2/my/profiles Source: https://help.classlink.com/s/article/v2-my-profiles Retrieves the profile information for the currently authenticated user. ```APIDOC ## GET /v2/my/profiles ### Description Retrieves the profile information for the currently authenticated user. ### Method GET ### Endpoint https://nodeapi.classlink.com/v2/my/profiles ### Parameters #### Headers - **Authorization** (string) - Required - Bearer Token ### Response #### Success Response (200) - **Priority** (integer) - Priority level - **ProfileId** (integer) - ID assigned to profile - **ProfileName** (string) - Name of the profile - **RoleId** (integer) - ID of the role - **RoleName** (string) - Name of the role - **GroupId** (integer) - ID of the group - **GroupName** (string) - Name of the group - **Level** (integer) - Level identifier - **IsCurrentProfile** (integer) - Flag indicating if it is the current profile #### Response Example { "Priority": 3280, "ProfileId": 3280, "ProfileName": "Developer Student Profile", "RoleId": 3, "RoleName": "Student", "GroupId": 13596, "GroupName": "Developer Student", "Level": 4, "IsCurrentProfile": 1 } ``` -------------------------------- ### Sample API Response Source: https://help.classlink.com/s/article/v2-my-profiles Example of the JSON structure returned by the /v2/my/profiles endpoint. ```JSON { Priority: 3280 ProfileId: 3280 ProfileName: "Developer Student Profile" RoleId: 3 RoleName: "Student" GroupId: 13596 GroupName: "Developer Student" Level: 4 IsCurrentProfile: 1 } ```