Hi,
We developed a custom Connect app for a customer that used an undocumented API to retrieve the Page Name for a given page ID in a JSM knowledge base in order to render a list for a report.
It recently stopped working, and we are investigating whether it is possible to release this app publicly.
Essentially the “get Articles” https://developer.atlassian.com/cloud/jira/service-desk/rest/api-group-knowledgebase/#api-rest-servicedeskapi-knowledgebase-article-get resource only has a free text search field, and since the only information our app has about knowledge base pages is the page ID - we have no way to reliably retrieve this page name.
What would be ideal would be an extra parameter to the search that allows specifying a list of page id’s, and being able to get the summary information for each page - alternatively a get page by ID API.
The bigger problem is that we have no way to suggest or request this change - is there any way for this feedback to be passed to the relevant team? In general - what should we do with such requests?
@richard.white
Although, ‘get articles’ API is an experimental API, I will have to check with our team if it’s ok to release the app publicly using it.
As for how to retrieve the page name using page ID, for now, there is no straightforward way to go about it. But I have found a workaround and see if it works for you:
https://{your-domain}.atlassian.net/rest/servicedeskapi/knowledgebase/article?query=project={project-key}
Try making the GET request to above API along with correct auth and 'X-ExperimentalApi: opt-in'
header.
You will get a list of knowledge base articles and you can filter through them with a bit of code. Here is an example:
function findTitleById(jsonData, idToSearch) {
// Loop through the 'values' array
for (let i = 0; i < jsonData.values.length; i++) {
// Check if the 'pageId' matches the given ID
if (jsonData.values[i].source.pageId === idToSearch.toString()) {
// Return the 'title' if a match is found
return jsonData.values[i].title;
}
}
// Return null if no match is found
return null;
}
// Sample JSON data
const jsonData = {
"size": 2,
"start": 0,
"limit": 50,
"isLastPage": true,
"_links": {
"self": "https://your-domain.atlassian.net/rest/servicedeskapi/knowledgebase/article?query=project=AS",
"base": "https://your-domain.atlassian.net",
"context": ""
},
"values": [
{
"title": "ASSETS",
"excerpt": "Welcome to your new knowledge base space!\nWe've ad",
"source": {
"type": "confluence",
"pageId": "1413972162",
"spaceKey": "AS"
},
"content": {
"iframeSrc": "https://your-domain.atlassian.net/rest/servicedeskapi/knowledgebase/article/view/1413972162"
}
}
]
};
// Test the function
const idToSearch = 1413972162;
const title = findTitleById(jsonData, idToSearch);
if (title) {
console.log(`Title found: ${title}`);
} else {
console.log('No matching ID found');
}
Let me know if that helps.
2 Likes
Hi @aagrawal2 ,
Thanks so much for the quick reply - that will help a bit - but obviously not ideal - I think we will have to consider the case where there might be several hundred pages in the knowledgebase - and perhaps cache the results or something.
Your query format query=project={project-key}
does not seem to be documented anywhere - is there any more information or other information about it?
In this case, I tried it from the top of my mind. This is the same behaviour as of Jira context parameters.
In the page, it says:
The context variable must be either a path component or the value
in a query string parameter formatted as name=value
.
Hi @aagrawal2
It does seem to work - however - is it possible you could request the team to document this behaviour. It is really not intuitive that searching linked Confluence pages works by specifying Jira context parameters in the free text query field and it is not mentioned on the rest api documentation.
Agreed. I will pass this on to the team. Thanks.