API V2 Beta Documentation

Most site updates would already be covered by the /subjects endpoint when combined with the If-Modified-Since or Etag header. But yeah… deleted items would currently be missed.

Perhaps the most straight-forward way to indicate deletions would be to add a “status” field:

{
  id: :integer,
  object: :string,
  url: :string,
  data_updated_at: :date,
  data: {
    status: :string,  // "active", "reset", "deleted"
    [...]
  }
}

/subjects endpoint:

  • active: object is valid
  • deleted: object has been removed from service

other endpoints:

  • active: object is unlocked (otherwise it wouldn’t show up in the endpoint)
  • reset: object was unlocked, but has been relocked due to reset
  • deleted: object has been removed from service

One thing you can surely do is remove the CA certificate from the certificate chain (the AddTrust one). It’s not needed, because the clients have them in their own trust store. Thats a few KB off the handshake.

Thanks for the suggestion. We’ll take a look into this.

This would be implicitly combining results with those from one or more ‘delta events’ tables, assuming the original record was deleted. Maybe including deltas this way could be toggled with a filter since not all clients will be interested in synchronizing.

@bbucommander,
A filter “status=active” would work for that.

True. I was thinking deltas would not be included unless the updated_since filter is used. Combine that with your status=active filter and you get back the original updated_since results without deltas.

For my use case I want review statistics with the subject information included. To my mind this is why GraphQL is so popular these days (although there’s no Ruby server side implementation that I know of).

Anyhow, I’m now splicing the subject data into the review_statistics if anyone is interested in that format of data. E.g.:

I’m also working on a cache API, but mine is a userscript framework that runs while the user is on the WK site. Other WK userscripts will be able to access the full cache, which is often a significant portion of the work in writing a userscript.

If I have enough time, I plan to convert all my userscripts to use the framework.

That’s pretty cool, @rfindley. I reckon you’ll satisfy most all use cases that way.

In my case I’m working on an HTML-based screensaver that will cycle through my leaches. To make it a screensaver I’m using a OSX website-as-screensaver tool which doesn’t run userscripts.

The route I’m going makes more sense for sites built on WK data as opposed to WK pages.

I’ll be using the same library for my stats site, so it should be portable. It relies entirely on the WK APIv2.
The main down-side is that the queries and storage will be redundant if used on more than one site. But at least userscripts running on WK won’t have to compete for the per-site storage limit.

Does WK already know the interleaved version of the primary reading?

E.g.

For

17 PM

This (or the equivalent grouping)

<ruby><rb>日</rb><rt>に</rt> <rb>本</rb><rt>ほん</rt></ruby>

Does API V2 provide a way to query for recent unlocks?

You can do this by using the assignment endpoint (preferably with updated_after filter) and filter the response results on the client end by unlocked_at.

It’s not explicitly available, but you can derive it successfully for most vocab by looking at the subcomponents, and just fall back to a single <rt> for the exceptions.

Do you keep data from srs stage changes? Would it be possible to expose some of them through this API? mastered_at, enlightened_at, etc. could be useful for stats and also for fancy timelines in UI.

We have been recording review session history for a while now, which contains this info. We do plan on exposing it to an endpoint at some point.

@viet

Could it be that there is a logic bug with updated_after (at least on the /api/v2/review_statistics endpoint)? If I supply the previous data_updated_at field value as updated_after I appear to get review statistics that are updated on or after the given date (or most likely that there are some truncated milliseconds at play here).

For example (won’t be repeatable as soon as I do my new review, but still):

curl -H 'Authorization: Token token=MY_API_TOKEN' 'https://www.wanikani.com/api/v2/review_statistics?updated_after=2017-09-09T04:19:01Z'

Responds with:

{
  "object": "collection",
  "url": "https://www.wanikani.com/api/v2/review_statistics?updated_after=2017-09-09T04%3A19%3A01Z",
  "pages": {
    "next_url": null,
    "previous_url": null,
    "last": 1,
    "current": 1
  },
  "total_count": 1,
  "data_updated_at": "2017-09-09T04:19:01Z",
  "data": [
    {
      "id": 76933118,
      "object": "review_statistic",
      "url": "https://www.wanikani.com/api/v2/review_statistics/76933118",
      "data_updated_at": "2017-09-09T04:19:01Z",
      "data": {
        "created_at": "2017-07-31T13:16:29Z",
        "subject_id": 2539,
        "subject_type": "vocabulary",
        "meaning_correct": 24,
        "meaning_incorrect": 0,
        "meaning_max_streak": 24,
        "meaning_current_streak": 24,
        "reading_correct": 24,
        "reading_incorrect": 11,
        "reading_max_streak": 5,
        "reading_current_streak": 1,
        "percentage_correct": 81
      }
    }
  ]
}

Just as a sanity check against things like URL encoding/decoding, does it remove those records if you increase the updated_after by 1sec?

The same issue exists on the subjects and assignments endpoints, so I imagine it affects all endpoints. And yes, adding a second to the timestamp yields an empty collection as expected. So instead, I store the last time I made a request to a particular endpoint and use that instead of max(data_updated_at), as suggested in post 19. (API V2 Beta Documentation - #19 by viet)

Good catch.

The field is populated with a more accurate date, which gets truncated in our serializer. Looks like we’ll need to address this.