1

I am trying to add 100 of users to a group in crowd and I want to automate it using curl and crowd's rest api. At first I am just trying to add a singleuser to a group and then auotmate it using shell script. Following this document, I pass the command as

curl -X POST{"name":"groupname"} -ik -u application:password-H 'Content-Type: application/json' -H 'Accept: application/json' https://localhost/crowd/rest/usermanagement/1/user/group/direct?username=username.

I am getting the following error.

HTTP/1.1 405 Method Not Allowed
Server: Apache-Coyote/1.1
X-Embedded-Crowd-Version: Crowd/2.8.3
X-Crowd-User-Management-Version: 1.4
Set-Cookie: JSESSIONID=17490A660F9A2267B378CD767CEADDF8; Path=/crowd/; Secure; HttpOnly
Allow: HEAD,DELETE,POST,GET,OPTIONS
X-Content-Type-Options: nosniff
Content-Type: text/html;charset=utf-8
Content-Language: en
Content-Length: 1013
Date: Mon, 29 Jun 2015 02:56:15 GMT

FYI: I am using a application to authenticate against crowd via rest. Please suggest on what I need to do and how should I do.

P.S. I also need to figure out on adding hudreds of groups to crowd too.

Kara
  • 6,115
  • 16
  • 50
  • 57
user1250496
  • 59
  • 2
  • 3

1 Answers1

2

You are missing a space between POST and your data.

To post data use:

-d, --data

(HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded. Compare to -F, --form.

So the command should be:

curl -X POST -d {"name":"groupname"} -ik -u application:password -H 'Content-Type: application/json' -H 'Accept: application/json' https://localhost/crowd/rest/usermanagement/1/user/group/direct?username=username

From Crowds Docs,

Authentication Access to all resources (using any method) requires the client to be authenticated via basic authentication. See RFC 2617.

Your environment must retain cookies set by the Crowd server and retransmit them on subsequent calls, otherwise Crowd will have to re-authenticate the application on every REST call.

So first authenticate your self and store the cookies, (make note of --cookie-jar parameter)

curl -i -u application_name:application_password --data '{"value": "my_password"}' http://localhost:8095/crowd/rest/usermanagement/1/authentication?username=my_username --header 'Content-Type: application/json' --header 'Accept: application/json' --cookie-jar cookies.txt

So as per docs on subsequent calls use the cookies (using --cookie parameter)

curl -X POST -d {"name":"groupname"} -ik -u application:password -H 'Content-Type: application/json' -H 'Accept: application/json' https://localhost/crowd/rest/usermanagement/1/user/group/direct?username=username --cookie cookies.txt
Yash
  • 182
  • 1
  • 4
  • Hi Yash, thank you for your help. One more question, Do my username have to be an admin for the crowd instance and what kind of application user name and password should i be using? Thanks again. – user1250496 Jun 29 '15 at 13:03
  • This is the way i did: curl -k -s -X POST -d '{"name":"admin-users"}' -u username:password -H 'Content-Type: application/json' -H 'Accept: application/json' "https://localhost.com/crowd/rest/usermanagement/1/user/group/direct?username=user" which fixed my concern. – user1250496 Jun 30 '15 at 18:31