Create a new user via REST api Users by adding Projects and roles in the same way/time.
Added by Emmanuel PRIZZI about 5 years ago
Hello,
I want to create a new user in redmine via REST API Users and add him into a project and role.
How to do that with the REST API Users ? http://www.redmine.org/projects/redmine/wiki/Rest_Users
DO i have to use memberships REST API ? => http://www.redmine.org/projects/redmine/wiki/Rest_Memberships
How to do that please ?
detail:
Find Attached the screen shot of My POST request with POSTMAN.
I have genenerated a php page with cURL and the creation is working fine but I can't add the project and roles (see attachments 5.png)
I use the API key for the the authentification (without login and passowrd visible)
The GET request (GET /users.xml) with POSTMAN, return this information (containing Projects and roles)
http://witsbue1000dit.eur.gad.schneider-electric.com:3000/redmine/users/2369.xml?include=memberships,groups
<user>
<id>2369</id>
<login>SESA481984</login>
<firstname>Emmanuel</firstname>
<lastname>PRIZZI</lastname>
<mail>emmanuel.prizzi@non.se.com</mail>
<created_on>2019-09-20T19:54:28+02:00</created_on>
<last_login_on>2019-09-23T15:46:55+02:00</last_login_on>
<api_key>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</api_key>
<status>1</status>
<groups type="array"></groups>
<memberships type="array">
<membership>
<id>6722</id>
<project id="12" name="OnSite Connect"/>
<roles type="array">
<role id="7" name="issues-user"/>
<role id="3" name="Manager "/>
</roles>
</membership>
</memberships>
</user>
Thanks
Replies (1)
RE: Create a new user via REST api Users by adding Projects and roles in the same way/time. - Added by Emmanuel PRIZZI about 5 years ago
Hello,
I found the solution.
I have created a group and add it in the project and the role.
I have used POSTMAN (free software) to build the PUT request and generated the php script:
(I use the API Key authentification and not the )
using the user_ids , the user is added in the group. It works fine ! :-)
php script:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_PORT => "3000",
CURLOPT_URL => "http://witsbue1000dit.eur.gad.schneider-electric.com:3000/redmine/groups/2392.xml?group[user_ids]=2421",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_HTTPHEADER => array(
"Postman-Token: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx",
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
image1.png (13.8 KB) image1.png | |||
image2.png (55.9 KB) image2.png | |||
image3.png (71.1 KB) image3.png | |||
image4.png (41.8 KB) image4.png |