Now that there is an API call for Merge Users, how to call it?

AI-generated summary

The discussion revolves around programmatically calling the Merge Users plugin in Discourse using the API. mpemburn initially asks for help with the API call, and riking suggests using the browser developer tools to reverse-engineer the request.

mpemburn attempts to replicate the request in Postman, providing details on the method, endpoint, headers, and parameters used. However, they encounter a “not found” error. riking suggests checking if the target username exists, which mpemburn confirms is the case.

mpemburn also mentions that removing the headers results in an HTML page with a “page doesn’t exist or is private” message. Another user, artur, joins the discussion, seeking a solution to automate merging users via the API for their Discourse instance.

Hi,

I started a topic yesterday (now closed) about calling the Merge Users plugin programmatically, and Rafael kindly referred me to the release notes, which feature a mention of the plugin now having a UI (Discourse 2.5.0.beta3 Release Notes). Sadly, my skills with the Discourse API are not such that I can translate this into an API call. This is something that we will need to do from our application on a fairly regular basis. Can you help me out, please?

Thanks in advance,

Mark Pemburn
Blue Ocean Ideas

The button is visible at the bottom of a user’s administration page.

image

If you open your browser developer tools while using it, you will see the request that needs to be made.

Hi Kane,

Thanks for the tip! It took me a while to be able to create some users in my sandbox Discourse, but I was able to do so today. I took what I gleaned from the dev tools Network panel and attempted to duplicate it via Postman. These are the values:

Method: POST
Endpoint: https://my-discourse-sandbox/admin/users/{source user ID}/merge.json

Headers:

Content-Type: multipart/form-data
Accept: application/json

Params:

Api-Key: {create via the UI}
Api-Username: system
context: /admin/users/{source user ID/{source username}
target_username: {target username}

The response was:

    {
        "errors": [
            "The requested URL or resource could not be found."
        ],
        "error_type": "not_found"
    }

Any idea of what I’m doing wrong?

Those all look correct at a glance. Have you checked that the target_username value exists?

Kane,

Yes, both source and target are current users. If I remove the headers, I get back an HTML page that says “Oops! That page doesn’t exist or is private.” The “page doesn’t exist” part is understandable for a 404 error, but I’m not sure what “private” implies here.

Mark

@mpemburn did you have any success with this?

I’m migrating some mailing lists to a discourse instance. Since many people used different emails the transfer creates many staged users per real person. I would like to automate the merging of users via the API.