I have the following REST API url
{confluence}/rest/api/content?spaceKey={space}&type=blogpost&cql=space={space}+and+type=blogpost+order+by+created+desc&limit=2
and i get the following items in response
blog1
blog2
Theses blog posts are the oldest ones. I want the newest ones, and was expecting order by created desc
to work.
What am i doing wrong with &cql=
?
Edit:
I tried 'order by id DESC' as my result were like this, but it didn't change also. It look like cql is not taken into account at all. Do we have a way of having a more verbose output from rest such that it shows ho CQL is parsed ?
{
'id': '1',
'type': 'blogpost',
'status': 'current',
'title': 'blog1',
'_links': {
'webui': 'REDACTED',
'edit': 'REDACTED',
'tinyui': 'REDACTED',
'self': 'REDACTED'
},
'_expandable': {
'container': '/rest/api/space/REDACTED',
'metadata': '',
'operations': '',
'children': '/rest/api/content/REDACTED/child',
'restrictions': '/rest/api/content/REDACTED/restriction/byOperation',
'history': '/rest/api/content/REDACTED/history',
'ancestors': '',
'body': '',
'version': '',
'descendants': '/rest/api/content/REDACTED/descendant',
'space': '/rest/api/space/REDACTED'
}
}
{
'id': '2',
'type': 'blogpost',
'status': 'current',
'title': 'blog2',
'_links': {
'webui': 'REDACTED',
'edit': 'REDACTED',
'tinyui': 'REDACTED',
'self': 'REDACTED'
},
'_expandable': {
'container': '/rest/api/space/REDACTED',
'metadata': '',
'operations': '',
'children': '/rest/api/content/REDACTED/child',
'restrictions': '/rest/api/content/REDACTED/restriction/byOperation',
'history': '/rest/api/content/REDACTED/history',
'ancestors': '',
'body': '',
'version': '',
'descendants': '/rest/api/content/REDACTED/descendant',
'space': '/rest/api/space/REDACTED'
}
}
It is working here with this query:
{confluence}/rest/api/content/search?cql=space={space}%20and%20type=page%20order%20by%20created%20desc&limit=2
Note the following:
I use {confluence}/rest/api/content/search
instead of {confluence}/rest/api/content
, as documented in the Atlassian REST API documentation.
I use cql
as the only query parameter (and move space
and type
into the CQL query).
id
order does not always correspond to created
order - there are (at least here) pages with higher ids created before pages with lower ids. To verify, add &expand=history
to the query and check the history.createdDate
in the response. The following example uses order by created asc
: