How to enable/associate a newly created group with an app related directory via REST API?
Asked by Allan Margono:

I can create a new group via REST API but can't find any API to enable/associate the newly created group with the application Directory. Currently, this has to be done via the Admin console GUI.

Has anyone found the right API for this?

Thanks


Answers:
author: Allan Margono
body: see the reply section :-)


author: Bruno Vincent
body: Hello Allan,

Please see my answer here (this is a duplicate question as far as I understand it): <https://community.atlassian.com/t5/Crowd-questions/Atlassian-CROWD-REST-API-for-quot-Associating-linking-a-Group-to/qaq-p/582495>

comments: author: Allan Margono
body: Thanks Bruno,

It does the trick :-)

Another question, I can't remove a user from a group, it gave me error.

HTTP/1.1 500 Internal Server Error  
Server: Apache-Coyote/1.1  
X-Embedded-Crowd-Version: Crowd/2.11.0  
X-Crowd-User-Management-Version: 1.4  
X-ASEN: SEN-L9527447  
Set-Cookie: JSESSIONID=7ED6DFD32CFE6B3A68A178A3213EE782; Path=/crowd/; HttpOnly  
X-Content-Type-Options: nosniff  
Vary: Accept,Accept-Encoding  
Content-Type: application/json  
Transfer-Encoding: chunked  
Date: Fri, 02 Jun 2017 17:26:12 GMT  
Connection: close

{"message":"The validated object is null","status-code":500,"stack-trace":"java.lang.NullPointerException: The validated object is null\\r\\n\\tat org.apache.commons.lang3.Validate.notNull(Validate.java:222)\\r\\n\\tat org.apache.commons.lang3.Validate.notNull(Validate.java:203)\\r\\n\\tat com.atlassian.crowd.manager.application.AliasManagerImpl.findUsernameByAlias(AliasManagerImpl.java:41)\\r\\n\\tat sun.reflect.GeneratedMethodAccessor348.invoke(Unknown Source)\\r\\n\\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\\r\\n\\tat

...

Here is the RestApi snippet

curl -X DELETE -ik -u $app:$passwd -H "Content-Type: application/json" -H "Accept: application/json" https://$crowdServer/crowd/rest/usermanagement/1/group/user/direct?groupname=$name\&username=$user

Appreciate your input on this.

Thanks,

Allan


author: Bruno Vincent
body: The resource URI should be

*/rest/usermanagement/1/++user/group/++direct*

instead of

/rest/usermanagement/1/++group/user/++direct

;-)

<https://docs.atlassian.com/atlassian-crowd/latest/REST/#usermanagement/1/user-removeUserFromGroup>


author: Allan Margono
body: Thanks for quick response, still no luck, something weird with the error message it said groupName can't be empty.

HTTP/1.1 500 Internal Server Error  
Server: Apache-Coyote/1.1  
X-Embedded-Crowd-Version: Crowd/2.11.0  
X-Crowd-User-Management-Version: 1.4  
X-ASEN: SEN-L9527447  
Set-Cookie: JSESSIONID=AA14A44B09E04478E90B78DD6D12E5C0; Path=/crowd/; HttpOnly  
X-Content-Type-Options: nosniff  
Vary: Accept,Accept-Encoding  
Content-Type: application/json  
Transfer-Encoding: chunked  
Date: Fri, 02 Jun 2017 18:33:49 GMT  
Connection: close

{"message":"groupName cannot be null or empty","status-code":500,"stack-trace":"java.lang.NullPointerException: groupName cannot be null or empty\\r\\n\\tat org.apache.commons.lang3.Validate.notEmpty(Validate.java:395)\\r\\n\\tat

Here is the harcoded groupname and username:

curl -X DELETE -ik -u $app:$passwd -H "Content-Type: application/json" -H "Accept: application/json" https://$crowdServer/crowd/rest/usermanagement/1/user/group/direct?username=dude123\&groupname=qa_leads


author: Bruno Vincent
body: Worked for me with single quotes around the URL

*curl -X DELETE -i -u 'test:\*\*\*\*\*\*\*\*' -H "Content-Type: application/json" -H "Accept: application/json" 'http://localhost:8095/crowd/rest/usermanagement/1/user/group/direct?username=jdoe\&groupname=foo'*

HTTP/1.1 204 No Content  
Server: Apache-Coyote/1.1  
X-Embedded-Crowd-Version: Crowd/2.12.0  
X-Crowd-User-Management-Version: 1.4  
X-ASEN: SEN-1268554  
Set-Cookie: JSESSIONID=069C5553F7A440C5ED785E56B8D0834F; Path=/crowd/; HttpOnly  
X-Content-Type-Options: nosniff  
Content-Type: application/json  
Date: Fri, 02 Jun 2017 18:50:32 GMT


author: Allan Margono
body: Thanks Bruno, finally it worked by adding the single quotes around the URL as you suggested.


author: Allan Margono
body: I have just noticed that a new group that I created using Rest API, was marked as Active = False by default.

How can I change it to Actrive = True?

Thanks,

Allan


author: Allan Margono
body: Never mind, I have just added the missing "Active" attribute and set it to True.


author: Allan Margono
body: The suggestion here to link a group with an app works, [https://community.atlassian.com/t5/Crowd-questions/Atlassian-CROWD-REST-API-for-quot-Associating-lin...](https://community.atlassian.com/t5/Crowd-questions/Atlassian-CROWD-REST-API-for-quot-Associating-linking-a-Group-to/qaq-p/582495)

However if you have multiple directories that are associated with an app, then the newly created group only linked with the first directory in the order. How to link the new group with the rest of directories?