API for reviewing?


#1

I was planning to make or at least experiment with a WaniKani VR application for the HTC Vive.
After having implemented the API I noticed there was no endpoints for reviewing?
All of the API endpoints seems to be only for statistics.

Is there a separate API the mobile application uses for reviews?
Anyone knows how it does it?

Without it the VR application will only be a statistics app -.-


#2

The mobile programs use an embedded iframe, that’s how you can login to it since WK has no authentication linking to it. There is no such API.


#3

Wouldn’t want to experience any level above 20 in VR anyway…


#4

Aw… I was hoping to do my reviews in a fun way in VR.

I’ll see if I can still do the reviews by using the site in the background but provide a VR GUI to do the reviewing in.
Would have been easier with an API.

Why no kanji above level 20 in VR?
I’ve done RTK 1 twice and can’t see where the issue is?
Of course the writing in VR has to be big for it to be viewable with nice AA/Supersampling.

The potential of what you can do in VR is infinite, I can’t wait to figure out a really fun way to do WaniKani in VR.

Edit: Just checked the review ajax requests and it seems like that’s the API I want to use :slight_smile:
Just need to have a session going and it should work.


#5
mattias said... Aw... I was hoping to do my reviews in a fun way in VR.

I'll see if I can still do the reviews by using the site in the background but provide a VR GUI to do the reviewing in.
Would have been easier with an API.

Why no kanji above level 20 in VR?
I've done RTK 1 twice and can't see where the issue is?
Of course the writing in VR has to be big for it to be viewable with nice AA/Supersampling.

The potential of what you can do in VR is infinite, I can't wait to figure out a really fun way to do WaniKani in VR.
 'cuz level twenties are death and thirties are hell... *Badum tsss*

#6

Haha, WaniKani reviews in VR? I’d like to see what that looks like :smiley:


#7

Hi there! I’m new here, so please pardon me if I break some sort of rule in this post. :smiley:

There’s no public API for that as far as I know, but you could just as well make a GET request to:
https://www.wanikani.com/review/queue?
^ Edit2: this is correct now

You need to pass the user’s _wanikani_session cookie in the request header (ie, Cookie: _wanikani_session=12341243SUPERSECRETNUMBER5325234). Getting the cookie is probably going to be the tricky part, but you could certainly analyze how WaniKani does it and make your own login transaction; not that that’s necessarily very good practice, lol. :stuck_out_tongue: For the purpose of testing though, you could just pull it out of the Network tools tab in the Chrome developer tools.

It’ll throw you back some JSON which should be fairly intuitive to read out into your own data structure. I can’t give it a proper look yet, because I have only 1 review in my queue, but I’m sure you can figure it out! Good luck BTW, I can’t wait to see WaniKani in VR!!

Edit 3:
It seems that you can make the SRS aware of progress updates via this service:
https://www.wanikani.com/json/progress
You can supply the ID of the item you want to update in the query string; ie:
https://www.wanikani.com/json/progress?r128[]=0
To assert that the ‘clam’ radical took 0 attempts to answer correctly (I think that’s the point of the 0 there).


#8

Very funny to see this here. I’ve already sent an E-Mail about it, since I wanted to build my own client without the need to disguise as a webbrowser.

Method of logging in:

visit https://www.wanikani.com/login
To get the “authenticity_token” that is inside the login form. (not actually sure if you need that x.x)
And then just send a post with the login informations and the authenticity_token.

Doing so in Firefox gives back a 302 response and  “_wanikani_session” is found in the answer header
Doing it outside of firefox gives me back a 200 response and the “_wanikani_session” cookie.
 
Calling “https://www.wanikani.com/vocabulary/力” to retrieve the item ID required for https://www.wanikani.com/json/progress?v18[]=0 sadly gives me a 500 response.
https://www.wanikani.com/json/progress?v18[]=0 can be called to answer “力” correctly (only works if the item is ready for reviewing)
I haven’t found a different way to get the item ID except for the item page’s javascript

Items that are on your reviewlist can be gathered from the api tho


Here is hopping that Viet at least responses to my E-Mail, but I guess he is a busy man. :slight_smile:
Hope I could help someone with my attempt


EDIT: Did I write 301?.. I mean’t 302…
EDIT2: Don’t just copy urls I guess… whoops…

#9

Ah nice, that’s brilliant. 

Hm, odd; I get a 200 OK regardless of the item ID. Does it still give you a 500 if you replace that ‘r’ with a ‘v’? I think that’s supposed to denote the type; ie, for the 力 vocab word, does this work?
https://www.wanikani.com/json/progress?v18[]=0


#10

Oh that is what you get if you take the shortcut and copy it. xD
I have “/json/progress?v18[]=0&v18[]=0” in my code. (as this is what your browser sends after getting it right)

I get the 500 when gathering the Item ID found on the item page:

Line 430 -> https://www.wanikani.com/vocabulary/力: Notes.add(‘vocabulary’, ‘meaning’, 18, progression.requested_information.meaning_note, $(’#note-meaning’));
Haven’t tried calling progress yet, as it failed on a step before it. I Guess I’ll try it out real quick… and edit the above one… again…


#11

Yeah, I’m just going to create a desktop window which you can login with to get the session.
Then inside VR I’ll make use of this undocumented API.

Kind of how Wevr transport does it.

