User Group Self-Management

experience
#1

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:

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

0 Likes

#2

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

0 Likes

#3

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.

0 Likes

#4

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

0 Likes

#5

Hi Leo,

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

Thanks,
Julia

0 Likes

#6

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

#7

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

#8

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

0 Likes