tonyzimbinski / infinite-campus

📚 unofficial API for Infinite Campus written in Node JS
GNU General Public License v3.0
30 stars 11 forks source link

"Username/Password is incorrect" error even when it is correct #7

Closed Isaiah-Hamilton closed 3 years ago

Isaiah-Hamilton commented 3 years ago

I installed the "npm i infinite-campus" and I looked at the documentation and followed the all the code, but when I run the code it says this error:

/Users/Name/node_modules/reqjs-err-handler/index.js:131 throw new Error([${prefix}][${errPrefix}] ${text}) ^

Error: [LOGIN][F_BODY_0] Username/Password is incorrect. at ErrorHandler._throwErr (/Users/Name/node_modules/reqjs-err-handler/index.js:131:11) at /Users/Name/node_modules/reqjs-err-handler/index.js:61:18 at Array.forEach () at ErrorHandler.handle (/Users/Name/node_modules/reqjs-err-handler/index.js:58:30) at Request._callback (/Users/Name/node_modules/infinite-campus/index.js:207:26) at Request.self.callback (/Users/Name/node_modules/request/request.js:185:22) at Request.emit (events.js:315:20) at Request. (/Users/Name/node_modules/request/request.js:1154:10) at Request.emit (events.js:315:20) at IncomingMessage. (/Users/Name/node_modules/request/request.js:1076:12)

This is my code:

const InfiniteCampus = require('infinite-campus') const user = new InfiniteCampus('Atlanta', 'GA', 'ihamilto0684', 'XXXXX')

// wait until we are done logging in user.on('ready', () => { // now that we are logged in, fetch courses user.getCourses().then((courses) => { console.log(courses) }) })

qwazwsx commented 3 years ago

hmm... This error indicates that either the username or password is incorrect. Assuming that your username and password are in fact correct, the issue could be that the district is wrong.

The way Infinite Campus works is that each district can have its own users with different usernames and passwords. So we need to search for your district and then we try to log in using your username and password with the district information.

The API finds the district by searching on this page and selecting the first result. Play around with it to make sure it's picking the right district.

As this screenshot shows, it's selecting a school district called "SLAM Atlanta" because it's #1. If this isn't your district I'd try to use a more specific search term, such as 'atlanta charter', 'atlanta city', or 'atlanta unbound'. Or if your district isn't any of these try a different search term altogether.

Let me know if this solves your issue. Otherwise we can talk about some other ways to fix your problem. Sorry that you're having issues. Happy coding :)

qwazwsx commented 3 years ago

if you're still having issues I can add an new option to log in by specifying your district login URL, bypassing the search entirely.

Isaiah-Hamilton commented 3 years ago

Thank you so muck for responding. I did what you said and narrowed down the search terms and now i'm logged in. Though when I ran it got this information.

{ name: '1', seq: 1, startDate: '2020-08-24', endDate: '2020-10-23', courses: [ [Object], [Object], [Object], [Object] ] }, { name: '2', seq: 2, startDate: '2020-10-26', endDate: '2021-01-15', courses: [ [Object], [Object], [Object], [Object] ] }, { name: '3', seq: 3, startDate: '2021-01-19', endDate: '2021-03-19', courses: [ [Object], [Object], [Object], [Object] ] }, { name: '4', seq: 4, startDate: '2021-03-22', endDate: '2021-05-26', courses: [ [Object], [Object], [Object], [Object] ] }

It's getting the sequence and the date right but everything else is blank. I don't know if it's my fault or thats what it's supposes to do. What i'm trying to get is my grades. Thank you again for helping me.

qwazwsx commented 3 years ago

Yeah, no problem! It means a lot to me that you want to use my code, and I enjoy helping people. :)

That's not your fault at all, NodeJS doesn't print out nested objects to a certain extent. For example if you try to run the following:

console.log({
    a: {
        b: {
            c: {
                d: {
                    e: {
                        f: {g: 'hi!'}
                    }
                }
            }
        }
    }
})

it will return

{
    a: {
        b: {
            c: [Object]
        }
    }
}

I wrote an example script to help explain this in terms of the infinite-campus API:

const InfiniteCampus = require('infinite-campus')
const user = new InfiniteCampus('DISTRICT', 'STATE', 'USER', 'PASS') // *****REPLACE ME*****

// wait until we are done logging in
user.on('ready', () => {
  // now that we are logged in...

  // get grades from all courses
  user.getCourses().then((courses) => {
    // when node tries to print this, it will replace nested objects with [Object], the data is still there, 
    //   console.log just doesnt like printing nested objects
    console.log('EXAMPLE 1 (node doesnt like printing nested objects)')
    console.log(courses)

    // OUTPUT: this should result in the same output (with the [Object]) that you posted above
    // ----------------------------------------------------------------------------------------------------------------------------------------------------

    // you can use JSON.stringify() to convert the object into a JSON string. 
    //   copypaste it into a site https://jsonformatter.curiousconcept.com/ to view it a little better
    console.log('\n\nEXAMPLE 2 (JSON.stringify)')
    console.log(JSON.stringify(courses))

    // OUTPUT: this should print a big long "string" of the data in JSON format, this is useful if you want to export it to a file or to an external viewer
    // ----------------------------------------------------------------------------------------------------------------------------------------------------

    // now lets do some processing of the data
    console.log('\n\nEXAMPLE 3 (processing the data with loops)')

    // use .forEach to loop over each term (quarter, semester etc) in the courses array
    courses.forEach((term) => {
      // the element is assignmed to 'term'

      // print out each course
      console.log(`term called ${term.name} with ${term.courses.length} courses in it`)

      // loop over each COURSE in term
      term.courses.forEach((course) => {
        console.log(`    - class called ${course.name} with grade ${course.grades.score}`) 
        // (if grade is 'undefined' it just means that course doesn't have a grade yet)
      })

    })

    // OUTPUT: this should output something like the following
    //     term called Quarter 1 with 3 courses in it
    //          - class called English with grade A
    //          - class called Math with grade A
    //          - class called Science with grade A
    //     term called Quarter 2 with 3 courses in it
    //          - class called English with grade A
    //          - class called Math with grade A
    //          - class called Science with grade A

  })

})

A great option for debugging is to use the devtools inspector.

Just run node --inspect myFile.js and connect to the nodeJS process using DevTools (inspect element). Although the connection is closed once the program ends so you might want to add an infinite loop to keep it running like this

// ask JS to evaluate 1+1 every once and a while to keep the program from terminating
setInterval(() => {
  1 + 1
}, 10000)

I hope this helps! Have fun building something cool! :)

Isaiah-Hamilton commented 3 years ago

Thank you it worked and also your api is amazing.

qwazwsx commented 3 years ago

No problem :) Glad we got it sorted out :+1: