How to get user information from Confluence REST API?

Ashwini Singh
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 17, 2017

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.

3 answers

3 votes
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 29, 2017

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.

Arjun Shukla May 30, 2017

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?

Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 30, 2017

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.

Like Stan Ry likes this
Daniel Sanabria Valdes
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 6, 2017

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!

Like Stan Ry likes this
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 6, 2017

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.

Like # people like this
Stan Ry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 26, 2019

@Stephen Deutsch 

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.

Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 30, 2019

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).

Like Stan Ry likes this
Stan Ry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 1, 2019

 

@Stephen Deutsch, 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

 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?

Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 4, 2019

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.

Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 4, 2019

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.

frithjof falck August 9, 2023

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 

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

2 votes
Alex van Vucht (GLiNTECH)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 5, 2020

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>]
Nicolas Esteves May 27, 2020

Thank you!

Second endpoint is what I was looking for. ;)

Michael Aglas January 26, 2023

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...

0 votes
tom_engels
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 20, 2024

Stephen Deutsch, 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.


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']

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events