kreta-api-v3 v1.2.0
Welcome to kreta-api-v3 👋
A wrapper for KRÉTA's v3 REST API
🏠 Homepage
Install
npm install kreta-v3-api
Example
The best way to try this out is on RunKit. You can see your code and the documentation side by side!
Caution: All documents on runKit are PUBLIC. Don't use it with personal details! (only use it to get a hang of the module with getSchoolList)
var api = require("./index");
api.getSchoolList("a-good-user-agent").then((data) => console.log(data));
api
.authenticate("a-good-user-agent", "username", "pass", "klik012345678")
.then((data) => {
var acessToken = data.access_token;
var refreshToken = data.refresh_token;
api
.getTimeTable(
"a-good-user-agent",
"klik012345678",
acessToken,
"2020-06-01",
"2020-06-02"
)
.then((data) => console.log(data));
api
.refreshToken("a-good-user-agent", refreshToken, "klik012345678")
.then((data) => console.log(data));
});
Usage
The module is intended to be used to communicate with the API in alternative clients. Most of the known API methods are covered.
Every method of the module returns a native JavaScript Promise
, which is after the API responds, fulfilled with an Object
containing the server response or a String
containing an error.
Every function's first parameter is the ua
, the Use-Agent
which the wrapper should send to the server.
getSchoolList(ua)
gets the school list.authenticate(ua, username, password, instituteCode)
authenticates the user with the given details.refreshToken(ua, refreshToken, instituteCode)
requests a new access_token from the server, but instead of using traditional login details, it uses the refresh_token you get with theauthenticate()
method.getTimeTable(ua, instituteCode, access_token, fromDate, toDate)
requests the user's time table from the server. Because of the effort to keep the package as minimal as possible, it only accepts dates in theyyyy-mm-dd
format (for example2020-06-01
), which is also what the API wants.getGrades(ua, instituteCode, access_token)
requests the user's grades. Nothing too special here.getAverages(ua, instituteCode, access_token, oktatasiNevelesiFeladatUid)
requests the user's averages. NEW: The request URL had a typo in it below version 1.1.2. Please update!getClassAverages(ua, instituteCode, access_token, oktatasiNevelesiFeladatUid)
requests the class averages of the user's class. NEW: The request URL had a typo in it below version 1.1.2. Please update!getNotes(ua, instituteCode, access_token)
requests the user's notes (feljegyzések in Hungarian, so you're not confused).getNoticeBoard(ua, instituteCode, access_token)
requests the user's noticeboard (faliújság in Hungarian, so you're not confused).getHomework(ua, instituteCode, access_token, fromDate)
requests the user's homeworks. The date format is the same as above:yyyy-mm-dd
. It's weird that it has no endDate, you'll need to handle that yourself.getAbsences(ua, instituteCode, access_token)
requests the user's absences (mulasztások in Hungarian).getHomeworkComments(ua, instituteCode, access_token, homeworkId)
requests the comments on a homework. You can get the homework id fromgetHomework
.commentOnHomework(ua, instituteCode, access_token, homeworkId, commentText)
writes a comment to a homework.getTests(ua, instituteCode, access_token)
requests the tests that the user has been "assigned".getGroups(ua, instituteCode, access_token)
requests the groups within the user's class. There is a chance that you'll get nothing, if the group only consists of one group.getUserData(ua, instituteCode, access_token)
requests user info, such as birth date, mothers name, address, etc.getUserData(ua, instituteCode, access_token)
requests user info, such as birth date, mothers name, address, etc.getHeadTeacherData(ua, instituteCode, access_token)
requests info about the user's head teacher (olsztályfőnök). I don't see any practical use to it, but hey, they have an endpoint.getYearOrder(ua, instituteCode, access_token)
requests the year order (tanév rendje) of the school. For me it 404's, but for others, it might work.getMessages(ua, access_token)
gets the user's E - Ügyintézés messages (sent, received, deleted) from the server.getReceivedMessages(ua, access_token)
gets the user's received E - Ügyintézés messages from the server.getSentMessages(ua, access_token)
gets the user's sent E - Ügyintézés messages from the server.getDeletedMessages(ua, access_token)
gets the user's deleted E - Ügyintézés messages from the server.getUnreadMessages(ua, access_token)
gets the count of the user's unread E - Ügyintézés messages.getReceivedMessages(ua, access_token)
gets the user's received E - Ügyintézés messages from the server.getMessageContent(ua, access_token, messageId)
gets the content of a single message. You can getmessageId
from any of theget*Messages
methods.getAdresseeTypes(ua, access_token)
gets the adressee types (címezhető típusok) from E - Ügyintézés. For me it's always an empty string.getTeacherData(ua, access_token)
gets the data of teachers from E - Ügyintézés.getHeadTeacherMessagingData(ua, acessToken)
gets the data of the user's head teacher (osztályfőnök) from E - Ügyintézés. For me, it's always an empty string.getDirectorateData(ua, acessToken)
gets the data of the directoriate from E - Ügyintézés.getAdministratorData(ua, acessToken)
gets the data of the admins from E - Ügyintézés.getMessagingGroupsData(ua, acessToken)
gets the data of the adressee groups (címezhető csoportok) from E-Ügyintézés. For me it 404s, for others it might work.getMessagingClassesData(ua, acessToken)
gets the data of the adressee classes (címezhető osztályok) from E-Ügyintézés. For me it 404s, for others it might work.getSzmkRepresentativeData(ua, acessToken)
gets the data of the SZMK representatives (SZMK képviselők) from E-Ügyintézés.downloadFile(ua, acessToken, fileID)
Downloads a file (attachment of a message) from E-Ügyintézés.
🚫 Not implemented yet
- E-Ügyintézés: sending a message, uploading files, downloading files.
❗ Errors
After release 1.1, those errors will no longer occur, since it only returns an Object
, if the JSON is valid. In the future, the plan is to reject the promise with the error.
In versions before 1.1:
If you get an error about
unexpected i at position 0 in JSON
it's most likely a string answer,invalid_grant
. Your access_token is incorrect. If the error isunexpected < at position 0 in JSON
, it's JSON.parse not being able to parse HTML.
Author
👤 Daniel Vanko
- Github: @daaniiieel
🤝 Contributing
Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also take a look at the contributing guide.
Show your support
Give a ⭐️ if this project helped you!
📝 License
Copyright © 2020 Daniel Vanko (https://github.com/daaniiieel).
This project is GPL--3.0--or--later licensed.