Project

General

Profile

Create a new user via REST api Users by adding Projects and roles in the same way/time.

Added by Emmanuel PRIZZI over 4 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></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

1.png (87.7 KB) 1.png
2.png (85 KB) 2.png
3.png (39.4 KB) 3.png
4.png (35.5 KB) 4.png
5.png (87.1 KB) 5.png

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 over 4 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;
}

?>

    (1-1/1)