12

I was thinking of creating a nice question on Programming Puzzles & Code Golf related to Winter Bash 2014, but I need some specific data for that question - The number of hats of each user.

Is there a way to query the number of hats owned by a user using the stack exchange API?

2 Answers 2

8

The unofficial Winterbash inbox API

If you have any user's account_id then the hats information is just one call away.

And the call is

http://winterbash2014.stackexchange.com/api/inbox?accountId=<account_id>

For example, hats information about me can be retrieved via

http://winterbash2014.stackexchange.com/api/inbox?accountId=4996787

But here are the caveats:

  • This is most probably a temporary API, so no idea how long it will work, or if it will change in between.
  • I have no idea whether it works with an API key or not, thus for now, it only works for yourself It works for everyone who is participating in the WinterBash.

To get any user's account_id, simply use the /users API.

For example, a sample API for PPCG with name search on peter is

http://api.stackexchange.com/2.2/users?order=desc&sort=reputation&inname=peter&site=codegolf&filter=!)RwcIFaJnzoLPrdy_GOamMlj

which gives the following output

{
  "items": [
    {
      "account_id": 278703,
      "user_id": 194,
      "display_name": "Peter Taylor"
    },
    {
      "account_id": 262054,
      "user_id": 788,
      "display_name": "Peter Olson"
    },
    {
      "account_id": 4989165,
      "user_id": 31378,
      "display_name": "Peter Weistroffer"
    },
    {
      "account_id": 24885,
      "user_id": 8977,
      "display_name": "Peter Mortensen"
    },
    {
      "account_id": 23121,
      "user_id": 1852,
      "display_name": "Peter Lawrey"
    },
    {
      "account_id": 45792,
      "user_id": 833,
      "display_name": "PetersenDidIt"
    },
    {
      "account_id": 4284,
      "user_id": 842,
      "display_name": "peter"
    },
    {
      "account_id": 25835,
      "user_id": 1280,
      "display_name": "Peter Mourfield"
    },
    {
      "account_id": 3012,
      "user_id": 1441,
      "display_name": "Peter Hart"
    },
    {
      "account_id": 62463,
      "user_id": 1535,
      "display_name": "Peter Jaric"
    },
    {
      "account_id": 190859,
      "user_id": 1986,
      "display_name": "Peter DeWeese"
    },
    {
      "account_id": 15021,
      "user_id": 2019,
      "display_name": "peterchen"
    },
    {
      "account_id": 113435,
      "user_id": 2259,
      "display_name": "Peter Milley"
    },
    {
      "account_id": 130125,
      "user_id": 2648,
      "display_name": "Peter Smith"
    },
    {
      "account_id": 951403,
      "user_id": 3203,
      "display_name": "Peter John Acklam"
    },
    {
      "account_id": 130009,
      "user_id": 4617,
      "display_name": "Peter"
    },
    {
      "account_id": 13104,
      "user_id": 4648,
      "display_name": "Tony Peterson"
    },
    {
      "account_id": 8490,
      "user_id": 4871,
      "display_name": "Peter"
    },
    {
      "account_id": 31204,
      "user_id": 5419,
      "display_name": "Peter Smit"
    },
    {
      "account_id": 872850,
      "user_id": 6893,
      "display_name": "peter"
    },
    {
      "account_id": 349151,
      "user_id": 7927,
      "display_name": "Peter Majeed"
    },
    {
      "account_id": 25721,
      "user_id": 9002,
      "display_name": "Peter Gibson"
    },
    {
      "account_id": 211922,
      "user_id": 9036,
      "display_name": "Eric Peterson"
    },
    {
      "account_id": 104670,
      "user_id": 12672,
      "display_name": "PeterT"
    },
    {
      "account_id": 14690,
      "user_id": 12910,
      "display_name": "Peter Hosey"
    },
    {
      "account_id": 172638,
      "user_id": 13568,
      "display_name": "Peter Nixey"
    },
    {
      "account_id": 2799,
      "user_id": 13621,
      "display_name": "Peter Cooper"
    },
    {
      "account_id": 1988549,
      "user_id": 14149,
      "display_name": "Peter Horvath"
    },
    {
      "account_id": 2239333,
      "user_id": 14160,
      "display_name": "Peter Vasilev"
    },
    {
      "account_id": 1055603,
      "user_id": 14216,
      "display_name": "Peter W."
    }
  ]
}
3
5

http://winterbash2014.stackexchange.com/api/user-hats?userId=29538&host=stackapps.com

This returns an array of arrays. Each inner array contains three integers:

  • The Id of the hat
  • The number of times the user has earned this hat, all over the network
  • 1 if the user has earned this hat on this particular site (Stack Apps, in this example); 0 otherwise.
3
  • Cool. When did API come into existence ?
    – Optimizer
    Commented Dec 19, 2014 at 14:04
  • Two years ago (except that it contained less data because hats were more strictly per-site). It's the API that gets called to populate the hat rack when you click on the "X hats" number on a user profile.
    – balpha Staff
    Commented Dec 19, 2014 at 14:06
  • This is a good start, but how do we get a list of badge names to go with the ID's? And, it looks like we can tease the hat images out of the winterbash2014 page, but is there an easier way via the API? Commented Dec 19, 2014 at 22:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .