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

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

1 Like

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

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

6 Likes

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?

1 Like

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

2 Likes

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

1 Like

@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.