I guess I’ll start writing on a library to use this undocumented API.
It should be fine since you still need to actually login to use it.

Going to have to write a library for both the public API and the undocumented one before I start on creating VR content.


#12

Haha, you sometime just need to take a little break to see something so obvious…
No 401 response with session cookie anywhere

I don’t really want to tell you but ok…
The reason for the 500 was me sending “力”. (facepalm)
200 with the wanted Item ID after doing some UTF-8 magic…

submitting an answer is:

A get to :
/json/progress?v<ITEM_ID>[]=0&v<ITEM_ID>[]=0
With this being in the header. (you get 406 otherwise)
X-Requested-With", "XMLHttpRequest"
And the “_wanikani_session” cookie ofc
and you log in with:
A get to :
https://www.wanikani.com/login
And retriving “authenticity_token” from the Loginform
and a post with the logindata and the authenticity_token.
The Item ID can be found on its page inside the javascript near the end of the file

I guess I slept when I tried it first…
Would be nice to so something in the API regardless as less experienced people (like me q.q) get a better chance of doing things

#13
Darky1 said...submitting an answer is:
A get to :
/json/progress?v<ITEM_ID>[]=0&v<ITEM_ID>[]=0
 And, of course, replace the zeros with ones if you got meaning or reading wrong.  I can't remember which one is meaning and which is reading.  It's been a long time since I did anything with those.  But I think it's the same order as how it appears on the item progress screen (where it shows percent correct and longest streak).

#14
rfindley said...
Darky1 said...submitting an answer is:
A get to :
/json/progress?v<ITEM_ID>[]=0&v<ITEM_ID>[]=0
 And, of course, replace the zeros with ones if you got meaning or reading wrong.  I can't remember which one is meaning and which is reading.  It's been a long time since I did anything with those.  But I think it's the same order as how it appears on the item progress screen (where it shows percent correct and longest streak).
 Totally forgot that.

Something to note would be that the "v" stands for vocab, and is replaced with "k" for Kanji and "r" for Radicals.
My guess would be that the first of the two 0s is the amount of meaning answers you got wrong, and the second one the amount of wrong reading answers.
Radicals have the first 0 changed. (the other one remains 0)

#15

You don’t need to lookup the kanji etc to find the id. All data is available in the queue response:
https://www.wanikani.com/review/queue?

Watching some of the headers I also see X-CSRF-Token, might need that as well?
I haven’t written any code yet. But all you need is to have the network tab open in your browser and do some reviews to find the right api calls and which headers/data they use.


#16

^^^
I’ve done an automated WK login for some scripts that monitor WK updates.  I just used wget in a bash shell, with the flag to save cookies to a file.  Worked great, and I didn’t have to look at what cookies were being saved.  Doing it in an app instead of shell-script should be fine if your http library has decent cookie support.


#17

How do you do login script in Python? What info do I need?

payload = {'user[login]': 'xxxxxx', 'user[password]': 'xxxxxx', 'user[remember_me]' : True, 'authenticity_token' : 'zQE9GfubYgUZdGMlXsnNXzoMbAYBVAKhyIJnhw1TUtB4LAtC/+qExa1/53nhOC9oGTEjz3nU7CkIOPUkoVMaGw==', 'utf8' : '&#x2713;' }

#18

For the ‘utf8’ parameter, I used:

utf8=%E2%9C%93

My overall POST data looked like this (without the new-lines):

utf8=%E2%9C%93
&authenticity_token=ZwqNBZMlyTtJzX3Yw%2BbbxGGX87ScrvxwGCVJd2%2B62bqgNssN6oXlOcpoChWh8nQQMWp9tl5fNMMCjroRg%2Bz9jg%3D%3D
&user%5Blogin%5D=xxxxxx
&user%5Bpassword%5D=xxxxxx
&user%5Bremember_me%5D=0
&user%5Bremember_me%5D=1

And, of course, you have to keep the cookies between calls.

I used a bash script for the fetching, and a node.js script to extract the info from the login page:

bash script
#!/bin/bash

COOKIES="html/cookies.txt"

# Clear cookies
rm -f ${COOKIES}

# Get login page, and extract auth token
wget -Ohtml/login.html --save-cookies ${COOKIES} --keep-session-cookies "https://www.wanikani.com/login" -o/dev/null
post_data=`./extract_login_auth`

# Login, and save Dashboard
wget -Ohtml/dashboard.html --load-cookies ${COOKIES} --keep-session-cookies --save-cookies ${COOKIES} --post-data "${post_data}" "https://www.wanikani.com/login" -o/dev/null
node.js script
#!/usr/bin/js

var username = 'your_username';
var password = 'your_password';
var utf8='utf8=%E2%9C%93';

var fs = require('fs');
var cheerio = require('cheerio');

var page = fs.readFileSync('html/login.html');
var $ = cheerio.load(page);
console.log(
        utf8+
        '&authenticity_token='+encodeURIComponent($('input[name="authenticity_token"]').val())+
        '&'+encodeURIComponent('user[login]')+'='+encodeURIComponent(username)+
        '&'+encodeURIComponent('user[password]')+'='+encodeURIComponent(password)+
        '&'+encodeURIComponent('user[remember_me]')+'=0'+
        '&'+encodeURIComponent('user[remember_me]')+'=1'
);