Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to query the linked Confluence space of a Jira Cloud project using the REST API?

Peter Velosy March 19, 2023

Dear Community,

After linking a Jira Cloud project with a Confluence space (Project pages -> Connect), how can I query the key/id of the associated Confluence space using the Jira (or Confluence) REST API?

Many thanks!

2 answers

1 accepted

0 votes
Answer accepted
Avery Lane
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 13, 2025

There isn't a way to get this from the REST API that I am aware of but you can get it through the Atlassian GraphQL gateway with a couple of queries:

      query GetAllJiraProjects(
        $cloudId: ID!, 
        $first: Int, 
        $after: String
      ) {
        jira {
          allJiraProjects(
            cloudId: $cloudId,
            filter: {}, 
            first: $first, 
            after: $after
          ) {
            edges {
              node {
                id
                name
              }
            }
            pageInfo {
              hasNextPage
              endCursor
            }
          }
        }
      }
      query GetConnectedConfluenceSpaces($projectARI: ID!) {
        devOps {
          ariGraph {
            relationships(
              filter: {from: $projectARI, type: "project-documentation-entity"}
              sort: {lastUpdatedSortDirection: DESC}
            ) {
              nodes {
                to {
                  id
                  data {
                    ... on ConfluenceSpace {
                      id
                      name
                    }
                  }
                }
              }
            }
          }
        }
      }

Variables:

  • $cloudId - A UUID-like string used in Atlassian Cloud (i.e. xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
  • $projectARI - starts with "ari:cloud:jira::", followed by "project/" (i.e. ari:cloud:jira:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx:project/xxxxx)
  • $first - how many records to return
  • $after - starting position used for pagination (put endcursor here)
1 vote
habib rahman
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.
March 19, 2023

Hi @Peter Velosy  my name is Habib I shall do my best to help you with the question. 


To query the key/id of the associated Confluence space using the Jira or Confluence REST API, follow these steps:

1. First, obtain the Jira Cloud project key and the Confluence Cloud space key.

2. Make a GET request to the Jira REST API endpoint that returns information about the project. The endpoint is in the following format:
```
https://your-domain.atlassian.net/rest/api/2/project/{projectKey}
```
Replace `{projectKey}` with the actual key of your Jira Cloud project.

3. In the response, look for a field called `projectCategory`. This field contains a nested object with a `projectCategoryKey` field. The value of `projectCategoryKey` is the key of the Confluence Cloud space associated with the Jira Cloud project.

4. Make a GET request to the Confluence REST API endpoint that returns information about the space. The endpoint is in the following format:
```
https://your-domain.atlassian.net/wiki/rest/api/space/{spaceKey}
```
Replace `{spaceKey}` with the actual key of your Confluence Cloud space.

5. In the response, look for a field called `key`. The value of `key` is the key of the Confluence Cloud space associated with the Jira Cloud project.

Alternatively, you can also use the Jira REST API to get the Confluence space key by making a GET request to the following endpoint:
```
https://your-domain.atlassian.net/rest/jira/latest/project/{projectKey}/properties/confluenceHome
```
Replace `{projectKey}` with the actual key of your Jira Cloud project.

The response will contain a `value` field, which is a URL that points to the Confluence Cloud space homepage. The space key is the last part of the URL, after the `/display/` path.


I hope this helps. 
thank you

Habib

Peter Velosy March 25, 2023

The Project Category is a different entity than the Confluence space associated with the Jira project. Maybe in your case, the two ID-s accidentally match up, but this is not the case on my end.

Like # people like this
Peter Velosy March 25, 2023

By the way, I have a strong suspect that you (provided that you are a human at all) generated this response with ChatGPT. Please refrain from spamming this expert forum this way. If you are a human who uses ChatGPT for researching information, please double-check if the response is correct and if it makes sense, as it is often not the case with language models.

Like Shawn Danisa likes this

Suggest an answer

Log in or Sign up to answer