Using external_id via API

Hello,

I’d like to create and retrieve a user via the API using an external_id. The external_id would be an integer that references an ID in our internal database. This is not SSO related.

I’m following the documentation but I can’t seem to get it to work. I can create the user but I cannot retrieve the user by external_id. The Create User API just shows the request to have an external_ids object but no more information on what the contents of the object should be. I searched the Community and only found this topic, but it wasn’t much help.

I’m trying to retrieve the user using the following GET request:

https://our_domain.discourse.group/u/by-external/7000.json

but it returns a 404 and the following response:

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

Following are examples of some of the Create User requests I’ve tried. The users are created successfully, I just can’t retrieve them by external_id. (Side note: is there also a way to view the external_id of a user?):

{
    "name": "John",
    "username": "Doe",
    "email": "john.doe@example.com",
    "password": "Z44Di3AeD93KoRUyxpyE",
    "active": true,
    "approved": true,
    "external_id": 7000
}
{
    "name": "John",
    "username": "Doe",
    "email": "john.doe@example.com",
    "password": "Z44Di3AeD93KoRUyxpyE",
    "active": true,
    "approved": true,
    "external_id": "7000"
}
{
    "name": "John",
    "username": "Doe",
    "email": "john.doe@example.com",
    "password": "Z44Di3AeD93KoRUyxpyE",
    "active": true,
    "approved": true,
    "external_ids": {
        "external_id": 7000
    }
}
{
    "name": "John",
    "username": "Doe",
    "email": "john.doe@example.com",
    "password": "Z44Di3AeD93KoRUyxpyE",
    "active": true,
    "approved": true,
    "external_ids": [
        7000
    ]
}

Is DiscourseConnect enabled on your site? If not, you need to find the provider name of your authenticator and use that in the request. Some details about this are here: Find a user by their identity provider 'external ID'.

Thanks for your reply.

I think that means we cannot use external_id, because we don’t want to enable DiscourseConnect. We don’t want to replace Discourse authentication.

We’ll probably have to create the user via API, then store the Discourse user.id in our system and reference them that way.

1 Like