It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Using the REST API, I need to get a list of all spaces with the status if archived or not

I need to get a list of all spaces and included if archived (or not).

I have successfully retrieved a list of all of my spaces using

url = ... rest/api/space
url = ... rest/spacedirectory/1/search?type=global

Both cases do not return the status value if archived or not. I've tried adding 'status' to expand but that doesn't help.

So, how can I tell if the space is archived or not?

1 answer

1 accepted

Filter the search results using the status parameter. Its value can be either 'archived' or 'current'

IE /wiki/rest/api/space?status=archived

Refer to this section of the Confluence REST API documentation for more info.

Hi Dave,

Well, you were close.  I really wanted to retrieve all Spaces then see each space's status value.  However, reading your link, all I have to do is put status in the expand to see the status value.

However, my focus right now is on Confluence Server and the link you sent does not work for Server.   The confluence server documentation is not as robust as cloud and reading it does not give me an obvious way to get the 'status' field back with each space.

This is the page I'm looking at for the server REST API - Space

The query for Confluence Server and Cloud look to be identical to me. Both have an identical endpoint "/rest/api/space" and both support the use of the status= parameter to filter the results.

When you submit a request to http://your_confluence_url/confluence/rest/api/space?status=archived , as per the Confluence Server documentation, does it or does it not return list of archived spaces?

According to the documentation, that endpoint can return the value of the status of the content of a space, but you have to ask for it specifically using the expand= parameter. On the documentation page, click the button 'schema' to see all the properties that can be returned. A few lines down down you'll see:

"content": {
"title": "Content",
"type": "object",
"properties": {
"status": {
"title": "Content Status",
"type": "object"
},
}

If you provide http://your_confluence_url/confluence/rest/api/space?expand then you should be given a list of what properties can be expanded.

So, I'm guessing the expanded request would be  http://your_confluence_url/confluence/rest/api/space?expand=definitions or http://your_confluence_url/confluence/rest/api/space?expand=definitions.content

Sorry, I don't have access to a Confluence Server ATM to test this, so just report your result.

Hi Dave, 

OK, my Server query does work correctly when I use

http://your_confluence_url/confluence/rest/api/space?status=archived

Where the Cloud and Server separate is on the results.  I've tried many expand combinations but I can't get anything from the content structure.

As a side note, for the server query, _expandable returns

"_expandable":{"metadata":"","icon":"","description":"","homepage":"/rest/api/content/15nnnn"}}

I can expand on only those values (like homepage) and get the expected results.

I've tried expanding with: 'defintions', 'defintions.content', 'content', 'content.status', etc. .. all have no effect.

The good news .. I can just search the specific status value and combine as needed.  But this is just a haunting curiosity why I can't retrieve back any of values under content.

OK, good to hear you have at least one method of getting the archived vs non-archived spaces.

As for the inability to expand the other properties or the REST API even reporting they're there, I'd guess you're using an older version of Confluence Server that didn't support those methods / properties listed on the linked documentation page.

PS. If this turns out to be the case, remember to mark the answer as accepted.

Like Robert Gottesman likes this

>>I'd guess you're using an older version of Confluence Server

The version I'm using is pretty current, vsn 7.3.1

There must be something else I'm missing  :~[

I just tested against Confluence Cloud and can confirm the status of the space is returned by the endpoint /wiki/rest/api/space

Here's an example of a response:

results 
0
id 16777218
key "AO"
name "ActiveObjects Plugin"
type "global"
status "current"
_expandable
settings "/rest/api/space/AO/settings"
metadata ""
operations ""
lookAndFeel "/rest/api/settings/lookandfeel?spaceKey=AO"
identifiers ""
permissions ""
icon ""
description ""
theme "/rest/api/space/AO/theme"
history ""
homepage "/rest/api/content/16744551"
_links
webui "/spaces/AO"
self "https://ecosystem.atlassian.net/wiki/rest/api/space/AO"

Sorry, can't provide any further advice re Confluence Server, as I don't have access to one ATM. 

I have a cloud account and verified your findings .. hence the issue is strictly on the server. Just posted a ticket to Atlassian support ... Once I hear back I will also post that answer here.

Dave, 

I posted an issue to the Atlassian help center and they clarified the situation.  You are absolutely correct dealing with the cloud.  The cloud doc on Get Spaces is accurate. And in both cases (cloud & server), you can only derive the status value by issuing a query on status. 

Atlassian admitted that the schema portrayed in api/space in the Server doc is not correct in that shows the entire schema .. you have to drill down in the middle to find the section that applies to space.  It appears the expand options for cloud and server are very similar in that to get information on labels you need to expand 'metadata.labels' and to get the description expand 'description.plain'.

Well done on the persistence and getting clarification from Atlassian.

Yeah, it's a bit of shame when the APIs of Server and Cloud diverge in functionality like this, but it's not that often and sometimes Server allows something nice that Cloud doesn't.

Like Robert Gottesman likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
6.13.8
TAGS
Community showcase
Posted in Confluence

Lessons and Learnings: Six Months of Working Remote [Discussion]

Hey there, folks! For most of us, the past six months- yes, you read that right- have been a journey. More people than ever before have pivoted to working remotely, and navigating being on-scre...

5,966 views 4 6
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you