How to check Cloud Confluence space last modified
Asked by Jack Hsia:

Hi All,

Does any one know how to check when is a space in cloud version was last modified?

Trying to archive the unused spaces to tidy up our confluence, but found it difficult to do so.

Thanks.

BR,

Jack Hsia


Answers:
author: Stephen Deutsch
body: I would assume that you are referring to when some action was performed in that space. Here's something I threw together real quick that will show the time when a page was last modified in that space. You can run it by pasting it into your browser console while you are logged into Confluence (usually brought up by pressing F12 or look for Developer tools in the browser menu) and it will return a list of spaces with the last modified date (should work for both Server and Cloud):

```
jQuery.ajax({dataType: 'json',
  contentType: 'application/json',
  type: 'POST',
  url: contextPath + '/rpc/json-rpc/confluenceservice-v2/getSpaces',
  success: function(spaces) {
    jQuery(spaces).each(function() {
      var space = this;
      if (space.type === "global") {
        jQuery.ajax({
          url: contextPath + '/rest/api/content/search?cql=space%3D' + space.key + '%20and%20type%3Dpage%20order%20by%20lastmodified%20desc&expand=version&limit=1',
          success: function(data) {
            console.log(space.name + "(" + space.key + ") - " + data.results[0].version.when);
          }
        });
      }
    });
  }
});
```

Also, if you're interested in managing pages better on your Confluence Cloud instance, you may want to check out [Space Timeline](https://marketplace.atlassian.com/plugins/space-timeline/cloud/overview), which allows you to manage pages easier.

comments: author: Jack Hsia
body: Hi Stephen,

Thank you very much for your help.

It works very well.

You've made my day.

Thanks again.

Jack


author: Bojana
body: Hi [@Stephen Deutsch](/t5/user/viewprofilepage/user-id/781490) \& [@Jack Hsia](/t5/user/viewprofilepage/user-id/328329)

I am looking for the same solution for cloud instance, is your code above still valid? I have tried to run it but getting errors...

Many thanks in advance! :)


author: Alex K
body: Hi [@Stephen Deutsch](/t5/user/viewprofilepage/user-id/781490) ,

I'm also looking for this functionality, code threw errors and no results. do let us know if you have modified solution.


author: Zden?k
body: I managed to get most of the space last updated dates via this script you cna put into browser console:
>
> ```
> var spaceInfo = {};
> var currentPage = 1;
> var pageSize = 50; // Adjust as needed, depending on your space count
>
> // Function to fetch space details
> function fetchSpaceDetails(spaceKey) {
> return new Promise((resolve, reject) => {
> jQuery.ajax({
> url: contextPath + '/rest/api/content/search?cql=space%3D' + spaceKey + '%20and%20type%3Dpage%20order%20by%20lastmodified%20desc&expand=version&limit=1',
> success: function (data) {
> if (data.results && data.results.length > 0 && data.results[0].version) {
> var lastUpdated = data.results[0].version.when;
> resolve(lastUpdated);
> } else {
> reject(new Error("Space details not found for " + spaceKey));
> }
> },
> error: function (error) {
> reject(error);
> }
> });
> });
> }
>
> // Function to fetch spaces page by page
> function fetchSpacesPage(page) {
> jQuery.ajax({
> dataType: 'json',
> contentType: 'application/json',
> type: 'GET',
> url: contextPath + '/rest/api/space',
> data: {
> limit: pageSize,
> start: (page - 1) * pageSize
> },
> success: function (spaces) {
> var totalSpaces = spaces.size;
> spaceInfo.totalSpaces = totalSpaces;
>
> jQuery(spaces.results).each(async function () {
> var space = this;
> if (space.type === "global") {
> try {
> var lastUpdated = await fetchSpaceDetails(space.key);
> spaceInfo[space.key] = {
> name: space.name,
> lastUpdated: lastUpdated
> };
> console.log(space.name + " (" + space.key + ") - " + lastUpdated);
> } catch (error) {
> console.error(error.message);
> }
> }
> });
>
> if ((page * pageSize) < totalSpaces) {
> fetchSpacesPage(page + 1);
> }
> },
> error: function (error) {
> console.error("Error fetching spaces: " + error.statusText);
> }
> });
> }
>
> fetchSpacesPage(currentPage);
> ```


Tags: cloud