14

Goal

Use the SE API in order to get the lists of the badges for every website in the network. The /badges endpoint provide this data.

Expected result

According to the paging documentation, we can request up to 100 items:

pagesize can be any value between 0 and 100 and defaults to 30

Source: https://api.stackexchange.com/docs/paging:

So the API should allow us to request up to 100 badges, in order to reduce the number of requests.

In fact, it worked for 11 years (according to my git history) with 100 items per page , before it broke in late August 2024.

Actual result

(see the last update below)

No pagesize

Example:

https://api.stackexchange.com/docs/badges#order=desc&sort=rank&filter=default&site=eosio&run=true

Output:

enter image description here

With 43 <= pagesize <= 100

Example:

https://api.stackexchange.com/docs/badges#pagesize=100&order=desc&sort=rank&filter=default&site=eosio&run=true

For some reason, the API returns an error when pagesize is equal or greater than 43.

Output:

enter image description here

Output as text:

{
  "error_id": 404,
  "error_message": "no method found with this name",
  "error_name": "no_method"
}

So pagesize must be removed from the request, and we have to perform more calls to retrieve all the tags.

Update after tests from Makyen

Actually the error doesn't come from pagesize, since we can request the page 2 with pagesize = 95:

https://api.stackexchange.com/docs/badges#page=2&pagesize=95&order=desc&sort=rank&filter=default&site=eosio&run=true

Cause of the error

The root issue is a problem with the Guide badge, as shown in this answer from Jeremy.

Minor update after more tests in /badges/{ids} (2024-10-10)

On serverfault

We can see the badge with 542 for serverfault here (name has been removed to avoid the error):

https://api.stackexchange.com/docs/badges#page=135&pagesize=1&order=desc&sort=rank&filter=!-*xW3Xj7tCc7&site=serverfault&run=true

And we can see its name Guide here on /badges/{ids}:

https://api.stackexchange.com/docs/badges-by-ids#order=desc&sort=rank&ids=542&filter=default&site=serverfault&run=true

So this tag has a name indeed, but this tag crashes /badges.

We can see a link in the response, but it returns a 404 page: https://serverfault.com/help/badges/542/guide

On Stack Overflow

About this badge: https://stackoverflow.com/badges/12166/

We can look at it by its id: https://api.stackexchange.com/docs/badges-by-ids#order=desc&sort=rank&ids=12166&filter=!-*xW3Xj7tCc7&site=stackoverflow&run=true

If we add name to the filters, it crashes.

It also lack a description.

So it's very likely that the badges about the Staging Ground feature broke several API endpoints related to badges.

15
  • 6
    So ... now we have to wonder: Is 42 a magic number?
    – rene Mod
    Commented Sep 1 at 14:34
  • Your analysis is inaccurate, your conclusions false, and your conclusions imply debugging that you appear to have not done. The actual problem appears to be that the error is produced when, on EOS.IO, you try to return the 43rd badge that results from the sort order you are using, not when you ask for a pagesize > 42 (example: page=2 with pagesize=95).
    – Makyen
    Commented Sep 1 at 15:03
  • On EOS.IO, it appears to be two different badges, as that request fails with both page=1&pagesize=94 and page=2&pagesize=94.
    – Makyen
    Commented Sep 1 at 15:05
  • The problem appears to exist on other sites too: example MSE: page=2&pagesize=100 also fails, but page=1&pagesize=100 doesn't.
    – Makyen
    Commented Sep 1 at 15:07
  • 1
    So from Makyen’s comments, this seems like it’s an internal error (bug) being naively converted into an external error, in a way that makes it look like it’s an intended error from the API, which is responding with a 404 error code and a 302 http status, when it’s clearly a 500 situation? That seems confusing and misleading.
    – Jeremy
    Commented Sep 1 at 15:09
  • Note: the link I provided in my first comment here should have been page=2 with pagesize=95. The difference is that this link is using order=desc, which matches your examples. I had switched to order=asc for additional testing and copied the wrong URL.
    – Makyen
    Commented Sep 1 at 15:13
  • 1
    @Jeremy Yes, based on past experience with errors on the SE API, that 404 with no method found with this name error is definitely returned on correctly formatted, valid requests when the server encounters an internal error. I don't know if it's returned all the time in such cases, but it's definitely returned as such on at least some types of internal server errors, which should be 500. We've seen such errors in response to requests from SmokeDetector over multiple years (examples: 1, 2)
    – Makyen
    Commented Sep 1 at 15:23
  • 8
    @Makyen "Your analysis is inaccurate, your conclusions false, and your conclusions imply debugging that you appear to have not done." Why post a comment this aggressive? There are more civil ways to express the same ideas.
    – A.L
    Commented Sep 1 at 15:23
  • 2
    @A.L I'm sorry that it comes off as aggressive. I agree that it's blunt, but it's an accurate description of what I found with respect to what you had written. Other people who look at this deserve to have accurate information, so they don't waste their time trying to track down the wrong thing or use the wrong conclusions. Admittedly, I was a bit frustrated that a minimal amount of changing the parameters of the request which you had linked showed substantial discrepancies between what was written in the question and the results of that minimal testing.
    – Makyen
    Commented Sep 1 at 15:31
  • @Makyen Thanks for the tests, I updated the question with your remarks. I didn't suspected that the 43rd badge could be the issue! So I didn't try to change the other parameters than pagesize.
    – A.L
    Commented Sep 1 at 15:37
  • Regarding the bounty remark "The SE API has been broken". Isn't it only a minor edge case when you try to read specific badge? If you don't read specific badge, isn't everything else working fine? Commented Sep 12 at 12:00
  • @ShadowWizard I don't try to read a specific badge, I try to get all the badges for each website, and it crashes when reaching a specific badge. Please let me know if this question is unclear.
    – A.L
    Commented Sep 12 at 12:26
  • @A.L fair, but still - with try..catch you can avoid the whole app crashing. My point is that it's not a fatal bug - you can still work with the API can read everything else. Commented Sep 12 at 14:21
  • @ShadowWizard This is true that a workaround can be developed, but it would mean that the faulty page would have to be skipped, so some badges would be missing. This will be a last resort option if the SE API is not fixed.
    – A.L
    Commented Sep 16 at 15:33
  • 2
    FYI to CMs: the title was edited several times after the [status-review] tag was added to this post, so it may end up creating duplicate Jira tickets. Try searching Jira for tickets with the previous titles to avoid creating duplicate tickets on the relevant team's board :)
    – V2Blast
    Commented Oct 14 at 18:12

