User Group Self-Management

User Group Self Management:

I’m trying to get it so that a customer can submit a company name as their user group.
When the customer attempts to create an account I’d like to allow them to enter a company name.
I will then use a workflow to check to see if that group is already created.
If yes, I will send an email to the admin requesting access for the new user.
If no, I will create the the new user group and assign the creator as the administrator.

I am getting stuck on how best to submit the userTags data back to Losant using HTML.
I see the schema for a new experience user (and know that I’m going to need to make the post request match parts of this to create the user appropriately):

{
  "email": "example@experienceuser.com",
  "firstName": "Example",
  "lastName": "Name",
  "password": "aUserPassword",
  "userTags": {
    "customKey": "customValue"
  }
}

I know my current profileForm component is incorrect because I get an error when submitting the additional data:

An example submission of the body that is currently being sent can be seen here:

And the invalid data error can be seen here:
image

Is there anything I can use to point me in the right direction for matching the schema when it comes to submitting desired userTags?

Hi Leo!

I used the Create User Node in my workflow to see how my form should be formatted, here is the payload:

If you were to follow the above example (with a user tag group), your profileForm component for the userTags div to be written as such:

<input required value="{{ pageData.userTags.group }}" type="text" class="form-control" name="userTags" id="userTags" placeholder="kanarra">

Let me know if this helps!
Julia

Julia,
Thanks for the quick response!

I added the input for the userTags to the profile component:

I also updated the validation node in the workflow (kicked off by a POST request to the /create-account endpoint) for creating a new user:

Here is the 1st schema (userTags as type “object”) I tried which the POST body is being validated against:

I suspect that since “userTags” is not in the correct format I get the invalid data error:

I tried changing the schema the type of userTags to “string” but that also returned a invalid data:


Lastly, I tried to copy the schema directly from the docs link listed below:
Experience User Post Schema
No luck there either:


I get the same invalid data error.

If you have any ideas on where I’m making a mistake, I’d appreciate them.

Hi Leo!

I would suspect the Validation Payload Schema for userTags to look something like this:

"userTags": {
   "group": {
     "type":"string"
    }
 }

I try to format similarly to how it would be output on the payload. I know that group has to be a key for userTags based on the payload shown here:
44%20PM

One thing I am not certain of is naming conventions for userTags within the component. It could be that id and name should be group (thinking out loud here), but I am curious to see the output you get from the Validate Payload Node. Let me know what comes back and we will take the next steps to debugging this!

Thanks,
Julia

Hi Leo,

In addition, here is a link to some documentation on the request body.

Thanks,
Julia

Julia,
It seems we are getting closer as the error has changed from invalid to userTags is the wrong type!

Here is the payload:

Here is the error which is generated after we attempt to create the new user (which is to say that we made it past the initial validation node but when we submit the request to create the user it doesn’t like the format that we submit the userTags in… which seems to be because the userTags should be an object with a “key” (group): “value” (company name) pair. I’m not sure how to send an object back using the HTML form submission (which is written in the profileForm) instead of a string which is what we are sending back now. Or should this be handled on the workflow side, perhaps utilizing a mutate node before submitting to the Create User Node?

Thanks for your assistance.

-Leo

1 Like

Hi Leo,

I built out a similar example and was able to recreate this problem. After a bit of research, I discovered a Stack Overflow post with the answer:

“HTML provides no way to generate JSON from form data.”

Thus, if you would like to handle the form data client-side, you will have to use Javascript, and these answers have some suggestions on how to do so. If you would like to do this in the workflow, you would need only add a Mutate node:

Now my payload is in the correct format!

Thanks,
Julia

1 Like

That works great for taking in the company submitted by the user and adding is as a userTag to the created experience user.
Thanks!

-Leo

To complete this thread, is there a way to assign a group to a user from a workflow?
In my case, a user from an existing company (group) signs up and enters a company code. This company code is registered under a group (company) and I use a data table to store my companies and company codes.
When a user submits a company code, the group name is pulled from the data table, and this name is used to get the group.

Here is my group in my payload:
image

Now, I can’t manage to assign this group to the user from the workflow, using the “User: Update” node:

image
Note that I’ve tried {{data.group.id}} and {{data.group.name}} without success.
Any tips?

@Jules_Huguenin,

I just did some testing on my end and was able to update User groups with the ID.

Here’s my workflow:
image

Here’s what’s in my Virtual Button:

{
    "group": {
        "id": "5fd0f20633491f0006da973f",
    }
}

And here’s my User Group configuration in my User: Update Node:

image

How are you referencing the user you are trying to update the group for? Via email or with the user ID that’s provided in the Experience Context? For example, I am just updating the group for 1 user:

image

When your experience workflow runs, is the user being removed from all groups? Or, is the group just not updating to what you would like it to be?

How are you getting the group ID for the group you would like the user to be moved to?

As always, you can right click a payload path and copy the path:
image

Don’t forget you can test templates in the workflow engine with the Payload Tester:
image

And you can always copy the whole payload to clipboard, and test it in the Template Tester in our documentation.

1 Like

Thanks @Heath for your help, it works now!

1 Like