This will be a quick example of how to create a simple export of student data from the Aeries SIS system using Node.js. To make things simple, we have created an NPM package that wraps the API into a helper to make calls for data easy. You can read more about that here, https://www.npmjs.com/package/aeriesjs.
The full Aeries API documentation can be found, here.
To start out we’re going to take a simple Node application and add the aeriesjs and csv-write-stream package references to the package.json dependencies section.
{ "name": "aeries-export", "version": "1.0.0", "description": "Aeries SIS Export Example", "main": "app.js", "author": { "name": "Josh Santomieri", "url": "https://www.santsys.com/" }, "dependencies": { "aeriesjs": "^1.1.1", "csv-write-stream": "^2.0.0" } }
Once we have that added, we can start building our code… In this example we’re going to create a students.csv file that will export a caret (^) delimited list of students. The student information we will be pulling will be Student ID, First Name, Last Name and Home Phone Number.
In this demo we’re going to use the Aeries API demo URL and certificate. In practice you should use your districts API Url and Certificate.
In our application code, lets name this file app.js, add the following:
'use strict'; let api = require('aeriesjs'); let csv = require('csv-write-stream'); let fs = require('fs'); var aeries = new api({ certificate: '477abe9e7d27439681d62f4e0de1f5e1', url: 'https://demo.aeries.net/aeries/', verifyCerts: true }); // Get all of the students at school 990 aeries.getStudents(990, function (err, students, code) { if (err) { console.log(err); } else { if (students && students.length > 0) { // Setup the file stream var writer = csv({ separator: '^', newline: '\r\n', sendHeaders: true }); writer.pipe(fs.createWriteStream('students.csv')); var count = 0; // loop through the students for (var i in students) { var s = students[i]; if (s) { // create a new object with the information we want var studentOut = { PermanentID: s.PermanentID, FirstName: s.FirstName, LastName: s.LastName, HomePhone: s.HomePhone }; // write the student to the file writer.write(studentOut); count++; } } // close the file stream writer.end(); console.log('Wrote ' + count + ' students to file "students.csv".'); } else { console.log('No students found.'); } } });
That’s it!
If you run that code using node app.js
you will end up with a file named students.csv that contains the information we outlined above.
"PermanentID"^"FirstName"^"LastName"^"HomePhone" "99000001"^"Robert"^"Aadasian"^"7775550214" "99000002"^"Ruben"^"Aadasian"^"7775550214" "99000003"^"Jonathan"^"Aguilar"^"7775557860" "99000004"^"Tonya"^"Acres"^"7775555363" "99000005"^"Stephanie"^"Aguilar"^"7775557860" ...
If you need to FTP this data anywhere, I always recommend using something like WinSCP to script out the FTP process. You can get more information on WinSCP here, https://winscp.net/.
Download this sample code here, aeriesjs-test.
To run, Install Node 8 or greater, extract the zip to a directory, then run npm update
then node app.js
.
C:\> cd aeriesjs-test C:\aeriesjs-test> npm update npm notice created a lockfile as package-lock.json. You should commit this file. npm WARN aeriesjs-test@1.0.0 No repository field. + csv-write-stream@2.0.0 + aeriesjs@1.1.1 added 69 packages from 70 contributors in 6.795s C:\aeriesjs-test> node app.js Wrote 740 students to file "students.csv".