Some help with the API

I’m trying to do a simple tracker of my daily progress using the API.

Here’s what I’d like to keep track of:

  • Lessons completed
  • Reviews completed
  • Lessons available
  • Reviews available

This is what I have so far, from what I understood this should give me the amount of reviewed items on that day:

    const today = new Date();

    today.setHours(0, 0, 0, 0);

    const apiEndpointPath = `reviews/?updated_after=${today.toISOString()}`;

    const requestHeaders =
        new Headers({
            'Wanikani-Revision': '20170710',
            Authorization: 'Bearer ' + apiToken
        });

    const apiEndpoint =
        new Request('https://api.wanikani.com/v2/' + apiEndpointPath, {
            method: 'GET',
            headers: requestHeaders
        });

    const response = await fetch(apiEndpoint);

    const responseBody = await response.json() as ReviewsResponse;

    return responseBody.total_count;

For the other stuff, I’m assuming I also would have to use the reviews API, but I’m a bit confused to what parameters I’d have to provide to get the results I want.

1 Like

I just realized that when I was looking at the docs yesterday I thought I was checking the reviews section but I was actually on the assignments one, which is why the parameters I was trying out didn’t seem to be working. :roll_eyes:

With immediately_available_for_lessons and immediately_available_for_review I should be able to get the lessons and reviews currently available, I’m assuming.

2 Likes

You can get this from the assignments endpoint, just check which have a started_at date.

You could get this either by fetching all reviews, or by fetching the review statistics for each item an looking at the number of times you got meaning/reading correct.

You’ll find these in the summary endpoint, or as you said, check the info in the assignments endpoint

1 Like

Ah, thank you so much.

I’m checking the docs and it doesn’t seem like the assignments endpoint tells you whether or not the item is a lesson or a review, not sure if I’m missing something.

2 Likes

There is only one assignment per subject. It is what contains your personal data for the subject. As such it is neither a lesson or a review, but you can tell from the started_at date if or when when the lesson was done

1 Like

That makes more sense. I’m bad at reading docs.

So the assignment is the radical/kanji/vocabulary, and I can tell when it was first done by checking whether or not they have a started_at date.

I think I can take it from here, thanks a lot. :heart:

2 Likes

To be fair I think the terminology is a bit confusing. I know I was confused in the beginning as well

2 Likes

It is possible to export this information from Item Inspector to csv format. You may use a spreadsheet or process the csv file at your convenience. I am not sure if you want to go that route but this is an available option.

In Item Inspector this is named Lesson Date.

In Item Inspector this is called Total Answers Correct.

Lessons available are the Items in the Initiate SRS stage in Item Inspector.
Reviews available are the Items in with a Review Date.

If you export this information you are ready to go.

2 Likes

What is this Item Inspector? Is this done manually?

After fetching all this information I’m sending it in a webhook for discord, just to keep track off. If I can use it to do that, it would be an option, though I’m mostly done with the script anyway.

1 Like

The Item Inspector is a script for WK, so you would have to export and import manually

1 Like

Item Inspector is a script I wrote. You define which items you are interested in with filters and you define which information you want in the export file. Then you click a button and it does the export. But if you are almost done there may be no point to it.

Edit, the export is to a csv file. You will have to process that to get it to the web book automatically.

1 Like

I see.

I already worked it out using the API directly, but thanks for the idea.

Censored out the name to save you from second hand embarrassment

:+1:

1 Like

I would not have felt embarrassed. I am happy that it worked out for you. With the kind of needs you have working directly from the API is probably the better idea.

1 Like