SQL Server / Atlassian Confluence Cloud / Move a page to a new location relative to a target page
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
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
-- Adds the "Authorization: Bearer <access_token>" header.
EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'
DECLARE @resp int
EXEC sp_OAMethod @http, 'QuickRequest', @resp OUT, 'PUT', 'https://your-domain.atlassian.net/wiki/rest/api/content/:id/move/:position/:targetId'
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
RETURN
END
DECLARE @sbResponseBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody
DECLARE @jResp int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT
EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
EXEC sp_OASetProperty @jResp, 'EmitCompact', 0
PRINT 'Response Body:'
EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
PRINT @sTmp0
DECLARE @respStatusCode int
EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT
PRINT 'Response Status Code = ' + @respStatusCode
IF @respStatusCode >= 400
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
RETURN
END
EXEC @hr = sp_OADestroy @resp
-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)
-- {
-- "pageId": "Duis "
-- }
-- Sample code for parsing the JSON response...
-- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
DECLARE @pageId nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @pageId OUT, 'pageId'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO
Curl Command
curl -X PUT
-H "Authorization: Bearer <access_token>"
https://your-domain.atlassian.net/wiki/rest/api/content/:id/move/:position/:targetId
Postman Collection Item JSON
{
"name": "Move a page to a new location relative to a target page",
"request": {
"auth": {
"type": "oauth2"
},
"method": "PUT",
"header": [
],
"url": {
"raw": "{{baseUrl}}/api/content/:id/move/:position/:targetId",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"content",
":id",
"move",
":position",
":targetId"
],
"variable": [
{
"key": "id",
"value": "<string>",
"type": "string",
"description": "(Required) The ID of the page to be moved"
},
{
"key": "position",
"value": "<string>",
"type": "string",
"description": "(Required) The position to move the page to relative to the target page:\n* `before` - move the page under the same parent as the target, before the target in the list of children\n* `after` - move the page under the same parent as the target, after the target in the list of children\n* `append` - move the page to be a child of the target"
},
{
"key": "targetId",
"value": "<string>",
"type": "string",
"description": "(Required) The ID of the target page for this operation"
}
]
},
"description": "Move a page to a new location relative to a target page:\n\n* `before` - move the page under the same parent as the target, before the target in the list of children\n* `after` - move the page under the same parent as the target, after the target in the list of children\n* `append` - move the page to be a child of the target\n\nCaution: This API can move pages to the top level of a space. Top-level pages are difficult to find in the UI\nbecause they do not show up in the page tree display. To avoid this, never use `before` or `after` positions\nwhen the `targetId` is a top-level page."
},
"response": [
{
"name": "Page was successfully moved",
"originalRequest": {
"method": "PUT",
"header": [
{
"description": {
"content": "Added as a part of security scheme: oauth2",
"type": "text/plain"
},
"key": "Authorization",
"value": "<token>"
}
],
"url": {
"raw": "{{baseUrl}}/api/content/:id/move/:position/:targetId",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"content",
":id",
"move",
":position",
":targetId"
],
"variable": [
{
"key": "id"
},
{
"key": "position"
},
{
"key": "targetId"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"pageId\": \"Duis \"\n}"
},
{
"name": "Returned if;\n\n- A page already exists in the target space with the same name.\n User is advised to rename page before moving.\n- The move would create a parent-child loop (page becomes a descendant and ancestor of itself)\n- The page has permission restrict",
"originalRequest": {
"method": "PUT",
"header": [
{
"description": {
"content": "Added as a part of security scheme: oauth2",
"type": "text/plain"
},
"key": "Authorization",
"value": "<token>"
}
],
"url": {
"raw": "{{baseUrl}}/api/content/:id/move/:position/:targetId",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"content",
":id",
"move",
":position",
":targetId"
],
"variable": [
{
"key": "id"
},
{
"key": "position"
},
{
"key": "targetId"
}
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/plain"
}
],
"cookie": [
],
"body": ""
},
{
"name": "Returned if;\n\n- User does not have permission to remove page from current space\n- User does not have permission to create a page in target space",
"originalRequest": {
"method": "PUT",
"header": [
{
"description": {
"content": "Added as a part of security scheme: oauth2",
"type": "text/plain"
},
"key": "Authorization",
"value": "<token>"
}
],
"url": {
"raw": "{{baseUrl}}/api/content/:id/move/:position/:targetId",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"content",
":id",
"move",
":position",
":targetId"
],
"variable": [
{
"key": "id"
},
{
"key": "position"
},
{
"key": "targetId"
}
]
}
},
"status": "Forbidden",
"code": 403,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/plain"
}
],
"cookie": [
],
"body": ""
},
{
"name": "Returned if;\n\n- The id or targetId refer to non-existent pages",
"originalRequest": {
"method": "PUT",
"header": [
{
"description": {
"content": "Added as a part of security scheme: oauth2",
"type": "text/plain"
},
"key": "Authorization",
"value": "<token>"
}
],
"url": {
"raw": "{{baseUrl}}/api/content/:id/move/:position/:targetId",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"content",
":id",
"move",
":position",
":targetId"
],
"variable": [
{
"key": "id"
},
{
"key": "position"
},
{
"key": "targetId"
}
]
}
},
"status": "Not Found",
"code": 404,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/plain"
}
],
"cookie": [
],
"body": ""
}
]
}