How to get SRS stats with V2 API?

I would like to display user’s current SRS stats (the count of Apprentice, Guru, Master, Enlightened and Burned items on the user dashboard) with the new V2 API, is that possible in an efficient manner?

1 Like

There isn’t a simple getter for SRS totals (although it would be really convenient if the srs_stages endpoint added an item_total property…), so what I ended up doing for my userscript was having to loop through all items and accumulate counters for each SRS stage.

const wkSRSTotals = [0, 0, 0, 0, 0, 0, 0, 0, 0];
const config = {
    wk_items: {
        options: {assignments: true}
    }
};
window.wkof.ItemData.get_items(config).then((processItems) => {
    for (let item of processItems) {
        const srsLevel = item && item.assignments && item.assignments.srs_stage;
        if (srsLevel != null) {
            wkSRSTotals[srsLevel - 1]++;
        }
    }
})

I’m using the open framework API wrappers here for userscript convenience, but you could technically implement the same logic using the base API in any language…

2 Likes

Could also use the .get_index() method.

wkof.ItemData.get_items('assignments')
    .then(items => wkof.ItemData.get_index(items, 'srs_stage'))
    .then(breakdown => {
        // Do stuff
});
2 Likes

Not sure which API version does it use, but this script does it plus shows leaches:

That uses API v2 through the Open Framework.