Chilkat Online Tools

SQL Server / Atlassian Confluence Cloud / Copy page hierarchy

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    -- Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    -- The following JSON is sent in the request body.

    -- {
    --   "destinationPageId": "Duis in",
    --   "copyAttachments": false,
    --   "copyPermissions": false,
    --   "copyProperties": false,
    --   "copyLabels": false,
    --   "copyCustomContents": false,
    --   "titleOptions": {
    --     "prefix": "<string>",
    --     "replace": "<string>",
    --     "search": "<string>"
    --   }
    -- }

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'destinationPageId', 'Duis in'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'copyAttachments', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'copyPermissions', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'copyProperties', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'copyLabels', 0
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'copyCustomContents', 0
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'titleOptions.prefix', '<string>'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'titleOptions.replace', '<string>'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'titleOptions.search', '<string>'

    -- Adds the "Authorization: Bearer <access_token>" header.
    EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://your-domain.atlassian.net/wiki/rest/api/content/:id/pagehierarchy/copy', 'application/json', @json
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        RETURN
      END

    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT @iTmp0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    PRINT @sTmp0
    EXEC @hr = sp_OADestroy @resp


    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json


END
GO

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-d '{
    "destinationPageId": "Duis in",
    "copyAttachments": false,
    "copyPermissions": false,
    "copyProperties": false,
    "copyLabels": false,
    "copyCustomContents": false,
    "titleOptions": {
        "prefix": "<string>",
        "replace": "<string>",
        "search": "<string>"
    }
}'
https://your-domain.atlassian.net/wiki/rest/api/content/:id/pagehierarchy/copy

Postman Collection Item JSON

{
  "name": "Copy page hierarchy",
  "request": {
    "auth": {
      "type": "oauth2"
    },
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"destinationPageId\": \"Duis in\",\n    \"copyAttachments\": false,\n    \"copyPermissions\": false,\n    \"copyProperties\": false,\n    \"copyLabels\": false,\n    \"copyCustomContents\": false,\n    \"titleOptions\": {\n        \"prefix\": \"<string>\",\n        \"replace\": \"<string>\",\n        \"search\": \"<string>\"\n    }\n}"
    },
    "url": {
      "raw": "{{baseUrl}}/api/content/:id/pagehierarchy/copy",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "content",
        ":id",
        "pagehierarchy",
        "copy"
      ],
      "variable": [
        {
          "key": "id",
          "value": "<string>",
          "type": "string",
          "description": "(Required) "
        }
      ]
    },
    "description": "Copy page hierarchy allows the copying of an entire hierarchy of pages and their associated properties, permissions and attachments.\n The id path parameter refers to the content id of the page to copy, and the new parent of this copied page is defined using the destinationPageId in the request body.\n The titleOptions object defines the rules of renaming page titles during the copy;\n for example, search and replace can be used in conjunction to rewrite the copied page titles.\n\n Response example:\n <pre><code>\n {\n      \"id\" : \"1180606\",\n      \"links\" : {\n           \"status\" : \"/rest/api/longtask/1180606\"\n      }\n }\n </code></pre>\n Use the /longtask/<taskId> REST API to get the copy task status."
  },
  "response": [
    {
      "name": "Returns a full JSON representation of a long running task",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: oauth2",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"destinationPageId\": \"id in esse\",\n    \"copyAttachments\": false,\n    \"copyPermissions\": false,\n    \"copyProperties\": false,\n    \"copyLabels\": false,\n    \"copyCustomContents\": false,\n    \"titleOptions\": {\n        \"prefix\": \"<string>\",\n        \"replace\": \"<string>\",\n        \"search\": \"<string>\"\n    }\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/content/:id/pagehierarchy/copy",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "content",
            ":id",
            "pagehierarchy",
            "copy"
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "Accepted",
      "code": 202,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "name": "Returned if original page or destination page doesn't exist.",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: oauth2",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"destinationPageId\": \"id in esse\",\n    \"copyAttachments\": false,\n    \"copyPermissions\": false,\n    \"copyProperties\": false,\n    \"copyLabels\": false,\n    \"copyCustomContents\": false,\n    \"titleOptions\": {\n        \"prefix\": \"<string>\",\n        \"replace\": \"<string>\",\n        \"search\": \"<string>\"\n    }\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/content/:id/pagehierarchy/copy",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "content",
            ":id",
            "pagehierarchy",
            "copy"
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "name": "Returned if the user does not have permission to create content at destination",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: oauth2",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"destinationPageId\": \"id in esse\",\n    \"copyAttachments\": false,\n    \"copyPermissions\": false,\n    \"copyProperties\": false,\n    \"copyLabels\": false,\n    \"copyCustomContents\": false,\n    \"titleOptions\": {\n        \"prefix\": \"<string>\",\n        \"replace\": \"<string>\",\n        \"search\": \"<string>\"\n    }\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/content/:id/pagehierarchy/copy",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "content",
            ":id",
            "pagehierarchy",
            "copy"
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}