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 https://developer.atlassian.com/cloud/confluence/rest/#api-space-spaceKey-property-key-put would possibly allow this by setting the key "status" to the value "archived" - like this:
curl --request PUT \ --url 'https://your-domain.atlassian.net/wiki/rest/api/space/{spaceKey}/property/status' \ --user 'email@example.com:' \ --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)?
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 'https://your-domain.atlassian.net/wiki/rest/api/space/{spaceKey}' \
--user 'email@example.com:' \
--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":"https://site.atlassian.net/wiki/rest/api/space/SPACEID","collection":"/rest/api/space","webui":"/spaces/SPACEID","base":"https://site.atlassian.net/wiki"}}
And the PUT call to set the space to archived:
PUT /wiki/rest/api/content/{id}
curl --request PUT \
--url 'https://your-domain.atlassian.net/wiki/rest/api/space/{spaceKey}' \
--user 'email@example.com:' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"status": "archived"}'
And another GET call to verify:
curl --request GET \
--url 'https://your-domain.atlassian.net/wiki/rest/api/space/{spaceKey}' \
--user 'email@example.com:' \
--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":"https://site.atlassian.net/wiki/rest/api/space/SPACEID","collection":"/rest/api/space","webui":"/spaces/SPACEID","base":"https://site.atlassian.net/wiki"}}
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.
Regards,
Stephen Sifers
Seems this doesn't work. I ran (through python):
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): oandacorp.atlassian.net:443
DEBUG:urllib3.connectionpool:https://oandacorp.atlassian.net:443 "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): oandacorp.atlassian.net:443
DEBUG:urllib3.connectionpool:https://oandacorp.atlassian.net:443 "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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
Regards,
Stephen Sifers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 'https://instancename.atlassian.net/wiki/rest/api/space/~12345 \
--user 'username@domain.com:APITOKEN \
--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":"https://instancename.atlassian.net/wiki/rest/api/space/~12345","collection":"/rest/api/space","webui":"/spaces/~12345","base":"https://instancename.atlassian.net/wiki"}}
Please give the above a try and let us know the results.
Regards,
Stephen Sifers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That worked perfectly. I made it work in my Python script too.
Thankyou for your help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
Regards,
Stephen SIfers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.