Chilkat Online Tools

SQL Server / Atlassian Confluence Cloud / Convert content body

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

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

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

    -- {
    --   "value": "<string>",
    --   "representation": "<string>"
    -- }

    DECLARE @json int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'value', '<string>'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'representation', '<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/contentbody/convert/:to?expand=<string>&expand=<string>&spaceKeyContext=<string>&contentIdContext=<string>&embeddedContentRender=current', '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

    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 @json
        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)

    -- {
    --   "value": "eu dolor",
    --   "representation": "editor2",
    --   "_expandable": {
    --     "content": "anim"
    --   },
    --   "embeddedContent": [
    --     {
    --       "entityId": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "entity": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       }
    --     },
    --     {
    --       "entityId": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "entity": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       }
    --     }
    --   ],
    --   "webresource": {
    --     "keys": [
    --       {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       }
    --     ],
    --     "contexts": [
    --       {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       }
    --     ],
    --     "uris": {
    --       "all": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "css": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "js": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       }
    --     },
    --     "tags": {
    --       "all": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "css": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "data": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       },
    --       "js": {
    --         "value": "<Error: Too many levels of nesting to fake this schema>"
    --       }
    --     },
    --     "superbatch": {
    --       "value": "<Error: Too many levels of nesting to fake this schema>"
    --     }
    --   }
    -- }

    -- Sample code for parsing the JSON response...
    -- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    DECLARE @entityIdValue nvarchar(4000)

    DECLARE @entityValue nvarchar(4000)

    DECLARE @value nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @value OUT, 'value'
    DECLARE @representation nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @representation OUT, 'representation'
    DECLARE @Content nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Content OUT, '_expandable.content'
    DECLARE @Value nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Value OUT, 'webresource.uris.all.value'
    DECLARE @CssValue nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @CssValue OUT, 'webresource.uris.css.value'
    DECLARE @JsValue nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @JsValue OUT, 'webresource.uris.js.value'
    DECLARE @AllValue nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @AllValue OUT, 'webresource.tags.all.value'
    EXEC sp_OAMethod @jResp, 'StringOf', @CssValue OUT, 'webresource.tags.css.value'
    DECLARE @DataValue nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @DataValue OUT, 'webresource.tags.data.value'
    EXEC sp_OAMethod @jResp, 'StringOf', @JsValue OUT, 'webresource.tags.js.value'
    DECLARE @SuperbatchValue nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @SuperbatchValue OUT, 'webresource.superbatch.value'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'embeddedContent'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @entityIdValue OUT, 'embeddedContent[i].entityId.value'
        EXEC sp_OAMethod @jResp, 'StringOf', @entityValue OUT, 'embeddedContent[i].entity.value'
        SELECT @i = @i + 1
      END
    SELECT @i = 0
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'webresource.keys'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @value OUT, 'webresource.keys[i].value'
        SELECT @i = @i + 1
      END
    SELECT @i = 0
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'webresource.contexts'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @value OUT, 'webresource.contexts[i].value'
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-d '{
    "value": "<string>",
    "representation": "<string>"
}'
https://your-domain.atlassian.net/wiki/rest/api/contentbody/convert/:to?expand=<string>&expand=<string>&spaceKeyContext=<string>&contentIdContext=<string>&embeddedContentRender=current

Postman Collection Item JSON

