How to get user information from Confluence REST API?
Asked by Ashwini Singh:

I am trying to get user details like their name, email, phone, about me, department and position.

I am getting only following as response and no expandable properties.

URL - "/rest/api/user?username=sample"

++Response++

{"type":"known","username":"sample","userKey":"2edfc034541014edfc2c9ba06b8","profilePicture":{"path":"/images/icons/profilepics/default.png","width":48,"height":48,"isDefault":true},"displayName":"Sample, User","_links":{"base":"<https://confluence.com","context":"","self":"https://confluence.com/rest/experimental/user?key=2edfc034541014edfc2c9ba06b8>"}}

PS - I have modified to JSON details above to hide personal details.


Answers:
author: Stephen Deutsch
body: Hi Ashwini,

I'm fairly familiar with the Confluence API and I'm pretty sure that there is no way to get the information that you require via the REST API. Only name and e-mail should be available, but unfortunately phone, about me, department, and position are not accessible.

comments: author: Arjun Shukla
body: Hi Stephen,  
Can you please share how to get the user's email address.  
<https://docs.atlassian.com/confluence/REST/6.2.1/#user-getUser>  

What all is expadable while making the request?


author: Stephen Deutsch
body: Hi Arjun,

I stand corrected. It does seem possible to get the details using the new /rest/user API endpoint. Here is the usage:

https://\<confluence_url\>/\<context_path, if there is one\>/rest/api/user?username=\<username\>\&expand=details.personal,details.business

details.personal contains phone, website, and e-mail, and details.business contains position, department, and location.


author: Daniel Sanabria Valdes
body: Hi Stephen,

I also want to get the email address via REST, but it's missing.

That's what I got for:

GET /rest/api/user?username=myusername\&expand=details.personal,details.business

{  
"type": "known",  
"username": "myusername",  
"userKey": "myuserkey",  
"profilePicture": {  
"path": "/download/attachments...",  
"width": 48,  
"height": 48,  
"isDefault": false  
},  
"displayName": "myDisplayName",  
"_links": {  
"base": "baseURL",  
"context": "",  
"self": "..."  
}  
}

We are using the external LDAP user directory. Confluence Version 6.2.1.

Thanks for your help!


author: Stephen Deutsch
body: It appears that the expansions are not available for Confluence Server yet; I tested on Cloud and thought that it would be the same, but apparently the products are developing at a different pace.

An alternative to be able to get the e-mail address:

https://\<confluence_url\>/rest/prototype/1/user/non-system/myusername

The result should be in displayableEmail.


author: Stan Ry
body: [@Stephen Deutsch](/t5/user/viewprofilepage/user-id/781490)

Hi Stephen, could you please elaborate on using properties? How do I know what properties I can pass in the expand parametner of a specific API?

For example, how did you figure it out that the details.personal and details.business properties are available for expansion?

Is the /prototype/1/user/non-system/{username} API the only one that shows emails for the user? So there is no way to collect user names in emails in a single run, correct?

One has to collect all users by using /rest/api/group/{groupName}/member and then retrieve emails for each specific user, right?

Thank you.


author: Stephen Deutsch
body: To know what you can expand, do an API call and look under the "_expandable" key. For more information, look at this documentation: <https://docs.atlassian.com/atlassian-confluence/REST/6.6.0/>  
under "How to use expansion in the REST APIs"

On Confluence Cloud, /rest/api/user returns the e-mail address, but on server, it seems that it's not available except in that older call (this may change in 7.0).


author: Stan Ry
body: [@Stephen Deutsch](/t5/user/viewprofilepage/user-id/781490), thank you for support!

Consider the /rest/content API.

Provided example reads as follows:

Example request URI(s):  
[http://example.com/rest/api/content?spaceKey=TST\&title=Cheese\&expand=space,body.view,version,container](http://example.com/rest/api/content?spaceKey=TST&title=Cheese&expand=space,body.view,version,container)

The given response example however says:

version": {  
"by": {  
"type": "known",  
"username": "username",  
"userKey": "",  
"displayName": "Full Name",  
"_expandable": {  
"status": ""  
}  
}}

I am not seeing there none of these 'space', 'body.view', and 'version' expand options. Is it because the response has been already expanded? So the only way to further expand on 'version' would be to pass 'version.status' in expand parameter? Correct?


author: Stephen Deutsch
body: Note that there should be several _expandable entries in the response. This particular expandable section is for version, so version can be expanded to "version.status", but later in the response you should see other expandable fields. It's possible that the example response is truncated.


author: Stephen Deutsch
body: And yes, for version, the only further expansion would be status, so instead of "version" you would put "version.status" in the expand parameter of your request.


author: frithjof falck
body: Any updates on the confluence api? can't seem to get extended profile information about a user on confluence data center, only status as an _expandable parameter. [@Stephen Deutsch](/t5/user/viewprofilepage/user-id/781490)

I find it a little strange that this is not an option using the REST api...


author: Alex van Vucht (GLiNTECH)
body: In recent versions of Confluence Server, I use three endpoints to get all information on a user:

GET rest/api/user?username=\<username\>

GET rest/mobile/1.0/profile/\<username\>

POST rpc/json-rpc/confluenceservice-v2/getUserByName

* JSON Body: \[\<username\>\]

comments: author: Nicolas Esteves
body: Thank you!

Second endpoint is what I was looking for. ;)


author: Michael Aglas
body: is there also an endpoint for groups and their members... If I could just send an email to users of a group as simple as in Jira...


author: tom_engels
body: [Stephen Deutsch](https://community.atlassian.com/t5/user/viewprofilepage/user-id/781490), your second endpoint worked for me perfectly! Thank you! Here's my Python code for anyone else wondering if this still works in 2024... my function is returning the unique confluence user id. The user's email is not included in the response, but I personally only need the user id.  

<br />

```
import requests
CONFLUENCE_USER_ENDPOINT = 'https://confluence.company.com/rest/api/user' # Swap for your company's confluence domain
```

```

headers = {
"Authorization": f"Bearer: {AUTH_TOKEN}"
}
```

```
def get_user_id(self, username: str) -> str:
    get_parameters = {
        "username": f"{username}"
    }
    response = requests.get(url=CONFLUENCE_USER_ENDPOINT, headers=headers, params=get_parameters)
    print(response.raise_for_status())
    return response.json()['userKey']
```


Tags: rest-api