Using external_id via API

AI-generated summary

Using external_id via API

The discussion revolves around creating and retrieving users via the API using an external_id. eg-gam is trying to use an external_id, an integer referencing an ID in their internal database, but is unable to retrieve the user by external_id despite successfully creating the user.

eg-gam has tried various Create User requests with different formats for the external_id, but none have worked. They are receiving a 404 error when attempting to retrieve the user using the GET request https://our_domain.discourse.group/u/by-external/7000.json.

simon points out that DiscourseConnect needs to be enabled to use external_id, and provides a link to a related topic. However, eg-gam decides not to enable DiscourseConnect, as they don’t want to replace Discourse authentication. Instead, they plan to create the user via API and store the Discourse user.id in their system for referencing.

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: Finding 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.