Potential API bug - "Get a public list of users" endpoint

I was just doing some testing with the “get public list of users” endpoint and needed to do paging to get the remaining users. I used the load_more_directory_items field to get the path for the next page, which was listed as /directory_items?order=days_visited&page=1&period=all

However, when using this path, I didn’t get a proper API response with users, and instead just got some HTML. I compared it to the original endpoint and it looks like it’s missing the .json after directory_items. Adding the .json to the path for the next page appeared to work. Would this be an API bug?

1 Like

It’s likely you received the 404 not found html page.

When using the API please always use .json for any api requests because while most endpoints will return json by default some will return html. Looks like this route doesn’t have a default though, so when it didn’t get passed .json the route couldn’t be found.

You really should be specifying .json so you don’t get this error page, but I wonder if we do detect an API call if we should return an actual 404 http response instead of 200 with an unreadable html body :thinking:?

5 Likes

Right, with the endpoint in the initial API call I am specifying .json. The issue I was noting was that in the response, the load_more_directory_items under meta did not specify .json.

"meta": {
        "last_updated_at": "2020-08-11T11:40:43.000Z",
        "total_rows_directory_items": 1132,
        "load_more_directory_items": "/directory_items?order=days_visited&page=2&period=all"
    }

The value is: /directory_items?order=days_visited&page=2&period=all

When it should be: /directory_items.json?order=days_visited&page=2&period=all

Since it doesn’t include .json, I have to manually update that string each time I need to page.

1 Like

Ah, I see what you mean now. That should be a quick fix. I’ll work on that today.

2 Likes

I pushed a fix for this:

https://github.com/discourse/discourse/commit/ee366f7ac7d6855e8eb9d54b0f2e6743ad411238

It should be available in your instance if you git pull and rebuild. Thanks for bringing this up :slight_smile:.

3 Likes