Adding Users to Group via the API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2019 03:27 AM
Hi
I am looking for some assistance if someone could assist. I can create the user which is all fine and well using the API, but when researching to add that user to a group. It appears that I need to look at using GlideRecord.
I had a look into this further to see how its done etc through the communities, but it appears that this is to setup business rules, or something along those lines instead of actually adding it through the api.
Can someone please advise a complete novice, on how to add a user to a group using the API? Also how this would look like within Postman?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2019 09:22 AM
here is the code that will do it:
var user_sysid = '62826bf03710200044e0bfc8bcbe5df1';
var group_sysid = 'b85d44954a3623120004689b2d5dd60a';
var gr = new GlideRecord('sys_user_grmember');
gr.initialize();
gr.setValue('user', user_sysid);
gr.setValue('group', group_sysid);
gr.insert();
variations on this depend upon how you are adding the user to the group?
through a job? another record?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2019 09:22 AM
You'll want to use a POST pointed at the sys_user_grmember table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2019 09:25 AM
Hi,
user group relationships are stored in a table named sys_user_grmember.
you could simply do this with the table API. given that you know the sys ids of the user and the group.
To do this with by group/user names require a scripted rest api (preferably). Other wise you will need to have your business logic regarding searching and returning the proper accounts/groups stored on the consuming side of the integration, which is less than ideal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2019 12:22 AM
Thank you for the response in this
@Asbjørn, yes. I am looking to avoid attempting to do this through business rules. I'd rather allow the script to do the creation of the user and then the adding into a particular group.
I tried what you have suggested on the screenshot. It appears that I am receiving a bad request when doing so.
{
"error": {
"message": "Exception while reading request",
"detail": "Cannot decode: java.io.StringReader@6a0562"
},
"status": "failure"
}
Is there something which I am missing?