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!
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:
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
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.
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.
@Avery Would there be a similar way to get a list for all the connected Confluence spaces per project within a Jira cloud instance?If so, how?In advance, thanks for your help.
Just a remark here - I tried to solve that via the steps above but finally ran into the following error - so that does NOT work for oauth authenticated situations which basically is always in our context.```The internal Atlassian GraphQL API (devOps.ariGraph.relationships with type: "project-documentation-entity", accessible via api.asApp().requestGraph()) knows the relationship but explicitly denies access: "Field is not available for OAuth authenticated requests" (Forge apps always authenticate via OAuth).```
devOps.ariGraph.relationships
type: "project-documentation-entity"
api.asApp().requestGraph()
"Field is not available for OAuth authenticated requests"
It looks like you're new here. Sign in or register to get started.