# Confluence spaces in the REST API

URL: https://goingstellar.ro/reference/atlassian-rest-api/spaces/

GET /wiki/api/v2/spaces filters by keys, ids, type and status, and returns the space id that later calls need. GET /wiki/api/v2/spaces/{id}/pages lists the pages in a space and pages through a cursor.

## Endpoints

| Method | Path | What it does |
|---|---|---|
| GET | `/wiki/api/v2/spaces` | Lists spaces; keys filters by space key. |
| GET | `/wiki/api/v2/spaces/{id}/pages` | Lists the pages of a space. |

## Examples

### GET /wiki/api/v2/spaces

Finds a space by key and reads its id and homepage id.

```bash
curl -G \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  --data-urlencode 'keys=SD' \
  'https://your-domain.atlassian.net/wiki/api/v2/spaces'
```

```python
import os
import requests

EMAIL = "you@example.com"
r = requests.get(
    'https://your-domain.atlassian.net/wiki/api/v2/spaces',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
    params={'keys': 'SD'},
)
print(r.status_code, r.text)
```

Response: HTTP 200

```
{
 "results": [
  {
   "homepageId": "655541",
   "status": "current",
   "name": "Software Development",
   "key": "SD",
   "id": "655364",
   "type": "onboarding"
  }
 ]
}
```

Sent to Atlassian Cloud on 29 Nov 2026.

### GET /wiki/rest/api/space/SD

The v1 lookup of the same space.

```bash
curl \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  'https://your-domain.atlassian.net/wiki/rest/api/space/SD'
```

```python
import os
import requests

EMAIL = "you@example.com"
r = requests.get(
    'https://your-domain.atlassian.net/wiki/rest/api/space/SD',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
)
print(r.status_code, r.text)
```

Response: HTTP 200

```
{
 "id": 655364,
 "key": "SD",
 "name": "Software Development",
 "type": "onboarding",
 "status": "current"
}
```

Sent to Atlassian Cloud on 29 Nov 2026.

### GET /wiki/api/v2/spaces/{spaceId}/pages

Lists the pages of the space, one per call, sorted by id.

```bash
curl -G \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  --data-urlencode 'limit=1' \
  --data-urlencode 'sort=id' \
  'https://your-domain.atlassian.net/wiki/api/v2/spaces/{spaceId}/pages'
```

```python
import os
import requests

EMAIL = "you@example.com"
r = requests.get(
    'https://your-domain.atlassian.net/wiki/api/v2/spaces/{spaceId}/pages',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
    params={'limit': '1', 'sort': 'id'},
)
print(r.status_code, r.text)
```

Response: HTTP 200

```
{
 "results": [
  {
   "parentId": null,
   "status": "current",
   "title": "Software Development",
   "id": "655541"
  }
 ],
 "_links": {
  "next": "/wiki/api/v2/spaces/655364/pages?limit=1&cursor=eyJpZCI6IjY1NTU0MSIsImNvbnRlbnRPcmRlciI6ImlkIiwiY29udGVudE9yZGVyVmFsdWUiOjY1NTU0MX0="
 }
}
```

Response headers:

```
Link: </wiki/api/v2/spaces/655364/pages?limit=1&cursor=eyJpZCI6IjY1NTU0MSIsImNvbnRlbnRPcmRlciI6ImlkIiwiY29udGVudE9yZGVyVmFsdWUiOjY1NTU0MX0=>; rel="next", <https://your-domain.atlassian.net/wiki>; rel="base"
```

Sent to Atlassian Cloud on 29 Nov 2026.

### GET {_links.next}

Follows the next link from the previous call as it is.

```bash
curl \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  'https://your-domain.atlassian.net{_links.next}'
```

```python
import os
import requests

EMAIL = "you@example.com"
r = requests.get(
    'https://your-domain.atlassian.net{_links.next}',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
)
print(r.status_code, r.text)
```

Response: HTTP 200

```
{
 "results": [
  {
   "parentId": "655541",
   "id": "655577",
   "status": "current",
   "title": "Template - Product requirements"
  }
 ],
 "_links": {
  "next": "/wiki/api/v2/spaces/655364/pages?cursor=eyJpZCI6IjY1NTU3NyIsImNvbnRlbnRPcmRlciI6ImlkIiwiY29udGVudE9yZGVyVmFsdWUiOjY1NTU3N30=&limit=1"
 }
}
```

Sent to Atlassian Cloud on 29 Nov 2026.

## How it behaves

- The v2 space entry has id as a string and homepageId, which is the root page of the space (conf-spaces-v2).
- With limit=1 the response holds one page, a Link header with rel="next" and _links.next in the body with the same cursor (conf-space-pages-limit1).
- The next URL is relative and already includes the limit, so it can be requested without changes (conf-space-pages-next).

## Pitfalls

- Space calls take the numeric id, not the key. Look the key up once and store the id.
- The next URL starts at /wiki, so it is prefixed with the site URL, not with the v2 base.
- Stop paging when the Link header and _links.next are both absent. The v2 intro says so.

## Questions and answers

### How do I find a space id?

Call GET /wiki/api/v2/spaces with keys set to the space key and read id.

## Related

- [Find a page by title](https://goingstellar.ro/reference/atlassian-rest-api/find-page-by-title/)
- [Create a page](https://goingstellar.ro/reference/atlassian-rest-api/create-page/)
- [Child pages](https://goingstellar.ro/reference/atlassian-rest-api/page-children/)
- [Confluence REST API v1 vs v2](https://goingstellar.ro/reference/atlassian-rest-api/confluence-v1-vs-v2/)
- [Labels](https://goingstellar.ro/reference/atlassian-rest-api/page-labels/)

## Sources

- [Get spaces (Confluence REST API v2)](https://developer.atlassian.com/cloud/confluence/rest/v2/api-group-space/#api-spaces-get)
- [Get pages in space (Confluence REST API v2)](https://developer.atlassian.com/cloud/confluence/rest/v2/api-group-page/#api-spaces-id-pages-get)
- [The Confluence Cloud REST API v2 (Atlassian Developer)](https://developer.atlassian.com/cloud/confluence/rest/v2/intro/)