1 Answer 1

16
+50

For the instance of this error in the original post, this error is occurring for the Guide badge, which is a badge for Staging Ground participation. That badge should only exist on Stack Overflow (and if you follow the link provided by the API on other sites, you get a 404 result), but the API is returning it on other sites as well. That bad badge data is probably the root bug, but the cases where the does or does not occur are very weird.

The error only occurs if you use a filter that includes the name field.

/2.3/badges?page=43&pagesize=1&order=desc&sort=rank&site=eosio
{
  "error_id": 404,
  "error_message": "no method found with this name",
  "error_name": "no_method"
}

If you use a filter to exclude it, the query can complete successfully.

/2.3/badges?page=43&pagesize=1&order=desc&sort=rank&site=eosio&filter=2LTN6ox_Y64-p(fo
{
  "items": [
    {
      "badge_type": "named",
      "award_count": 0,
      "rank": "bronze",
      "badge_id": 113,
      "link": "https://eosio.stackexchange.com/badges/113/",
      "description": "Review 10 posts in Staging Ground"
    }
  ]
}

But you can include it without error if you specify the name as a query parameter.

/2.3/badges?order=desc&sort=rank&inname=Guide&site=eosio&filter=qbpQSZryYlXMZRun
{
  "items": [
    {
      "badge_type": "named",
      "award_count": 0,
      "rank": "bronze",
      "badge_id": 113,
      "link": "https://eosio.stackexchange.com/badges/113/guide",
      "description": "Review 10 posts in Staging Ground",
      "name": "Guide"
    }
  ]
}

You can also include it without error on the route that looks up badges by ID.

/2.3/badges/113?order=desc&sort=rank&site=eosio&filter=qbpQSZryYlXMZ
{
  "items": [
    {
      "badge_type": "named",
      "award_count": 0,
      "rank": "bronze",
      "badge_id": 113,
      "link": "https://eosio.stackexchange.com/badges/113/guide",
      "description": "Review 10 posts in Staging Ground",
      "name": "Guide"
    }
  ]
}

The error does not occur for the Instructor badge, even though it's also a Staging Ground badge which doesn't exist on those sites.

/2.3/badges?page=46&pagesize=1&order=desc&sort=rank&site=eosio&filter=qbpQSZryYlXMZ
{
  "items": [
    {
      "badge_type": "named",
      "award_count": 0,
      "rank": "silver",
      "badge_id": 114,
      "link": "https://eosio.stackexchange.com/badges/114/instructor",
      "description": "Review 250 posts in Staging Ground",
      "name": "Instructor"
    }
  ]
}

The other instance pointed out by Makyen is even more weird. That badge doesn't even have a description:

/2.3/badges?page=44&pagesize=1&order=desc&sort=rank&site=eosio&filter=!-*xW3Xj7tCc7
{
  "items": [
    {
      "badge_type": "named",
      "award_count": 0,
      "rank": "bronze",
      "badge_id": 115,
      "link": "https://eosio.stackexchange.com/badges/115/",
      "description": ""
    }
  ]
}

Attempting to access its name fails even if you're looking it up by ID:

/2.3/badges/115?order=desc&sort=rank&site=eosio
{
  "error_id": 404,
  "error_message": "no method found with this name",
  "error_name": "no_method"
}

The badge ID is right after the staging ground badges. On Stack Overflow, there's no special badge in that location, it's just a random tag badge, but the API response we can see here indicates that this is not a tag badge, it's a normal "named" badge. But the fact that it occurs right after that staging ground badges certainly seems suggestive... maybe of some bug in whatever code was seeding those new badges in the database?

You must log in to answer this question.

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