Create User external_ids parameter

I am trying to write a function to import all existing users from our external site (3rd party i am only making the middleware) and i am trying to the createUser function. It works fine, except for the external_ids parameter. No matter what i send in it (i tried arrays, objects… you name it) the external id is not saved but the user is created. No errors.

Is there any specific format for the external_ids object?

I saw the sso_sync solution but i would rather not go down that path, especially that the external_ids param is included in the API.

Any tips? Thank you in advance

Hi, welcome :wave:

To answer specifically on this, I believe the format expected is something like:

{ <provider_name>: <unique_id> }

1 Like

Thank you for your replay and welcome!

I tried the format you sent and the request passed but no external ids are saved still :confused: "external_ids": {},

Here is a sample of the code i am using (nodejs)

const create = await connection.post('/users.json', {
			name: `${req.body.first_name} ${req.body.last_name}`,
			email: req.body.email,
			password: test_password,
			username: `${req.body.first_name}_${req.body.last_name}`,
			external_ids: JSON.stringify({ 'magento': req.body.user_id }),

Is there anything i must define before or something wrong you can see?

Have you set up the authenticator correctly? I believe the relevant code is the following:

I have already set up SSO, and was able to redirect from the 3rd party site to discourse, but i do not recall any place to define the provider except when defining discourse connect provider secrets. Is there something i am missing?

Hmm, ok. If you’re using DiscourseConnect, from reading the code, it looks like you can’t add the external id when creating. The code just above only handles associated accounts which are different from SSO.

Can you try making two calls: first call the same as you have now, but without the external ids, and add a second call to updateUser, including the external id info? Hopefully that works.

1 Like

Thank you for your help, and yes i am using DiscourseConnect which is probably why this isn’t working. I think this is the approach I will end up having to do. Either that or I have to make a second call that SSO logins the user with the external id so that it is linked to their email.
Edit: I think the updateUser will also have the same issue as i do not have a defined provider, so probably the SSO login is my best bet.

So just to update and close this, the only solution that worked was running sso_sync after creating a new user, and even that was not very necessary because once the user tries to sso into discourse the sync will happen anyways via email it seems.
Thanks for all who helped.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.