Here’s the use case, which I’m sure many people have faced:
- Have bunch of users in Discourse
- Have an external system (service provider, Drupal) which uses API create Discourse users and manage group memberships
- Drupal has partially overlapping set of users. ie. Users with same email address exist in Discourse and Drupal, but aren’t linked
- Drupal uses API to sync users, groups, and memeberships because users might never use SSO to access Discourse, instead relying on emails
Current behavior:
- Discourse sometimes rejects the API call to create a Discourse user, because a Discourse user already exists with same email
Desired behavior:
- Discourse links existing Discourse user to the Drupal user, via email
Proposed solution:
- Query discourse
/admin/users/list/all.json?email=$email
API endpoint to fetch any users with matching email address - If the matching user exists
- Connect the existing users (Drupal side)
- else
- Create a new discourse user
Questions
- Does this seem like a reasonable solution, or is there a better way to do it?
- Is the API query formed correctly?
Neitherall.json
nor theemail
query string param are documented, and I found very few examples, but this post seems to indicate it’s the best way to go.