Reputation: 109
I have a set of pages for "SOW","Data from Client", "Deliverable", etc inside many Spaces. I am reading the Space Key from Excel and able to iterate through all Spaces. However, I'm unable to figure out a way to loop through each page inside the Space. I have to look at each one to see its type before uploading the right document. Can you please let me know how to do this.
wiki/rest/api/search?cql=space= " + keyName Use this line for getting the Space. Extract the Json - res1 = response11.json() and loop through while x <= 6: name = str(res1['results'][x]['title']) However, this does not look for all the pages. In fact, it picks up the pages randomly.
I would appreciate it if you could give me a code snippet for performing this please.
Upvotes: 2
Views: 2176
Reputation: 109
Even better answer is to extract the results from the REST API response and loop through them using this code -
pages = res1['children']['page']['results']
i = 0
for p, page in enumerate(pages):
if(projectName == str(page['title'])):
print("Page Name - " + str(page['title']))
pageID = page['id']
Upvotes: 2
Reputation: 109
Was able to figure out how to do this.
Below is the API I am using - wiki/rest/api/space/" + spaceName + "/content"
Following is the code I am using for iterating through each page -
headers = {"Accept": "application/json"}
response11 = requests.request("GET", url, auth=auth)
if response11.status_code != 404:
res11 = response11.json()
x = 0
while x < len(res11['page']['results']):
name = str(res11['page']['results'][x]['title'])
x = x + 1
time.sleep(6)
Upvotes: 0