XWiki REST API - Create a sub-page to an already existing page

Hello.
I continue working on migrating my knowledge base from another platform that uses categories as a way to organize the information.

Basically, the categories are “folders” and the equivalent to those are XWiki’s Nested Pages / Nested Spaces.

I’m having trouble getting the pages to actually go to the parent pages, I’m using the REST API to achieve that, but I am unable to define the parent of a page.

Another issue I’m having is that the pages created via the API are all created as “Terminal” pages, which also adds to the issue I’m having trying to make sub-pages. Is there any way to force pages created via the API to not be “terminal”?

I read the REST API docs and apparently what I’m doing here:

form_token = fetch_csrf_token(xwiki_url, username, password)
    
    # Set up headers for form-urlencoded data
    headers = {
        "Content-Type": "application/x-www-form-urlencoded",
        "XWiki-Form-Token": form_token,
        "X-Requested-With": "XMLHttpRequest"
    }
    encoded_title = urllib.parse.quote(page_name+".WebHome")
    # Prepare payload with title and content
    payload = {
        'title': page_name,
        'parent': urllib.parse.quote('Page creation request.Brief\: How are PUNCHED panels designed and fabricated?.WebHome'),
        'content': content
    }
    
    # Construct the URL for the XWiki REST API
    page_url = f"{xwiki_url}/rest/wikis/xwiki/spaces/{space}/pages/{encoded_title}"
    
    # Send the PUT request
    response = session.put(page_url, headers=headers, data=payload)

Under the “page_url” variable, I should expand the “spaces/{space}” to include all the levels of nesting I’m trying to achieve?

So, for example if I want to do
Main/sub1/sub2/page02

I should have the page_url programatically be
(…)/wikis/spaces/Main/spaces/sub1/spaces/sub2/pages/page01
?

Thanks in advance, let me know if something is unclear.

Bests,

Hi @franciscol,

Is the Page creation request.Brief\: How are PUNCHED panels designed and fabricated?.WebHome an actual XWiki page that you want to be used as parent?

Yes, that’s right.

Yes, that would be correct for a terminal page. For a non-terminal one (that could also have children) it would end with spaces/sub2/spaces/page01/pages/WebHome.

Hope it helps,
Alex

Hello @acotiuga , yes the page is an actual page on my WIki and it’s currently repeated all over as I was testing:

The page is not a terminal page

So, it actually exists, it’s clear that my issue was about the “Nested Spaces” on the URL not being handled well.

One question I do have, is how do I make the pages names less wordy?
Is there a way to have the name in the URL be an ID or similar?

One final question, what is the intention or purpose of specifying a parent page in terms of the Rest API?