{
  "name": "Convert content body",
  "request": {
    "auth": {
      "type": "oauth2"
    },
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"value\": \"<string>\",\n    \"representation\": \"<string>\"\n}"
    },
    "url": {
      "raw": "{{baseUrl}}/api/contentbody/convert/:to?expand=<string>&expand=<string>&spaceKeyContext=<string>&contentIdContext=<string>&embeddedContentRender=current",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "contentbody",
        "convert",
        ":to"
      ],
      "query": [
        {
          "key": "expand",
          "value": "<string>",
          "description": "A multi-value parameter indicating which properties of the content to expand.\n\n- `childTypes.all` returns whether the content has attachments, comments, or child pages.\nUse this if you only need to check whether the content has children of a particular type.\n- `childTypes.attachment` returns whether the content has attachments.\n- `childTypes.comment` returns whether the content has comments.\n- `childTypes.page` returns whether the content has child pages.\n- `container` returns the space that the content is in. This is the same as the information\nreturned by [Get space](#api-space-spaceKey-get).\n- `metadata.currentuser` returns information about the current user in relation to the content,\nincluding when they last viewed it, modified it, contributed to it, or added it as a favorite.\n- `metadata.properties` returns content properties that have been set via the Confluence REST API.\n- `metadata.labels` returns the labels that have been added to the content.\n- `metadata.frontend` this property is only used by Atlassian.\n- `operations` returns the operations for the content, which are used when setting permissions.\n- `children.page` returns pages that are descendants at the level immediately below the content.\n- `children.attachment` returns all attachments for the content.\n- `children.comment` returns all comments on the content.\n- `restrictions.read.restrictions.user` returns the users that have permission to read the content.\n- `restrictions.read.restrictions.group` returns the groups that have permission to read the content. Note that\nthis may return deleted groups, because deleting a group doesn't remove associated restrictions.\n- `restrictions.update.restrictions.user` returns the users that have permission to update the content.\n- `restrictions.update.restrictions.group` returns the groups that have permission to update the content. Note that\nthis may return deleted groups because deleting a group doesn't remove associated restrictions.\n- `history` returns the history of the content, including the date it was created.\n- `history.lastUpdated` returns information about the most recent update of the content, including\nwho updated it and when it was updated.\n- `history.previousVersion` returns information about the update prior to the current content update.\n- `history.contributors` returns all of the users who have contributed to the content.\n- `history.nextVersion` returns information about the update after to the current content update.\n- `ancestors` returns the parent page, if the content is a page.\n- `body` returns the body of the content in different formats, including the editor format,\nview format, and export format.\n- `version` returns information about the most recent update of the content, including who updated it\nand when it was updated.\n- `descendants.page` returns pages that are descendants at any level below the content.\n- `descendants.attachment` returns all attachments for the content, same as `children.attachment`.\n- `descendants.comment` returns all comments on the content, same as `children.comment`.\n- `space` returns the space that the content is in. This is the same as the information returned by\n[Get space](#api-space-spaceKey-get).\n\nIn addition, the following comment-specific expansions can be used:\n- `extensions.inlineProperties` returns inline comment-specific properties.\n- `extensions.resolution` returns the resolution status of each comment."
        },
        {
          "key": "expand",
          "value": "<string>",
          "description": "A multi-value parameter indicating which properties of the content to expand.\n\n- `childTypes.all` returns whether the content has attachments, comments, or child pages.\nUse this if you only need to check whether the content has children of a particular type.\n- `childTypes.attachment` returns whether the content has attachments.\n- `childTypes.comment` returns whether the content has comments.\n- `childTypes.page` returns whether the content has child pages.\n- `container` returns the space that the content is in. This is the same as the information\nreturned by [Get space](#api-space-spaceKey-get).\n- `metadata.currentuser` returns information about the current user in relation to the content,\nincluding when they last viewed it, modified it, contributed to it, or added it as a favorite.\n- `metadata.properties` returns content properties that have been set via the Confluence REST API.\n- `metadata.labels` returns the labels that have been added to the content.\n- `metadata.frontend` this property is only used by Atlassian.\n- `operations` returns the operations for the content, which are used when setting permissions.\n- `children.page` returns pages that are descendants at the level immediately below the content.\n- `children.attachment` returns all attachments for the content.\n- `children.comment` returns all comments on the content.\n- `restrictions.read.restrictions.user` returns the users that have permission to read the content.\n- `restrictions.read.restrictions.group` returns the groups that have permission to read the content. Note that\nthis may return deleted groups, because deleting a group doesn't remove associated restrictions.\n- `restrictions.update.restrictions.user` returns the users that have permission to update the content.\n- `restrictions.update.restrictions.group` returns the groups that have permission to update the content. Note that\nthis may return deleted groups because deleting a group doesn't remove associated restrictions.\n- `history` returns the history of the content, including the date it was created.\n- `history.lastUpdated` returns information about the most recent update of the content, including\nwho updated it and when it was updated.\n- `history.previousVersion` returns information about the update prior to the current content update.\n- `history.contributors` returns all of the users who have contributed to the content.\n- `history.nextVersion` returns information about the update after to the current content update.\n- `ancestors` returns the parent page, if the content is a page.\n- `body` returns the body of the content in different formats, including the editor format,\nview format, and export format.\n- `version` returns information about the most recent update of the content, including who updated it\nand when it was updated.\n- `descendants.page` returns pages that are descendants at any level below the content.\n- `descendants.attachment` returns all attachments for the content, same as `children.attachment`.\n- `descendants.comment` returns all comments on the content, same as `children.comment`.\n- `space` returns the space that the content is in. This is the same as the information returned by\n[Get space](#api-space-spaceKey-get).\n\nIn addition, the following comment-specific expansions can be used:\n- `extensions.inlineProperties` returns inline comment-specific properties.\n- `extensions.resolution` returns the resolution status of each comment."
        },
        {
          "key": "spaceKeyContext",
          "value": "<string>",
          "description": "The space key used for resolving embedded content (page includes,\nfiles, and links) in the content body. For example, if the source content\ncontains the link `<ac:link><ri:page ri:content-title=\"Example page\" /><ac:link>`\nand the `spaceKeyContext=TEST` parameter is provided, then the link\nwill be converted to a link to the \"Example page\" page in the \"TEST\" space."
        },
        {
          "key": "contentIdContext",
          "value": "<string>",
          "description": "The content ID used to find the space for resolving embedded content\n(page includes, files, and links) in the content body. For example,\nif the source content contains the link `<ac:link><ri:page ri:content-title=\"Example page\" /><ac:link>`\nand the `contentIdContext=123` parameter is provided, then the link\nwill be converted to a link to the \"Example page\" page in the same space\nthat has the content with ID=123. Note, `spaceKeyContext` will be ignored\nif this parameter is provided."
        },
        {
          "key": "embeddedContentRender",
          "value": "current",
          "description": "Mode used for rendering embedded content, like attachments.\n\n- `current` renders the embedded content using the latest version.\n- `version-at-save` renders the embedded content using the version at\nthe time of save."
        }
      ],
      "variable": [
        {
          "key": "to",
          "value": "<string>",
          "type": "string",
          "description": "(Required) The name of the target format for the content body."
        }
      ]
    },
    "description": "Converts a content body from one format to another format.\n\nSupported conversions:\n\n- storage: view, export_view, styled_view, editor\n- editor: storage\n- view: none\n- export_view: none\n- styled_view: none\n\n**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:\nIf request specifies 'contentIdContext', 'View' permission for the space, and permission to view the content."
  },
  "response": [
    {
      "name": "Returned if the content is converted.",
      "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    \"value\": \"<string>\",\n    \"representation\": \"<string>\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/contentbody/convert/:to?expand=<string>&expand=<string>&spaceKeyContext=<string>&contentIdContext=<string>&embeddedContentRender=current",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "contentbody",
            "convert",
            ":to"
          ],
          "query": [
            {
              "key": "expand",
              "value": "<string>"
            },
            {
              "key": "expand",
              "value": "<string>"
            },
            {
              "key": "spaceKeyContext",
              "value": "<string>"
            },
            {
              "key": "contentIdContext",
              "value": "<string>"
            },
            {
              "key": "embeddedContentRender",
              "value": "current"
            }
          ],
          "variable": [
            {
              "key": "to"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"value\": \"eu dolor\",\n \"representation\": \"editor2\",\n \"_expandable\": {\n  \"content\": \"anim\"\n },\n \"embeddedContent\": [\n  {\n   \"entityId\": {\n    \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n   },\n   \"entity\": {\n    \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n   }\n  },\n  {\n   \"entityId\": {\n    \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n   },\n   \"entity\": {\n    \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n   }\n  }\n ],\n \"webresource\": {\n  \"keys\": [\n   {\n    \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n   },\n   {\n    \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n   }\n  ],\n  \"contexts\": [\n   {\n    \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n   },\n   {\n    \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n   }\n  ],\n  \"uris\": {\n   \"all\": {\n    \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n   },\n   \"css\": {\n    \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n   },\n   \"js\": {\n    \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n   }\n  },\n  \"tags\": {\n   \"all\": {\n    \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n   },\n   \"css\": {\n    \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n   },\n   \"data\": {\n    \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n   },\n   \"js\": {\n    \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n   }\n  },\n  \"superbatch\": {\n   \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n  }\n }\n}"
    }
  ]
}