Api question - creating and updating reviews

Hey hey. I’m making a WaniKani desktop app since I’m bored out of my mind and quarantine has me in the eighth dimension, but I’m stuck on something somewhat specific–or maybe not, but nevertheless, I’m still stuck.

Which endpoint do I post/put to so I can mark a review as answered? In the case that the answer as wrong, how do I signify that as well? The Create a Review section looks promising, but then what happens if someone answers incorrectly?

Am confused, help would be really nice. :Q

You only create a review when the user answers correctly, and for each incorrect answer beforehand you increment the appropriate field e.g. incorrect_meaning_answers. If they don’t answer correctly in that session you could keep track client side using some client-side persistent store to apply the incorrect answers to the next session, or you could just submit the review anyway (although then it won’t be available for the next session).

2 Likes

Looking at the Create a Review and Assignments articles, it appears to me that I have to make two requests: assignments, to get the count of how many reviews that need to be completed through the assignments endpoint, and then reviews with the IDs of the first request to get the incorrect meanings / reading answers. Can this be compressed into one request, or must I have to follow through with the two requests? Oh, and thanks for the help. :^)

You have to use the assignments endpoint to find out which reviews are available for review. Once the review is “done” you submit it via the reviews endpoint. How would you submit a review without knowing which reviews are available?

1 Like

I understand that I have to use the assignments endpoint, but I was wondering if it was mandatory to also use the reviews / review_statistics endpoints to get the amount of readings incorrect? I don’t know if I’m missing something important, but the assignment endpoint doesn’t have the meaning and reading statistics. I’m sorry, it just feels like I’m doing something wrong having to make requests to two different endpoints to make one set of data to push into the reviews endpoint.

1 Like

Oh, I see. The number of incorrect meaning and reading answers is something you have to provide as fresh data, it’s not something that you need to fetch from WK. If both incorrect counts are 0, then you passed the review and it will advance an SRS level. If one or both are not zero then you fail the review and the item will fall a number of SRS levels according to this formula

new_srs_stage = current_srs_stage - (incorrect_adjustment_count * srs_penalty_factor)

incorrect_adjustment_count is the number of incorrect times you have answered divided by two and rounded up. srs_penalty_factor is 2 if the current_srs_stage is at or above 5. Otherwise it is 1.

The reason why you have to provide the number of times you answered the review incorrectly is so that WK can update the SRS level accordingly

2 Likes

:0!!!

So the incorrect_meaning_answers doesn’t mean in total, it just means for that one review session? If so, that solves all of my issues!

1 Like

Almost, it’s for each individual item

Wanted to ask about the Reviews API, but didn’t want to create a new topic.

So I’ve got a dictionary with assignment_ids and subject_ids, but calling the “Create Review” API doesn’t seem to get rid of the item from the Review queue in Wanikani. Any ideas what I need to tweak?

Here’s my curl request:

#!/bin/bash

API_KEY="<API_KEY>"

assignment_id="338768484"
subject_id="9181"

response="$(curl --silent -X "POST" "https://api.wanikani.com/v2/reviews" \
  -H "Wanikani-Revision: 20170710" \
  -H "Content-Type: application/json; charset=utf-8" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{"review": {
        "assignment_id": '$assignment_id'
        "subject_id": '$subject_id',
        "incorrect_meaning_answers": 0,
        "incorrect_reading_answers": 0
        }
      }'
)"

error_message="$(echo "$response" | grep -i error)"
if [ "$error_message" != "" ]; then
  echo "Could not update $subject_id"
  echo "$response"
  exit 1
fi

Bruh, I’ve missed a comma after assignment_id…

After that, I got this message from the API:

{"error":"expect only assignment_id or subject_id","code":422}

Fixed it by removing the “assignment_id” from the curl request and then it worked.
Docs are kinda deceptive, because it says it requires both “assignment_id” and “subject_id” to be present (in the table).

Anyway, here’s the working snippet:

#!/bin/bash

API_KEY="<API_KEY>"

kana_vocabs=(9176 9177 9178 9179 9180 9181 9182 9183 9184 9185 9186 9187 9188 9189 9190 9191 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 9214 9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9226 9227 9228 9229 9230 9231 9232 9233 9234 9235 9236)

for subject_id in "${kana_vocabs[@]}"; do
  response="$(curl --silent -X "POST" "https://api.wanikani.com/v2/reviews" \
    -H "Wanikani-Revision: 20170710" \
    -H "Content-Type: application/json; charset=utf-8" \
    -H "Authorization: Bearer $API_KEY" \
    -d '{"review": {
          "subject_id": '$subject_id',
          "incorrect_meaning_answers": 0,
          "incorrect_reading_answers": 0
          }
        }'
  )"

  error_message="$(echo "$response" | grep -i error)"
  if [ "$error_message" != "" ]; then
    echo "Could not update $subject_id"
  else
    echo "$subject_id has been marked as correct"
  fi

  echo "$response"
done

Might be worth moving the code into Python with requests, JavaScript or Ruby to make it easier to handle small syntax issues :slight_smile:

I just grabbed the curl code snippet from the WK docs and went off with bash. Should’ve used something else as you suggested :sweat_smile:

Here’s the Python version of the script for those who don’t use Linux:

import requests

API_KEY = "<API_KEY>"

kana_vocabs = (9176, 9177, 9178, 9179, 9180, 9181, 9182, 9183, 9184, 9185, 9186, 9187, 9188, 9189, 9190, 9191, 9192, 9193, 9194, 9195, 9196, 9197, 9198, 9199, 9200, 9201, 9202, 9203, 9204, 9205, 9206, 9207, 9208, 9209, 9210, 9211, 9212, 9213, 9214, 9215, 9216, 9217, 9218, 9219, 9220, 9221, 9222, 9223, 9224, 9226, 9227, 9228, 9229, 9230, 9231, 9232, 9233, 9234, 9235, 9236)

for subject_id in kana_vocabs:
    response = requests.post(
        "https://api.wanikani.com/v2/reviews",
        headers={
            "Wanikani-Revision": "20170710",
            "Content-Type": "application/json; charset=utf-8",
            "Authorization": f"Bearer {API_KEY}",
        },
        json={
            "review": {
                "subject_id": subject_id,
                "incorrect_meaning_answers": 0,
                "incorrect_reading_answers": 0,
            },
        },
    )

    has_error = "error" in response.text
    if not response.ok or has_error:
        print(f"Could not update {subject_id}")
    else:
        print(f"{subject_id} has been marked as correct")

    print(response.text)

1 Like