Querying confluence spaces by name

Hi,

As part of an integration with confluence I would like to query spaces based on their name?

Use case:

  • I make a GET request to spaces passing a name field with value project
  • I expect to have spaces returned starting with this value, e.g project management , projects, etc…

It looks like the GET spaces endpoint V2 does not support this functionality.

Can this be implemented or alternatively, is there a different way to achieve this?

Thanks!

Hello and welcome,
you can use the confluence search API with an adequate cql to get the spaces you want.

Hi,

Thank you for your prompt reply.

I’ve tried using the Search API with a query like:
/wiki/rest/api/content/search?cql=space.title~"project"&limit=2

This returns pages within spaces matching the space title, but I actually need a way to get a list of spaces filtered by partial or wildcard space name.

Currently, the Spaces API doesn’t support filtering by space name, and the Search API does not return spaces directly.

Could you consider adding support to search or filter spaces by partial title via the API? This would greatly help integrations that need to query spaces by name.

Thanks for your help!

Adding the type=space to your CQL should do the trick

/wiki/rest/api/content/search?cql=type%3Dspace%20and%20space.title~%22project%22&limit=2

1 Like

Hi Corentin,

Thank you for looking into this.

It looks like specifying space as type does not work, it returns no result.

If I tweak your recommendation to have type=page though it does return results, but again, not the correct results because they are pages not spaces.

This tells me that while the syntax you used is correct, the endpoint does not support returning spaces.

Would you have anymore thoughts on this?

Have you tried a query with only type=space ? I’m thinking that you have something unexpected with the rest of your query space.title ~ "project"

Here is an example for my instance:

curl --location 'https://XXX.atlassian.net/wiki/rest/api/search?cql=type%3Dspace%20and%20space.title~%22dev%22' \
--header 'Authorization: Basic XXX'

Response:

 {
    "results": [
        {
            "space": {
                "key": "dev",
                "name": "dev",
                "type": "global",
                "metadata": {},
                "status": "current",
                "_expandable": {
                    "operations": "",
                    "permissions": "",
                    "roles": "",
                    "description": ""
                },
                "_links": {
                    "self": "XXX/wiki/rest/api/space/dev"
                }
            },
            "title": "dev",
            "excerpt": "",
            "url": "/spaces/dev",
            "resultGlobalContainer": {
                "title": "dev",
                "displayUrl": "/spaces/dev"
            },
            "breadcrumbs": [],
            "entityType": "space",
            "iconCssClass": "aui-icon content-type-space",
            "lastModified": "2023-07-25T15:04:53.000Z",
            "friendlyLastModified": "Jul 25, 2023",
            "score": 0.0
        }
    ],
    "start": 0,
    "limit": 25,
    "size": 1,
    "totalSize": 1,
    "cqlQuery": "type = space and space.title ~ \"dev\"",
    "searchDuration": 172,
    "_links": {
        "base": "XXX",
        "context": "/wiki",
        "self": "XXX/wiki/rest/api/search?cql=type%3Dspace%20and%20space.title~%22dev%22"
    }
}

Hi Corentin,

Thank you for your feedback.
I could get filtered spaces back. :partying_face:

The key thing was to use the search endpoint and not the search/content endpoint.
Here is an example that worked for me:

/wiki/rest/api/search?cql=type=space%20AND%20title~”project”&limit=2

2 Likes

Ah, sorry, I missed my copy/paste of the url in my first answer. Well done on finding hte solution in the end

Hi Corentin,

I have a follow up question.

Is there a way to make sure the space ids are being returned as part of the response?

I only see space keys.

Looking forward to hearing from you.