I am trying to add user to SP group with worklflow. Am using REST api to achieve it and by making a HTTP service call from the workflow.
1 Answer
To add a user to a SharePoint group, you need to pass the following REST call:
executor.executeAsync({
url: "<app web url>/_api/SP.AppContextSite(@target)/web
/sitegroups(7)/users
?@target='<host web url>'",
method: "POST",
body: "{ '__metadata': { 'type': 'SP.User' }, 'LoginName':'i:0#.w|domain\\user' }",
headers: {
"accept": "application/json; odata=verbose",
"content-type": "application/json; odata=verbose"
},
success: successHandler,
error: errorHandler
});
(Reference: Users, groups, and roles REST API reference)
To handle the same in a Workflow, you need to define a request dictionary, define a metadata dictionary and finally calling parameters dictionary. Then you can make the call in the Wf. There's a lengthy post showing an example in here: http://codelesssharepointinfopath.com/workflow-useful-rest-calls-add-user-to-group/. Due to the length, I'll only pass it as a link