Pink Ninja Man.4375:

Hi all,

I was wondering what the best way to get a list of all the items in the game. I’m not just looking for their IDs as I am aware of the API endpoint of items with no IDs passed in. In unfortunately only gives a list of IDs and not the in game name. I was hoping to make an input field auto-complete for items and I wanted to be able to get an active list of items. So, I figured I have two options: Either send 2 requests to the API server each item each time I load up my site (one to get IDs and one to get names for each ID), or I just have to update my site every now and then and hard-code in the names of all the items in the game (will likely make some script to do this that will use method 1). Are their any other options? Which option is better?

Thanks for your suggestions,

PinkNinjaMan

Lawton Campbell.8517:

My recommendation is to do a nightly scrape of /v2/items and store the contents in a local database, then query that to do text completion. The most efficient way (e.g., fewest requests) is to use ?page=X&page_size=200. New items are added to the endpoint as they’re discovered by players (which, in practice usually means daily), and item names are subject to change during patches.

There may be a third-party API that provides an auto-complete backend; someone else will have to chime in on that though.

DarkMagister.7429:

First, don’t forget to use API V2, or you will have to request each item separately.

Does it not have a limit of 200 ids for a single request anyway ? I mean is paging needed here at all?

I would use the following to make a local copy:
1. Download a full list of items available
2. In cycle create lists of 200 ids and request API with each such list.

smiley.1438:

Well, paging is convenient for the people who use their fingers to count, others can do it without… (j/k)

like so:

// put all the IDs into chunks...
$ids = array_chunk($ids, 200);

// ...now loop through the chunks
foreach($ids as $chunk){
	// ...and create the request for each chunk and language
	foreach($api_languages as $lang){
		$urls[] = $api_base.'?'.http_build_query(['lang' => $lang, 'ids' => implode(',', $chunk)]);
	}
}

Ok, php is unfair advantage :P

Eearslya.6309:

The way I’ve done it recently is to fetch the first page of 200 and discard everything but the header, and use the X-Page-Total header to determine the page count. The way I see it, it’s not that different from requesting the base endpoint first and chunking up the array into blocks, in terms of API access. (Plus it’s simpler for C.)