diff --git a/libs/api-admentum/lib/apiAdmentum.ts b/libs/api-admentum/lib/apiAdmentum.ts index 30122899..325fae8a 100644 --- a/libs/api-admentum/lib/apiAdmentum.ts +++ b/libs/api-admentum/lib/apiAdmentum.ts @@ -302,12 +302,18 @@ export class ApiAdmentum extends EventEmitter implements Api { if (!this.isLoggedIn) { throw new Error('Not logged in...') } + const token = await this.fetch('get-token', apiUrls.messages) + .then((res) => res.text()) + .then((html) => /token:\s+'(.*)'/.exec(html)?.pop()) // HACK: this could probably be found at a better place than the html code.. - const fetchUrl = apiUrls.messages(this.userId, '1') + console.log('token', token) + + const fetchUrl = apiUrls.conversations(this.userId, '1') console.log('fetching messages', fetchUrl) const messagesResponse = await this.fetch('get-messages', fetchUrl, { headers: { 'x-requested-with': 'XMLHttpRequest', + 'user-info': token, }, }) const messagesResponseJson = await messagesResponse.json() diff --git a/libs/api-admentum/lib/routes.ts b/libs/api-admentum/lib/routes.ts index ea55668a..0b29d344 100644 --- a/libs/api-admentum/lib/routes.ts +++ b/libs/api-admentum/lib/routes.ts @@ -15,9 +15,10 @@ export const apiUrls = { leisure_groups: api + 'leisure_groups', lesson_infos: api + 'lesson_infos', lessons: api + 'lessons', + messages: 'https://skola.admentum.se/messages/', // start at page 1 - messages: (userId: string, page: string) => - `https://messages.admentum.se/api/users/${userId}/conversations?page=${page}`, // unread_only=1 + conversations: (userId: string, page: string) => + `https://messages.admentum.se/api/users/${userId}/conversations?page=${page}`, // unread_only=1 organisations: api + 'organisations', orientations: api + 'orientations', overview: (action: string, year: string, week: string) =>