We are attempting to use the Confluence Cloud API to fetch data from a specific space, created by a particular user within the last 7 days, and containing a specific GitLab URL. While this search works correctly in the Confluence UI, the API endpoint is not returning any results.
The API search should return the same results as the UI search when using equivalent search criteria.
The API search returns no results, while the UI search successfully finds the expected pages.
Below is the CQL query used.
```
cql = ('space = XYZ AND ' 'text ~ "https://gitlab.company.internal/company/group/repo-old/-/merge_requests/123" AND ' 'type = page AND ' 'contributor in (user-x) AND ' 'lastModified >= now("-7d")')
```
Needs Investigation ?
Unable to programmatically search and retrieve Confluence content that is known to exist and is accessible through the UI. This impacts our ability to automate certain processes and integrate Confluence data with other systems.
I was able fix this with below approach.
So My Merge Request URL was below :
`https://gitlab.company.internal/company/group/repo-old/-/merge_requests/123`
MR Link
https://gitlab.company.internal/company/group/repo-old/-/merge_requests/123
CQL :
cql = f'space=QDN and text ~ "https:\/\/gitlab\.company\.internal\/company\/group\/repo\-old\/\-\/merge_requests\/123" and type = page'
Script To Lookup For URL Link on Confluence Using CQL
import requests
from requests.auth import HTTPBasicAuth
import json
import urllib.parse
url = "https://mycompany.atlassian.net/wiki/rest/api/search"
auth = HTTPBasicAuth(username="user@password", password="Pass***=****")
headers = {
"Accept": "application/json"
}
cql = f'space=XYZ and text ~ "https:\/\/gitlab\.company\.internal\/company\/group\/repo\-old\/\-\/merge_requests\/123" and type = page'
query = {
'cql': cql
}
response = requests.request(
"GET",
url,
headers=headers,
params=query,
auth=auth
)
print(response.text)
json_data = json.loads(response.text)["results"][0]["title"]
print(json.dumps(json_data, indent=4))
My remarks:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
1. Using the same user for both UI and API operation.
2. Response of the API Request
{
"results": [],
"start": 0,
"limit": 25,
"size": 0,
"_links": {
"base": "https://your-domain.atlassian.net/wiki",
"context": "/wiki",
"self": "https://your-domain.atlassian.net/wiki/rest/api/content/search?cql=space%20=%20XYZ%20AND%20text%20~%20%22https://gitlab.company.internal/company/group/repo-old/-/merge_requests/123%22%20AND%20lastmodified%20%3E=%20now(%22-7d%22)"
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you try this with a trivial query string like just "space=XYZ"?
If it worked, then maybe the whole problem is with not properly escaping the tilde or quotation or space characters... :-?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Below queries works
cql = ('space = XYZ AND '
'type = page AND '
'contributor in (user-x) AND '
'lastModified >= now("-7d")')
cql = ('space = XYZ AND '
'text ~ "repo-old" AND '
'type = page AND '
'contributor in (user-x) AND '
'lastModified >= now("-7d")')
But when i add the URL it fails completely
cql = ('space = XYZ AND '
'text ~ "https://gitlab.company.internal/company/group/repo-old/-/merge_requests/123" AND '
'type = page AND '
'contributor in (user-x) AND '
'lastModified >= now("-7d")')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import requests
from requests.auth import HTTPBasicAuth
import json
url = "https://your-domain.atlassian.net/wiki/rest/api/search"
auth = HTTPBasicAuth("email@example.com", "<api_token>")
headers = {
"Accept": "application/json"
}
cql = ('space = XYZ AND '
'text ~ "https://gitlab.company.internal/company/group/repo-old/-/merge_requests/123" AND '
'type = page AND '
'contributor in (user-x) AND '
'lastModified >= now("-7d")')
query = {
'cql': cql
}
response = requests.request(
"GET",
url,
headers=headers,
params=query,
auth=auth
)
print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
This is just input not the answer
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.