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

How can I use the remote API in Confluence to return a list of space keys?

MathewI May 8, 2013

Hello, All-

I'm trying to write a quick "garbage truck" script to run through and dump the trash for all of our spaces, but I'm not sure how to return a list of all space keys.

s.confluence2.getSpaces(token)

Seems to return the info I needed, but I just need the key for each space so I can iterate through them with.

Here is the rest of the script for context. I don't need help with anything beyond just getting the space keys. Thanks!

#!/usr/bin/python

import sys, os, urllib2, xmlrpclib
from urllib2 import URLError, HTTPError

wikiURL = "wiki url"

password = "password"
if password.endswith('\n'): password = password[:-1]

username = "username"


# Initialise XMLRPC session
s = xmlrpclib.ServerProxy(wikiURL + "/rpc/xmlrpc")

print "Logging in to " + wikiURL + " as user " + username
token = s.confluence2.login(username, password)

spaceList = s.confluence2.getSpaces(token)

print spaceList

spacekey = "SPACE"

#deleteTrash = s.confluence2.emptyTrash(token, spacekey)

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
MathewI May 9, 2013

Never mind- I'm not a python pro. Turns out I just needed to learn how dicts work

print "Logging in to " + wikiURL + " as user " + username
token = s.confluence2.login(username, password)

spaceInfo = s.confluence2.getSpaces(token)

for space in spaceInfo:
    spaceKey = space['key']
    print spaceKey

Toan Nguyen December 12, 2016

Is there anyway to ignore user's spaces?

TAGS
AUG Leaders

Atlassian Community Events