Add user to default users jira and conflunece with api script
Asked by Daniel Tveriya:

Hi,

I want use Atllasian API and users to defaults groups.

I tried API documents but without a success.

Did someone have example for that?

Thanks

Daniel


Answers:
author: Kieren _SmolSoftware_
body: Hi [@Daniel Tveriya](/t5/user/viewprofilepage/user-id/4845923)

I hope you were successful in getting your script to work? This has been an issue for a while for Atlassian Admins who want to utilise the default Atlassian groups for their SCIM sync'd users.

If you were unsuccessful, we do have an app that could help with this, essentially we're solving [ACCESS-604](https://jira.atlassian.com/browse/ACCESS-604). It's about to be released in a free closed beta around January 2024. If you're interested, contact us via our website [smolsoftware.com](http://smolsoftware.com/) to be a part of the beta.

-Kieren  
Co-Founder @ Smol Software \| Ex-Atlassian


author: David Pezet
body: I've had luck using the Jira [Add user to group](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-groups/#api-rest-api-3-group-user-post) endpoint. The call would be to something like,

```
https://<sitename>.atlassian.net/rest/api/3/group/user?groupname=<groupname>
```

(Note, that example is using groupname not groupid, at somepoint a groupname may change so choose accordingly.)

and the POST body should be something like,

```
{
"accountId": "<accountId>"
}
```

comments: author: David Pezet
body: Oh, and since it is a POST you will need to pass credentials in an Authorization header, [as described here](https://developer.atlassian.com/cloud/jira/platform/basic-auth-for-rest-apis/).


author: Daniel Tveriya
body: Thanks [@David Pezet](/t5/user/viewprofilepage/user-id/4480447) I will try.

But how I getting users id for all my site?

I tried also follow the docs but without a success.

Thanks


author: David Pezet
body: [Get all users](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-users/#api-rest-api-3-users-search-get) will provide a list. Use maxResults to increase the amount returned. Something like

```
/rest/api/3/users/search?maxResults=1000
```

(I'm not sure what the actual max is.)

If you have a larger, more general group you might also try [Get users from group](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-groups/#api-rest-api-3-group-member-get) to help control the list returned as well. This returns a paginated list of users in group.


author: Daniel Tveriya
body: I Using this script to get all my users directory   

# This code sample uses the 'requests' library:  
# <http://docs.python-requests.org>  
import requests  
import json

url = "<https://api.atlassian.com/admin/v1/orgs/{orgId}/users>"

headers = {  
"Accept": "application/json",  
"Authorization": "Bearer \<access_token\>"  
}

response = requests.request(  
"GET",  
url,  
headers=headers  
)

print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))  

how I getting the all users?


author: David Pezet
body: Unfortunately, I don't think that endpoint returns ALL users. It only returns the [organization's "managed" users](https://support.atlassian.com/user-management/docs/manage-your-organizations-atlassian-accounts/). The only way that comes to mind is to use the individual product's api (Jira's mentioned above) to get all users. Which product(s), are you hoping for?


author: Daniel Tveriya
body: I need to add new users to Jira and Confluence groups


author: David Pezet
body: Confluence uses the same groups handled by the Jira endpoint. So if all Confluence users are also in Jira you should be able to use the [Get all users](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-users/#api-rest-api-3-users-search-get) endpoint, or if not, you can use the [Get users from group](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-groups/#api-rest-api-3-group-member-get) endpoint passing your Confluence "Default Access Group" (typically confluence-user) -- this one is paginated so make sure to handle accordingly.


author: Daniel Tveriya
body: Hi David,  
My problem now is when I try to get a response from Jira, although I admit the response code is 403.

My user is admin and site.

Which permission am I missing?

Thanks


author: David Pezet
body: Do you have your user's api token encoded in your authorization header properly? Try Basic authentication, instead of Bearer. [See here for more details](https://developer.atlassian.com/cloud/jira/platform/basic-auth-for-rest-apis/). So it should look something like

```
"Authorization": "Basic <Base64 encoded token>"
```


Tags: administration

cloud