Topic: Is there a way to retrieve multiple tags at once via a single API call?

Posted under e621 Tools and Applications

I'm writing a Discord bot that goes through people's favorites and sees which tags they favorite the most commonly. A feature I'd like to add to this is to retrieve how many posts total have each tag and sort my output by what percentage of all posts on the site with that tag the user has favorited, to see which of their fetishes are the most niche. This is fairly simple to do -- call

/tags.json?search[name]=<whatever>

for each tag, and the return data contains how many posts on the site have that tag. The problem is that this requires me to make one API call per tag. Seeing as my own favorites total around 6,000 unique tags, and given e621's global ratelimit of one API call per second per IP address, I'm looking at close to two hours just for one user. Caching on my end would speed this up somewhat for subsequent users, but I'd still rather not wait. Is there a way to batch-retrieve tags, e.g. with a POST request and you send it a list of tags you want, or is my only option to write a script that looks for wildcards that match multiple tags I want to search for and do it that way?

You can search for up to 100 tags at a time like this:

https://e621.net/tags.json?search[name]=male,solo,horse

Keep in mind that you'll probably also need the limit=100 query parameter, as otherwise the results past 75 will get discarded.

If you are not that concerned with how up-to-date the exact post count is, you can also fetch the database export daily and synchronize it with a database of your own.
https://e621.net/db_export/

  • 1