PHP/API to check whether user exists (by email) and is in specific group

AI-generated summary

Jonathan5 is seeking a PHP script to interact with the Discourse API for user and group management tasks: checking if a user exists by email (possibly via adminListUsers), verifying group membership by username/id (possibly via listGroupMembers), creating users, and adding users to groups. They reference existing examples from meta.discourse.org for guidance. pfaffman suggests reverse-engineering the Discourse API to understand these endpoints better and notes that while admin/users should work for finding users by email, there may be a more direct endpoint available.

I’m just starting to look at the API documentation now, and wonder whether someone could share a PHP script that uses the Discourse API to do any of the following, or anything similar.

  • use an email address to check whether a user exists - is adminListUsers the best way, or is the a more direct approach?
  • use a username/id to check whether the user is in a specific group - is listGroupMembers the best way or, as above, is there a more direct approach?
  • create a user - createUser
  • add user to group - addGroupMembers

I’ve seen the examples at "BAD CSRF" when executing PUT using API, curl, and PHP - #3 by hjalali and Sync DiscourseConnect user data with the sync_sso route so will likely start from there.

Your best bet is to Reverse engineer the Discourse API to see how those things work.

I think there may be another endpoint to get user by email address, but the one on admin/users should work.