Custom field in discourseconnect

I am trying to pass a custom user field when signing on a user.

Here is the array I am signing…

$parameters =  array(
            'nonce'       => $nonce,
            'external_id' => 'jay',
            'email'       => 'bugsbunny@betaclub.org',
            'username'    => 'bugsbunny@betaclub.org',
            'name'        => 'Bugs Bunny',
            'add_groups'  => 'state_sponsors',
            'custom.experience' => 'Pro',
           'custom.state' => 'FL',
        );

The field name is Experience, it is a multiselect field and one of the options is Pro
I am not seeing this come across? I also have a custom field named State, which is a Text Field. How do I troubleshoot this. I don’t see anything about the custom field in the logs with discourse connect logging turned on.

If you have created those fields via the Admin → Customize → User Fields, you need to pass it as

$parameters =  array(
            'nonce'       => $nonce,
            'external_id' => 'jay',
            'email'       => 'bugsbunny@betaclub.org',
            'username'    => 'bugsbunny@betaclub.org',
            'name'        => 'Bugs Bunny',
            'add_groups'  => 'state_sponsors',
            'custom.user_field_1' => 'Pro',
            'custom.user_field_2' => 'FL',
        );

The field names aren’t the name you set on the UI, but numbered fields named user_field_NUMBER.

5 Likes

That worked thanks so much.

Do you know how to populate a multi select field with multiple values?

‘custom.user_field_1’ => ‘Pro, Newbie’,

??

1 Like

Curiously I was looking into this last week, and from the looks of it we do not support multi select fields via the DiscourseConnect payload at the moment.

Did some testing and it will populate a multi select field if only a single value is sent.
Does not work - ‘custom.user_field_1’ => ‘Pro, Newbie’,
Does work - ‘custom.user_field_1’ => ‘Pro’,

This is OK for our needs. If that field is editable by the end user they can add other selections as needed.

@Falco Thanks so much for the help

1 Like

Next question is about add_groups. I have a comma delimited list, but it is not adding user to the groups.

$parameters =  array(
            'nonce'               => $nonce,
            'external_id'         => $sponsor['spid'],
            'email'               => $sponsor['email'],
            'username'            => $sponsor['email'],
            'name'                => $fullname,
            'add_groups'          => 'state_sponsor, status_sponsor, elect_sponsor',
            'location'            => $location,
            'custom.user_field_1' => $experience, //experience - Newbie, Less than 5, Pro, Old Timer
            'custom.user_field_2' => $club['name'].' ('.$sponsor['new_id'].')',  //school name with clubid
            'custom.user_field_4' => $division, //division
        );

The payload reported is:

add_groups=state_sponsor%2C+status_sponsor%2C+elect_sponsor
email=xxxx%40spart1.org
external_id=xxxx
name=Angela+Moore
nonce=xxxx
username=xxxx%40spart1.org
location=Landrum%2C+SC
custom.user_field_1=Pro
custom.user_field_2=Landrum+Middle+School+%28JSC0081%29
custom.user_field_4=Junior

In the logs for discouseconnect I see:

add_groups: state_sponsor, status_sponsor, elect_sponsor
admin: 
moderator: 
avatar_force_update: 
avatar_url: 
bio: 
card_background_url: 
email: xxxx@spart1.org
external_id: xxxxx
groups: 
locale: 
locale_force_update: 
logout: 
name: Angela Moore
nonce: xxxx
profile_background_url: 
remove_groups: 
require_activation: 
return_sso_url: 
suppress_welcome_message: 
title: 
username: xxxx@spart1.org
website: 
location: Landrum, SC

Which looks correct.
I would like to add this user to the ‘state_sponsor, status_sponsor, elect_sponsor’ groups.

You need to drop the space between the commas.

1 Like

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