当 admin/users.json?email=foobar 或 admin/users/list/all.json?email=foobar 返回空数组的情况

您好,

根据标题,我在 Postman 中运行上述端点时收到 [] 的响应。如果用户 foobar 没有创建任何主题,几乎所有响应都是 [],但有一个用户刚刚创建了一个主题,但上述查询的响应仍然是 [],而我认为两者都应该始终返回用户信息,因为这些基本信息(注册 IP、用户名)是用户刚创建账户时的信息。

顺便说一下,我在 https://docs.discourse.org/ 上找不到 admin/users.json 端点。它是否已被移除,或者不再应该使用?谢谢!

1 个赞

你也可以使用这个端点 /admin/users/list/{flag}.json

要按电子邮件过滤,你可以这样做:

http://localhost:4200/admin/users/list/active.json?filter=name%40example.com&show_emails=true&order=&asc=&page=1

我将审查这些端点的 API 文档,看看是否需要进行一些更新。

您好 @blake

如果我仍然调用 admin/users.json,我会得到 404 还是可以在我的代码中继续使用它?我的 discourse 安装版本是 3.4.0.beta2,这意味着我仍然可以使用 admin/users.json?

奇怪的是,我在 https://docs.discourse.org/ 上找不到 admin/users/list/all.json?email。

是的,完全没问题。你可以继续使用 /admin/users.json。它使用的底层代码与 /admin/users/list/{flag}.json 完全相同。这可能是它尚未被文档化的原因之一。

我能够让 /admin/users.json 返回一个全新的用户,没有任何主题。

curl -i -sSL -X GET "http://localhost:4200/admin/users.json?email=982f145c7@example.com"  \
-H "Api-Key: ..."  \
-H "Api-Username: blake"

HTTP/1.1 200 OK

[
  {
    "id": 2731,
    "username": "982f145c7",
    "name": "982f145c7",
    "avatar_template": "/letter_avatar_proxy/v4/letter/9/46a35a/{size}.png",
    "active": true,
    "admin": false,
    "moderator": false,
    "last_seen_at": null,
    "last_emailed_at": null,
    "created_at": "2025-04-29T12:31:52.894Z",
    "last_seen_age": null,
    "last_emailed_age": null,
    "created_at_age": 103.259451,
    "trust_level": 1,
    "manual_locked_trust_level": null,
    "title": null,
    "time_read": 0,
    "staged": false,
    "can_be_deleted": true,
    "silence_reason": "",
    "days_visited": 0,
    "posts_read_count": 0,
    "topics_entered": 0,
    "post_count": 0
  }
]

你需要确保使用正确的电子邮件地址,否则将返回一个空数组。

谢谢 @blake。是我没有对查询字符串中的 mark + 进行编码,导致了空响应。正确编码后,返回了预期的结果。

我认为 admin/users/list/all.json?email 也是同样的原因,尽管它没有出现在文档中。

1 个赞

实际上,这在这里有记录:

https://docs.discourse.org/#tag/Admin/operation/adminListUsers

但是 all 不是一个有效的“标志”参数。

您需要进行分页才能获取所有用户。

http://localhost:4200/admin/users/list/active.json?show_emails=false&page=1
http://localhost:4200/admin/users/list/active.json?show_emails=false&order=&asc=&page=2
2 个赞

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.