Hi all,
I'm facing problems with updating Confluence pages via API and can't figure out what the underlying issue is. I hope to find some help here 😊
What am I trying to achieve?
I want to pull two reports and update certain Confluence pages with this data on a daily basis. One is an overview of all user- and group permissions of all of our spaces (Confluence Cloud Enterprise), the other is an overview of all admin users of all of our spaces.
How am I trying to achieve this?
I developed a phython script (ok, let's be honest: I asked chatGPT to create a phython script 😂), which fetches all spaces and all permissions of these spaces, then generates the overview tables and finally updates the given pages with these tables.
What problem am I facing?
When I fetch up to 20 spaces, everything is fine, the script is doing what it's supposed to, the pages are updated as expected.
But when I fetch 30 or more spaces (I didn't test from which exact count between 20 and 30 the issue starts to occur), then the API endpoint to update the page returns following error code and message:
Failed to update page 733020532: 400, {"errors":[{"status":400,"code":"INVALID_REQUEST_PARAMETER","title":"Content body cannot be converted to new editor format","detail":null}]}
What's really strange (at least to me), is that the issue is not about fetching the spaces, this works fine for our ~200 spaces (I let the script print them for debugging reasons).
(Although I know that all permission tables for 200+ spaces are quite a lot, I'm sure that it does not necessarily exceed any page size limit: in a very early version of this script I already managed to update the page with all these tables. I just lost this version somehow, probably when I tried to redesign it 😣)
The target pages are in the new editor format, this isn't touched anywhere in the script.
Please find the relevant functions as follows (I don't find any way to post the code here in a proper way, so I just made screenshots of it):
Hi @Stefan Draber -
There is some ... interesting Python syntax going on here that I don't quite understand:
row += ""-join(f"<td>{'✔' if perms.get(operation) else '✘'}</td>" for operation in operation_to_column.keys())
(Also, it would probably be easier for people to debug and test this if you posted the actual code. Like maybe as a Snippet?)
So... what I would do is modify the script to echo the final content variable to a file.
Then install Storage Format Editor for Confluence FREE and try copy/pasting the content your script generates into a blank test page on your site.
Hopefully that will reveal where ChatGPT (oy) went wrong.
Hi @Darryl Lee
thanks for your feedback and raising this idea, I put the whole script into a snippet in our companys Bitbucket instance for better debugging: https://bitbucket.org/hermesgermany/workspace/snippets/5qgK4A/space-permissions.
Concerning the line you mentioned: this one puts a check mark when a user has a certain permission or a cross mark when he has not. The syntax should be okay, as it works fine when the script is limited to 20 spaces. In the end it looks as follows:
Unfortunately I'm very restricted in installing new apps, so this is not an option :\
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Stefan Draber - since I believe the content you are generating is metadata about your site, one thing you could maybe do is create your own personal Confluence Cloud instance, install that add-on, and paste in the content just to debug what's going on.
The other thing, since it looks like you're using some kind of fancy code editor, is to save that content file as HTML and then examine it to see if the editor shows you any syntax errors in the code.
(Confluence storage format isn't exactly HTML, but it's pretty close, and so the syntax checkers for most code editors should be able to help.)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Darryl Lee
I cannot express how thankful I am for your ideas on how to troubleshoot this gnarly issue: I've checked the generated content in my private instance with that mentioned app (thx @K15t GmbHand found the issue straight away. It wasn't about the script, but it was about a "&" character in a space name. I just had to escape it and now it works like a charme 🤗
Thanks a million again, this it what I love this community for!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Stefan Draberthanks very much for sharing your snippet, I had a use case in the past where it would have been very useful to programmatically capture space permissions and I never did get around to writing a script to do that (my preferred language is Python also) so your code will be very helpful to me.
I have also wanted to work on a script to update a Confluence page and while I have seen the API I haven't used it so you have given me a great starting point. I am also going to have fun learning what
Kudos!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you're welcome, happy to help 🙂
ThreadPoolExecutor is what ChatGPT suggested when I asked to tweak the performance of my script 😁
So, please take this as a disclaimer: I'm not a software engineer and have only very little knowledge and experience in writing code. I know enough to let AI write code to solve such small exercises, but I cannot evaluate at all if this is the best (or even a good) solution to do so.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I just updated the snippet once more.
It now contains the functionality to escape special characters in space names.
Plus, I decided to write the full permission overview in a HTML file and upload the file to the Confluence page, instead of updating the page directly with the permissions table. With more than 200 spaces, the page performance is much better with an attached file than with 200 tables 😁
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I can't help with the question, but hoping people will vote for this feature request. Thanks!
[CONFCLOUD-79567] Report to get the list of space administrators for all spaces on a instance - Create and track feature requests for Atlassian products.
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.