Add user to group - Crowd Rest API
Asked by Parvaneh Zand:

Hi,

I want to add a user as a direct member to a group via rest API.

I'm using crowd admin for authorization (basic mode). But the result is: Application failed to authenticate! "401".

I can log in to crowd using crowd admin username and password. I don't know how to fix this status.

Any suggestion?

```
curl --location --request POST 'https://localhost/crowd/rest/usermanagement/1/group/user/direct?groupname=samplegroup' \--header 'Authorization: Basic username&password' \--header 'Content-Type: application/json'\ --data-raw '{"name": "sampleuser"}'
```


Answers:
author: BIF01
body: Same error

```
401 Unauthorized

Application failed to authenticate
```

using Crowd REST API <https://docs.atlassian.com/atlassian-crowd/5.1.0/REST/#usermanagement/1/group-addUserAsDirectGroupMember>.  
Credentials are correct since other Crowd REST APIs work as expected.

Any advice?  
Thanks in advance.  
Cheers.

comments: author: BIF01
body: Gotcha!
> Please note that the `usermanagement` resource expects the callers to authenticate using the application credentials (i.e. the application name and password configured in Crowd). Calls to this APIs are restricted by IP as configured.
>
> Other resources expect the callers to authenticate using the user credentials.


author: Penn
body: I wrote a wrapper in Rust as well as leveraged ScriptRunner and HttpURLConnection to do REST API calls with our Crowd instance. In the base formatting for my json and URL looked similar to below:

URL:

<http://crowdBaseUrl/crowd/rest/usermanagement/latest/user/group/direct?username=>"user unique ID"

JSON:

"{"name": "NAME OF GROUP", "description": "LEFT BLANK", "type": "GROUP", "active": "true"}"

comments: author: BIF01
body: > URL:
>
> [http://crowdBaseUrl/crowd/rest/usermanagement/latest/user/group/direct?username=](http://crowdbaseurl/crowd/rest/usermanagement/latest/user/group/direct?username=)"user unique ID"
>
> JSON:
>
> "{"name": "NAME OF GROUP", "description": "LEFT BLANK", "type": "GROUP", "active": "true"}"

So, Crowd REST API <https://docs.atlassian.com/atlassian-crowd/5.1.0/REST/#usermanagement/1/user-addUserToGroup> is working for you?

Thanks in advance.  
Cheers.


author: Penn
body: Yeap! Been working since we deployed the applet to do the group assignments! Is yours not? Have you manually executed the REST API call in the browser to validate that you're hitting the API correctly?


author: BIF01
body: Solved, see <https://community.atlassian.com/t5/Crowd-questions/Re-Re-Add-user-to-group-Crowd-Rest-API/qaq-p/2272428/comment-id/6280#M6280>

Thanks for reply.


author: Penn
body: The username password you're using is the application username password correct? These are defined as applications in crowd, not as users in crowd.

comments: author: Parvaneh Zand
body: Hi [@Penn](/t5/user/viewprofilepage/user-id/4307494) , thanks for your answer. I am using Crowd Admin User (internal user!)

What is Application username exactly?


author: Penn
body: [@Parvaneh Zand](/t5/user/viewprofilepage/user-id/2797120) when you look at your crowd installation, in the web interface you have "Applications" at the top. Within Applications you define each application and the access controls for the application. The "Name" in each application as well as the "Password" for that application are what I'm referring to. I believe these are the access control values you need to be supplying.


author: keremh
body: I have the same problem, any solution found?


Tags: rest-api