Chilkat Online Tools

SQL Server / Atlassian Confluence Cloud / Update content template

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.

    -- {
    --   "templateId": "<string>",
    --   "name": "<string>",
    --   "templateType": "<string>",
    --   "body": {
    --     "value": "<string>",
    --     "representation": "<string>"
    --   },
    --   "description": "<string>",
    --   "labels": [
    --     {
    --       "prefix": "ipsum dolor Excepteur Duis",
    --       "name": "nulla et ipsum voluptate consectetur",
    --       "id": "nostrud enim proident cupidatat eu",
    --       "label": "enim Lorem veniam amet"
    --     },
    --     {
    --       "prefix": "amet",
    --       "name": "officia adipisicing ut labo",
    --       "id": "ipsum in tempor",
    --       "label": "est occaecat magna"
    --     }
    --   ],
    --   "space": {
    --     "key": "<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, 'templateId', '<string>'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'name', '<string>'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'templateType', '<string>'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'body.value', '<string>'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'body.representation', '<string>'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'description', '<string>'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'labels[0].prefix', 'ipsum dolor Excepteur Duis'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'labels[0].name', 'nulla et ipsum voluptate consectetur'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'labels[0].id', 'nostrud enim proident cupidatat eu'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'labels[0].label', 'enim Lorem veniam amet'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'labels[1].prefix', 'amet'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'labels[1].name', 'officia adipisicing ut labo'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'labels[1].id', 'ipsum in tempor'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'labels[1].label', 'est occaecat magna'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'space.key', '<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 @sbRequestBody int
    -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbRequestBody OUT

    EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @sbRequestBody

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'PUT', 'https://your-domain.atlassian.net/wiki/rest/api/template', @sbRequestBody, 'utf-8', 'application/json', 0, 0
    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
        EXEC @hr = sp_OADestroy @sbRequestBody
        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 @sbRequestBody
        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)

    -- {
    --   "templateId": "id ipsum ut",
    --   "name": "sit dolor sint dolore",
    --   "description": "magna",
    --   "labels": [
    --     {
    --       "prefix": "fugiat sit Ut in ea",
    --       "name": "dolor in",
    --       "id": "aliqua culpa veniam ea",
    --       "label": "officia tempor ea"
    --     },
    --     {
    --       "prefix": "exercitation culpa proident",
    --       "name": "nulla mollit adipis",
    --       "id": "laborum sint",
    --       "label": "fugiat"
    --     }
    --   ],
    --   "templateType": "in cillum",
    --   "_expandable": {
    --     "body": "anim aute officia in culpa"
    --   },
    --   "_links": {},
    --   "body": {
    --     "value": "aute sit pariatur consequat deserunt",
    --     "representation": "anonymous_export_view",
    --     "_expandable": {
    --       "content": "nulla cillum reprehenderit"
    --     },
    --     "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 @prefix nvarchar(4000)

    DECLARE @id nvarchar(4000)

    DECLARE @label nvarchar(4000)

    DECLARE @entityIdValue nvarchar(4000)

    DECLARE @entityValue nvarchar(4000)

    DECLARE @value nvarchar(4000)

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

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


END
GO

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-d '{
    "templateId": "<string>",
    "name": "<string>",
    "templateType": "<string>",
    "body": {
        "value": "<string>",
        "representation": "<string>"
    },
    "description": "<string>",
    "labels": [
        {
            "prefix": "ipsum dolor Excepteur Duis",
            "name": "nulla et ipsum voluptate consectetur",
            "id": "nostrud enim proident cupidatat eu",
            "label": "enim Lorem veniam amet"
        },
        {
            "prefix": "amet",
            "name": "officia adipisicing ut labo",
            "id": "ipsum in tempor",
            "label": "est occaecat magna"
        }
    ],
    "space": {
        "key": "<string>"
    }
}'
https://your-domain.atlassian.net/wiki/rest/api/template

Postman Collection Item JSON

{
  "name": "Update content template",
  "request": {
    "auth": {
      "type": "oauth2"
    },
    "method": "PUT",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"templateId\": \"<string>\",\n    \"name\": \"<string>\",\n    \"templateType\": \"<string>\",\n    \"body\": {\n        \"value\": \"<string>\",\n        \"representation\": \"<string>\"\n    },\n    \"description\": \"<string>\",\n    \"labels\": [\n        {\n            \"prefix\": \"ipsum dolor Excepteur Duis\",\n            \"name\": \"nulla et ipsum voluptate consectetur\",\n            \"id\": \"nostrud enim proident cupidatat eu\",\n            \"label\": \"enim Lorem veniam amet\"\n        },\n        {\n            \"prefix\": \"amet\",\n            \"name\": \"officia adipisicing ut labo\",\n            \"id\": \"ipsum in tempor\",\n            \"label\": \"est occaecat magna\"\n        }\n    ],\n    \"space\": {\n        \"key\": \"<string>\"\n    }\n}"
    },
    "url": {
      "raw": "{{baseUrl}}/api/template",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "template"
      ]
    },
    "description": "Updates a content template. Note, blueprint templates cannot be updated\nvia the REST API.\n\n**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:\n'Admin' permission for the space to create a space template or 'Confluence Administrator'\nglobal permission to create a global template."
  },
  "response": [
    {
      "name": "Returned if the template is updated.",
      "originalRequest": {
        "method": "PUT",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: oauth2",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"templateId\": \"<string>\",\n    \"name\": \"<string>\",\n    \"templateType\": \"<string>\",\n    \"body\": {\n        \"value\": \"<string>\",\n        \"representation\": \"<string>\"\n    },\n    \"description\": \"<string>\",\n    \"labels\": [\n        {\n            \"prefix\": \"officia ea in eu\",\n            \"name\": \"commodo mollit\",\n            \"id\": \"veniam minim nisi quis officia\",\n            \"label\": \"commodo\"\n        },\n        {\n            \"prefix\": \"cupidatat dolor aliqua laboris\",\n            \"name\": \"officia amet\",\n            \"id\": \"voluptate ad quis p\",\n            \"label\": \"eu sit adipisicing ea Ut\"\n        }\n    ],\n    \"space\": {\n        \"key\": \"<string>\"\n    }\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/template",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "template"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"templateId\": \"id ipsum ut\",\n \"name\": \"sit dolor sint dolore\",\n \"description\": \"magna\",\n \"labels\": [\n  {\n   \"prefix\": \"fugiat sit Ut in ea\",\n   \"name\": \"dolor in\",\n   \"id\": \"aliqua culpa veniam ea\",\n   \"label\": \"officia tempor ea\"\n  },\n  {\n   \"prefix\": \"exercitation culpa proident\",\n   \"name\": \"nulla mollit adipis\",\n   \"id\": \"laborum sint\",\n   \"label\": \"fugiat\"\n  }\n ],\n \"templateType\": \"in cillum\",\n \"_expandable\": {\n  \"body\": \"anim aute officia in culpa\"\n },\n \"_links\": {},\n \"body\": {\n  \"value\": \"aute sit pariatur consequat deserunt\",\n  \"representation\": \"anonymous_export_view\",\n  \"_expandable\": {\n   \"content\": \"nulla cillum reprehenderit\"\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 }\n}"
    },
    {
      "name": "Returned if the calling user does not have permission to update the\ntemplate.",
      "originalRequest": {
        "method": "PUT",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: oauth2",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"templateId\": \"<string>\",\n    \"name\": \"<string>\",\n    \"templateType\": \"<string>\",\n    \"body\": {\n        \"value\": \"<string>\",\n        \"representation\": \"<string>\"\n    },\n    \"description\": \"<string>\",\n    \"labels\": [\n        {\n            \"prefix\": \"officia ea in eu\",\n            \"name\": \"commodo mollit\",\n            \"id\": \"veniam minim nisi quis officia\",\n            \"label\": \"commodo\"\n        },\n        {\n            \"prefix\": \"cupidatat dolor aliqua laboris\",\n            \"name\": \"officia amet\",\n            \"id\": \"voluptate ad quis p\",\n            \"label\": \"eu sit adipisicing ea Ut\"\n        }\n    ],\n    \"space\": {\n        \"key\": \"<string>\"\n    }\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/template",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "template"
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}