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

Update Confluence page via API does not work

Stefan Draber
Contributor
September 19, 2024

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):

update pages.pnggenerate permissions table.pngfetch spaces.png

If you need further information or script details, just let me know.
I'd be very happy for any hint you guys can give me!
Best regards,
Stefan

3 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
3 votes
Answer accepted
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 19, 2024

Hi @Stefan Draber -

There is some ... interesting Python syntax going on here that I don't quite understand:

row += ""-join(f"<td>{'&#x2714;' if perms.get(operation) else '&#x2718;'}</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. 

Stefan Draber
Contributor
September 19, 2024

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:

table in confluence.png

Unfortunately I'm very restricted in installing new apps, so this is not an option :\

Like Rick Westbrock likes this
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 19, 2024

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.)

Like # people like this
Stefan Draber
Contributor
September 20, 2024

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!

Like # people like this
0 votes
Rick Westbrock
Contributor
September 23, 2024

@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

ThreadPoolExecutor does.

Kudos!

Stefan Draber
Contributor
September 24, 2024

Hi @Rick Westbrock 

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.

Stefan Draber
Contributor
September 24, 2024

Hi @Rick Westbrock 

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 😁

 

Like Rick Westbrock likes this
0 votes
Christine Green
Contributor
September 19, 2024
TAGS
AUG Leaders

Atlassian Community Events