Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Archive space for inactive users through REST API Edited

Support suggested a way to export the user list (which I can filter in code to the inactive users):

To generate a list of inactive users, you can go to the User Management and click on Export Users in the top right corner, that will generate a CSV file with the users.

Then suggested the REST API to archive the spaces:

It is not possible to bulk archive Spaces, however, you could check our public Confluence Rest API page and see if you come up with something, as this would involve custom development.

The API doc isn't clear on how this could be achieved or even if it can be... I can't find anything that definitively suggests it's possible to set the status of a space, though it does seem like would possibly allow this by setting the key "status" to the value "archived" - like this:

curl --request PUT \
  --url '{spaceKey}/property/status' \
  --user '' \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{
  "value": "archived",
  "version": {
    "number": 197,
    "minorEdit": true

Am I on the right track here? This is the first API task I've had to do with Confluence Cloud.

Is there a better way to achieve what I'm after (which is to have inactive users' spaces not appear in search/browsing)?

1 answer

Hello David,

What you have is excellent as far as the references you followed along with an example snippet of the curl call you’re wanting to make. From reviewing your JSON everything looks as though it should archive the space you’re targeting. To give an example of a GET, PUT then GET of what it will look like before during and after please see the following:

Here is GET call for the space I want to archive:
GET /wiki/rest/api/content

curl --request GET \
 --url '{spaceKey}' \
 --user '' \
 --header 'Accept: application/json'

JSON response:

{"id":123456,"key":"SPACEID","name":"Stephen Sifers Space","type":"global","status":"current","_expandable":{"settings":"/rest/api/space/SPACEOD/settings","metadata":"","operations":"","lookAndFeel":"/rest/api/settings/lookandfeel?spaceKey=SPACEID","permissions":"","icon":"","description":"","theme":"/rest/api/space/SPACEID/theme","history":"","homepage":"/rest/api/content/654321"},"_links":{"context":"/wiki","self":"","collection":"/rest/api/space","webui":"/spaces/SPACEID","base":""}}

And the PUT call to set the space to archived:

PUT /wiki/rest/api/content/{id}

curl --request PUT \
 --url '{spaceKey}' \
 --user '' \
 --header 'Accept: application/json' \
 --header 'Content-Type: application/json' \
 --data '{"status": "archived"}'

And another GET call to verify:

GET /wiki/rest/api/content

curl --request GET \
 --url '{spaceKey}' \
 --user '' \
 --header 'Accept: application/json'

JSON response:

{"id":123456,"key":"SPACEID","name":"Stephen Sifers Space","type":"global","status":"archived","_expandable":{"settings":"/rest/api/space/SPACEOD/settings","metadata":"","operations":"","lookAndFeel":"/rest/api/settings/lookandfeel?spaceKey=SPACEID","permissions":"","icon":"","description":"","theme":"/rest/api/space/SPACEID/theme","history":"","homepage":"/rest/api/content/654321"},"_links":{"context":"/wiki","self":"","collection":"/rest/api/space","webui":"/spaces/SPACEID","base":""}}

To answer your question about the best method, this is the best available method using the REST API to set a space to current or archived.

I hope this proves helpful and you’re able to manage your removed user's spaces without issue.

Stephen Sifers

Seems this doesn't work. I ran (through python):

DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1):
DEBUG:urllib3.connectionpool: "PUT /wiki/rest/api/content/25493507 HTTP/1.1" 404 None
DEBUG:root:jsonarchivespace: {u'data': {u'authorized': False,
u'errors': [],
u'successful': False,
u'valid': True},
u'message': u'com.atlassian.confluence.api.service.exceptions.NotFoundException: Could not find Content for update with id ContentId{id=25493507}',
u'statusCode': 404}

Which results in an error.


Then it occurred to me that the space isn't content, so your example seemed wrong... I tried with /space:

DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1):
DEBUG:urllib3.connectionpool: "PUT /wiki/rest/api/space/~biglesias HTTP/1.1" 400 None
DEBUG:root:jsonarchivespace: {u'data': {u'authorized': True,
u'errors': [{u'message': {u'args': [],
u'translation': u'Cannot change space type from personal to global or vice versa'}}],
u'successful': False,
u'valid': False},
u'message': u'com.atlassian.confluence.api.service.exceptions.BadRequestException: Cannot update Space',
u'statusCode': 400}

Which also doesn't work...

The documentation doesn't mention anything about setting a space to archived, so I'm thinking this either isn't possible or is an undocumented feature if it exists.

Other ideas were to check settings and properties, but there's nothing there for state either that I can find.

If this is possible, can someone point me to the documentation for it?

Hello David,

Thank you for attempting to follow the sent information. The examples provided are for curl and I can assure you I have tested these calls against a cloud instance. I did see a typo I had within the URL and have since updated that with the correct URL (I did have content when I should have had space as you stated).

From your results, I do see you’re attempting to archive a personal space but the following is being returned: "Cannot change space type from personal to global or vice versa". Please allow us to continue further testing to see if we’re able to recreate the same result on our end. If we’re able to recreate we will open a bug request on your behalf for this issue.

Stephen Sifers

Hello David,

I retested and found you have to add the space type for personal spaces to mark them as archived. I tested the following curl call and confirmed the space was marked as archived.

curl -v --request PUT \
 --url ' \
 --user ' \
 --header 'Accept: application/json' \
 --header 'Content-Type: application/json' \
 --data '{“type”: “personal”, “status": "archived"}'

A GET call returns the following:

{"id":12345,"key":"~12345","name":"Stephen Sifers","type":"personal","status":"archived","_expandable":{"settings":"/rest/api/space/~12345/settings","metadata":"","operations":"","lookAndFeel":"/rest/api/settings/lookandfeel?spaceKey=~12345","permissions":"","icon":"","description":"","theme":"/rest/api/space/~12345/theme","history":"","homepage":"/rest/api/content/12345"},"_links":{"context":"/wiki","self":"","collection":"/rest/api/space","webui":"/spaces/~12345","base":""}}

Please give the above a try and let us know the results.

Stephen Sifers

Like David Angelovich likes this

That worked perfectly. I made it work in my Python script too.

Thankyou for your help!

Like Stephen Sifers likes this

Hello David,

Thank you for confirming this is working with the updated JSON data. With this said, I have gone ahead and created a bug for this issue. You may find the bug request at CONFCLOUD-66918. Since this does impact you I would suggest you select “This affects my team” along with watching this bug for future updates.

Thanks again for being patient and working with us to resolve your issue and confirm a defect.

Stephen SIfers

Like David Angelovich likes this

Hello, I am trying this in October 2020, and I am getting an error -> HTTP Status 405 – Method Not Allowed - The method received in the request-line is known by the origin server but not supported by the target resource.

Does this no longer work?

NOTE: I am also on confluence server

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Confluence

Announcing Team Calendars in Confluence Data Center

Hi Community! We're thrilled to share that Team Calendars for Confluence is now a built-in feature for Confluence Data Center releases 7.11 and beyond.  A long time favorite,  Team Cale...

187 views 0 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you