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

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?


Answers:
author: David Bakkers
body: 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](https://developer.atlassian.com/cloud/confluence/rest/api-group-space/#api-api-space-get) of the Confluence REST API documentation for more info.

comments: author: Robert Gottesman
body: 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](https://docs.atlassian.com/ConfluenceServer/rest/7.7.3/#api/space-spaces)


author: David Bakkers
body: 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 *`ht`* *`tp://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.


author: Robert Gottesman
body: 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.


author: David Bakkers
body: 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.


author: Robert Gottesman
body: **\>\>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 :\~\[


author: David Bakkers
body: 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.


author: Robert Gottesman
body: 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.


author: Robert Gottesman
body: 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](https://developer.atlassian.com/cloud/confluence/rest/api-group-space/#api-api-space-get) 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'.


author: David Bakkers
body: 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.


author: Robert
body: [@Robert Gottesman](/t5/user/viewprofilepage/user-id/504922) thanks!

didn't know how to get a description by REST, I'm got empty description.

But your advice was very helpful!
> "to get the description expand 'description.plain'"


Tags: atl-gruland

confluence-server

rest-api

server