Unable to move a Wiki Page to another Wiki using the REST API (when there is a ParentPageId)

I found some behavior that appears to be a bug (...errr defect) and wanted to post this here because I know that the devs often read this forum, and I wanted to provide a workaround for anyone else with the issue.

The issue occurs when you have a WikiPage that has a ParentPageId set, and you try to update both the WikiId and ParentPageId.

curl --location --request POST 'http://example.com/api.ashx/v2/wikis/pages/137.json' \
    --header 'Content-Type: application/x-www-form-urlencoded' \
    --header 'Rest-Method: PUT' \
    --data-urlencode 'WikiId=103' \
    --data-urlencode 'ParentPageId=117'

The result is this error.

    "WikiPage": null,
    "Info": [],
    "Warnings": [],
    "Errors": [
        "The page's parent must exist in the same wiki as the page."

The issue seems to be that the API checks the ParentPageId to see if it is in the CURRENT Wiki instead of checking to see if it exists in the TARGET Wiki.

The workaround is this...

  1. Update the Wiki Page by setting the ParentPageId to -1 and the WikiId to the target Wiki (in this case 103).
  2. Update the Wiki Page and set the ParentPageId to the correct parent (in this case 117).

With the workaround you end up having to update the Wiki Page twice instead of once.

fixed the workaround, condensing it to two steps
[edited by: robert.hanson at 7:26 PM (GMT 0) on Wed, Mar 18 2020]
Parents Reply Children
No Data