Code Examples
Node.js and Python examples demonstrate how to authenticate and generate a custom student growth chart.
The following examples show how to authenticate and generate a student growth chart with custom grade ranges and target measures using the Growth Planner API. Schema definitions for the request and response bodies can be found in Swagger.
Node.js Example
const fs = require('fs'); const path = require('path'); const CLIENT_ID = process.env.CLIENT_ID; const CLIENT_SECRET = process.env.CLIENT_SECRET; const API_URL = "https://atlas-growth-planner.lexile.com"; async function getAccessToken() { const response = await fetch(`${API_URL}/authToken`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ clientId: CLIENT_ID, clientSecret: CLIENT_SECRET }) }); const data = await response.json(); return data.accessToken; } async function getGrowthChart(token) { const data = { scale: "lexile", measures: [ { measure: 500, testDate: { month: 5, year: 2018 }, schoolYearStart: { month: 7, year: 2017 }, grade: 3, }, { measure: 750, testDate: { month: 5, year: 2019 }, schoolYearStart: { month: 7, year: 2018 }, grade: 4, }, { measure: 840, testDate: { month: 5, year: 2020 }, schoolYearStart: { month: 7, year: 2019 }, grade: 5, }, ], targetRanges: { challenging: { max: { value: 1200 }, min: { value: 1101 }, label: "A Difficult Target", }, medium: { max: { value: 1100 }, min: { value: 901 }, label: "A Just Right Target", }, easy: { max: { value: 900 }, min: { value: 700 }, label: "An Easy Target", }, }, gradeRange: { start: 3, end: 8, }, }; const response = await fetch(`${API_URL}/student-growth-interim`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}`, }, body: JSON.stringify(data), }); const result = await response.json(); return result.chart; } function saveSvg(base64Image) { const svgBuffer = Buffer.from(base64Image, 'base64'); const svgStr = svgBuffer.toString('utf-8'); const htmlContent = `<div style="width: 100%; height: auto;">${svgStr}</div>`; fs.writeFileSync(path.join(__dirname, 'interim-example-graph.html'), htmlContent); } (async () => { try { const token = await getAccessToken(); const base64Image = await getGrowthChart(token); saveSvg(base64Image); console.log("SVG chart saved as interim-example-graph.html"); } catch (err) { console.error("Error:", err.response?.data || err.message); } })();
Python Example
import base64 import os import requests CLIENT_ID = os.environ["CLIENT_ID"] CLIENT_SECRET = os.environ["CLIENT_SECRET"] API_URL = "https://atlas-growth-planner.lexile.com" auth_response = requests.post( f"{API_URL}/authToken", json={"clientId": CLIENT_ID, "clientSecret": CLIENT_SECRET}, ) access_token = auth_response.json()["accessToken"] data = { "scale": "lexile", "measures": [ { "measure": 500, "testDate": {"month": 5, "year": 2018}, "schoolYearStart": {"month": 7, "year": 2017}, "grade": 3, }, { "measure": 750, "testDate": {"month": 5, "year": 2019}, "schoolYearStart": {"month": 7, "year": 2018}, "grade": 4, }, { "measure": 840, "testDate": {"month": 5, "year": 2020}, "schoolYearStart": {"month": 7, "year": 2019}, "grade": 5, }, ], "targetRanges": { "challenging": { "max": {"value": 1200}, "min": {"value": 1101}, "label": "A Difficult Target", }, "medium": { "max": {"value": 1100}, "min": {"value": 901}, "label": "A Just Right Target", }, "easy": { "max": {"value": 900}, "min": {"value": 700}, "label": "An Easy Target", }, }, "gradeRange": { "start": 3, "end": 8, }, } response = requests.post( f"{API_URL}/student-growth-interim", json=data, headers={"Authorization": f"Bearer {access_token}"}, ) base64_image = response.json()["chart"] svg_data = base64.b64decode(base64_image) svg_str = svg_data.decode("utf-8") html_content = f"""<div style="width: 100%; height: auto;">{svg_str}</div>""" with open("interim-example-graph.html", "w") as f: f.write(html_content)