Forums

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

Confluence API - How to order content by lastmodified date?

Ben Loseby March 21, 2023

Hiya All,

 

I am currently trying to integrate with the Confluence API, to get wiki content pages to be used in a separate application. As part of this integration, I need to query content pages, and get pages updated within the last 24 hours, which is where to issue is occurring. I am getting errors when attempting to order by, or filter by the last modified date.

I have outlined more details below.

The Goal:

The Issue:

  • When using the below call, I am seeing a 400 error with the message 'com.atlassian.confluence.api.service.exceptions.BadRequestException: Unsupported orderBy field: history.lastUpdated desc'.
    • https://{{my domain}}.atlassian.net/wiki/rest/api/content?expand=history.lastUpdated&orderby=history.lastUpdated desc
  • An alternative approach that was tried was the search endpoint, and CQL, but this returns another error, detailed below.
    • https://{{my domain}}.atlassian.net/wiki/rest/api/content/search?cql=type = page and lastmodified > startOfWeek()
    • Error: "com.atlassian.confluence.api.service.exceptions.SSStatusCodeException: CQL was parsed but the search manager was unable to execute the search. Error message: com.atlassian.confluence.api.service.exceptions.SSStatusCodeException: There was an illegal request passed to XP-Search Aggregator API : HTTP/1.1 403 Forbidden"
Any assistance is much appreciated.

2 answers

1 accepted

0 votes
Answer accepted
Ben Loseby March 23, 2023

After more testing an experimentation, I have managed to achieve the desired goal using the search endpoint. The original issue was due permissions on the account making the call.

When using another account with increased permissions, I was able to make the below call, using an encoded object for the query itself.

https://{{my domain}}.atlassian.net/wiki/rest/api/content/search?limit=25&start=0&cqlcontext=%7B%22contentId%22%{{content ID}}%2C%22contentStatuses%22%3A%5B%22current%22%5D%2C%22spaceKey%22%{{space key}}%7D&cql=type%3Dpage%20and%20lastModified%3Enow%28%27-1d%27%29&expand=body.storage%2Cversion

pre-enconding = {"contentId":{{content id}},"contentStatuses":["current"],"spaceKey":{{space key}}}

0 votes
Juan Carlos Vera
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 21, 2023

hi @Ben Loseby ,

try with something like this:

https://{{your domain}}.atlassian.net/wiki/rest/api/content?orderBy=lastmodified&expand=history
Ben Loseby March 22, 2023

Hi @Juan Carlos Vera ,

Thanks for getting back to me.

I have just tried the above, and whilst it does not error, the API seems to be ignoring the orderBy, and still order the results by createDate in ascending order.

I tested by trying to order using the createdDate, with the below, and even then it seems to ignore the direction specified:

  • /wiki/rest/api/content?orderby=createdDate%20Desc&expand=history
    • Note: "orderby" uses lowercase b
    • Attempted with both "desc" and "Desc" 
    • Errors claiming "Unsupported orderBy direction: createdDate Desc"
  • /wiki/rest/api/content?orderBy=createdDate%20Desc&expand=history
    • Note: "orderBy" uses uppercase B
    • Attempted with both "desc" and "Desc"  
    • Doesn't error but order by direction is ignored
  • /wiki/rest/api/content?orderBy=lastmodified%20desc&expand=history
    • Note: "orderBy" uses uppercase B
    • Attempted with both "desc" and "Desc"  
    • Doesn't error but order by direction is ignored
  • /wiki/rest/api/content?orderby=lastmodified%20desc&expand=history
    • Note: "orderby" uses lowercase b
    • Attempted with both "desc" and "Desc" 
    • Errors claiming "Unsupported orderBy field: lastmodified desc"

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events