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
DECLARE @queryParams int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @queryParams OUT
EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'spaceKey', '<string>'
EXEC sp_OAMethod @queryParams, 'UpdateInt', @success OUT, 'start', 0
EXEC sp_OAMethod @queryParams, 'UpdateInt', @success OUT, 'limit', 25
EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'expand', '<string>'
EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'expand', '<string>'
-- Adds the "Authorization: Bearer <access_token>" header.
EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'
DECLARE @resp int
EXEC sp_OAMethod @http, 'QuickRequestParams', @resp OUT, 'GET', 'https://your-domain.atlassian.net/wiki/rest/api/template/page', @queryParams
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 @queryParams
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 @queryParams
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)
-- {
-- "results": [
-- {
-- "templateId": "pariatur adipisicing non Ut",
-- "name": "enim ullamco officia eu",
-- "description": "culpa",
-- "labels": [
-- {
-- "prefix": "Ut id pariatur",
-- "name": "amet ipsum reprehenderit",
-- "id": "ipsum",
-- "label": "do consectetur"
-- },
-- {
-- "prefix": "irure elit",
-- "name": "laboris cillum dolor pariatur aliquip",
-- "id": "deserunt consectetur d",
-- "label": "nisi ex"
-- }
-- ],
-- "templateType": "sunt eu",
-- "_expandable": {
-- "body": "Excepteur velit aliquip"
-- },
-- "_links": {},
-- "body": {
-- "value": "sint dolor mollit",
-- "representation": "view",
-- "_expandable": {
-- "content": "dolor"
-- },
-- "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>"
-- }
-- }
-- }
-- },
-- {
-- "templateId": "qui officia aute",
-- "name": "deserunt",
-- "description": "velit laborum cupidatat anim",
-- "labels": [
-- {
-- "prefix": "magna Ut",
-- "name": "culpa quis Duis",
-- "id": "et enim eiusmod quis",
-- "label": "elit qui"
-- },
-- {
-- "prefix": "eu proident",
-- "name": "pariatur non",
-- "id": "magna adipisicing ea amet sunt",
-- "label": "qui"
-- }
-- ],
-- "templateType": "nulla exercitation",
-- "_expandable": {
-- "body": "amet"
-- },
-- "_links": {},
-- "body": {
-- "value": "in ea consectetur",
-- "representation": "storage",
-- "_expandable": {
-- "content": "aliquip magna eu do "
-- },
-- "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>"
-- }
-- }
-- }
-- }
-- ],
-- "start": -93900983,
-- "limit": -84771492,
-- "size": -63798652,
-- "_links": {}
-- }
-- Sample code for parsing the JSON response...
-- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
DECLARE @templateId nvarchar(4000)
DECLARE @name nvarchar(4000)
DECLARE @description nvarchar(4000)
DECLARE @templateType nvarchar(4000)
DECLARE @Body nvarchar(4000)
DECLARE @Value nvarchar(4000)
DECLARE @Representation nvarchar(4000)
DECLARE @Content nvarchar(4000)
DECLARE @AllValue nvarchar(4000)
DECLARE @CssValue nvarchar(4000)
DECLARE @JsValue nvarchar(4000)
DECLARE @DataValue nvarchar(4000)
DECLARE @SuperbatchValue nvarchar(4000)
DECLARE @j int
DECLARE @count_j int
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 @start int
EXEC sp_OAMethod @jResp, 'IntOf', @start OUT, 'start'
DECLARE @limit int
EXEC sp_OAMethod @jResp, 'IntOf', @limit OUT, 'limit'
DECLARE @size int
EXEC sp_OAMethod @jResp, 'IntOf', @size OUT, 'size'
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'results'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'StringOf', @templateId OUT, 'results[i].templateId'
EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'results[i].name'
EXEC sp_OAMethod @jResp, 'StringOf', @description OUT, 'results[i].description'
EXEC sp_OAMethod @jResp, 'StringOf', @templateType OUT, 'results[i].templateType'
EXEC sp_OAMethod @jResp, 'StringOf', @Body OUT, 'results[i]._expandable.body'
EXEC sp_OAMethod @jResp, 'StringOf', @Value OUT, 'results[i].body.value'
EXEC sp_OAMethod @jResp, 'StringOf', @Representation OUT, 'results[i].body.representation'
EXEC sp_OAMethod @jResp, 'StringOf', @Content OUT, 'results[i].body._expandable.content'
EXEC sp_OAMethod @jResp, 'StringOf', @AllValue OUT, 'results[i].body.webresource.uris.all.value'
EXEC sp_OAMethod @jResp, 'StringOf', @CssValue OUT, 'results[i].body.webresource.uris.css.value'
EXEC sp_OAMethod @jResp, 'StringOf', @JsValue OUT, 'results[i].body.webresource.uris.js.value'
EXEC sp_OAMethod @jResp, 'StringOf', @AllValue OUT, 'results[i].body.webresource.tags.all.value'
EXEC sp_OAMethod @jResp, 'StringOf', @CssValue OUT, 'results[i].body.webresource.tags.css.value'
EXEC sp_OAMethod @jResp, 'StringOf', @DataValue OUT, 'results[i].body.webresource.tags.data.value'
EXEC sp_OAMethod @jResp, 'StringOf', @JsValue OUT, 'results[i].body.webresource.tags.js.value'
EXEC sp_OAMethod @jResp, 'StringOf', @SuperbatchValue OUT, 'results[i].body.webresource.superbatch.value'
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'results[i].labels'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
EXEC sp_OAMethod @jResp, 'StringOf', @prefix OUT, 'results[i].labels[j].prefix'
EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'results[i].labels[j].name'
EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'results[i].labels[j].id'
EXEC sp_OAMethod @jResp, 'StringOf', @label OUT, 'results[i].labels[j].label'
SELECT @j = @j + 1
END
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'results[i].body.embeddedContent'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
EXEC sp_OAMethod @jResp, 'StringOf', @entityIdValue OUT, 'results[i].body.embeddedContent[j].entityId.value'
EXEC sp_OAMethod @jResp, 'StringOf', @entityValue OUT, 'results[i].body.embeddedContent[j].entity.value'
SELECT @j = @j + 1
END
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'results[i].body.webresource.keys'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
EXEC sp_OAMethod @jResp, 'StringOf', @value OUT, 'results[i].body.webresource.keys[j].value'
SELECT @j = @j + 1
END
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'results[i].body.webresource.contexts'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
EXEC sp_OAMethod @jResp, 'StringOf', @value OUT, 'results[i].body.webresource.contexts[j].value'
SELECT @j = @j + 1
END
SELECT @i = @i + 1
END
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @queryParams
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO
Curl Command
curl -G -d "spaceKey=%3Cstring%3E"
-d "start=0"
-d "limit=25"
-d "expand=%3Cstring%3E"
-d "expand=%3Cstring%3E"
-H "Authorization: Bearer <access_token>"
https://your-domain.atlassian.net/wiki/rest/api/template/page
Postman Collection Item JSON
{
"name": "Get content templates",
"request": {
"auth": {
"type": "oauth2"
},
"method": "GET",
"header": [
],
"url": {
"raw": "{{baseUrl}}/api/template/page?spaceKey=<string>&start=0&limit=25&expand=<string>&expand=<string>",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"template",
"page"
],
"query": [
{
"key": "spaceKey",
"value": "<string>",
"description": "The key of the space to be queried for templates. If the `spaceKey`\nis not specified, global templates will be returned."
},
{
"key": "start",
"value": "0",
"description": "The starting index of the returned templates."
},
{
"key": "limit",
"value": "25",
"description": "The maximum number of templates to return per page.\nNote, this may be restricted by fixed system limits."
},
{
"key": "expand",
"value": "<string>",
"description": "A multi-value parameter indicating which properties of the template\nto expand.\n\n- `body` returns the content of the template in storage format."
},
{
"key": "expand",
"value": "<string>",
"description": "A multi-value parameter indicating which properties of the template\nto expand.\n\n- `body` returns the content of the template in storage format."
}
]
},
"description": "Returns all content templates. Use this method to retrieve all global\ncontent templates or all content templates in a space.\n\n**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:\n'Admin' permission for the space to view space templates and 'Confluence\nAdministrator' global permission to view global templates."
},
"response": [
{
"name": "Returned if the requested templates are returned.",
"originalRequest": {
"method": "GET",
"header": [
{
"description": {
"content": "Added as a part of security scheme: oauth2",
"type": "text/plain"
},
"key": "Authorization",
"value": "<token>"
}
],
"url": {
"raw": "{{baseUrl}}/api/template/page?spaceKey=<string>&start=0&limit=25&expand=<string>&expand=<string>",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"template",
"page"
],
"query": [
{
"key": "spaceKey",
"value": "<string>"
},
{
"key": "start",
"value": "0"
},
{
"key": "limit",
"value": "25"
},
{
"key": "expand",
"value": "<string>"
},
{
"key": "expand",
"value": "<string>"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"results\": [\n {\n \"templateId\": \"pariatur adipisicing non Ut\",\n \"name\": \"enim ullamco officia eu\",\n \"description\": \"culpa\",\n \"labels\": [\n {\n \"prefix\": \"Ut id pariatur\",\n \"name\": \"amet ipsum reprehenderit\",\n \"id\": \"ipsum\",\n \"label\": \"do consectetur\"\n },\n {\n \"prefix\": \"irure elit\",\n \"name\": \"laboris cillum dolor pariatur aliquip\",\n \"id\": \"deserunt consectetur d\",\n \"label\": \"nisi ex\"\n }\n ],\n \"templateType\": \"sunt eu\",\n \"_expandable\": {\n \"body\": \"Excepteur velit aliquip\"\n },\n \"_links\": {},\n \"body\": {\n \"value\": \"sint dolor mollit\",\n \"representation\": \"view\",\n \"_expandable\": {\n \"content\": \"dolor\"\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 },\n {\n \"templateId\": \"qui officia aute\",\n \"name\": \"deserunt\",\n \"description\": \"velit laborum cupidatat anim\",\n \"labels\": [\n {\n \"prefix\": \"magna Ut\",\n \"name\": \"culpa quis Duis\",\n \"id\": \"et enim eiusmod quis\",\n \"label\": \"elit qui\"\n },\n {\n \"prefix\": \"eu proident\",\n \"name\": \"pariatur non\",\n \"id\": \"magna adipisicing ea amet sunt\",\n \"label\": \"qui\"\n }\n ],\n \"templateType\": \"nulla exercitation\",\n \"_expandable\": {\n \"body\": \"amet\"\n },\n \"_links\": {},\n \"body\": {\n \"value\": \"in ea consectetur\",\n \"representation\": \"storage\",\n \"_expandable\": {\n \"content\": \"aliquip magna eu do \"\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 }\n ],\n \"start\": -93900983,\n \"limit\": -84771492,\n \"size\": -63798652,\n \"_links\": {}\n}"
},
{
"name": "Returned if the calling user does not have permission to view the\ncontent templates.",
"originalRequest": {
"method": "GET",
"header": [
{
"description": {
"content": "Added as a part of security scheme: oauth2",
"type": "text/plain"
},
"key": "Authorization",
"value": "<token>"
}
],
"url": {
"raw": "{{baseUrl}}/api/template/page?spaceKey=<string>&start=0&limit=25&expand=<string>&expand=<string>",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"template",
"page"
],
"query": [
{
"key": "spaceKey",
"value": "<string>"
},
{
"key": "start",
"value": "0"
},
{
"key": "limit",
"value": "25"
},
{
"key": "expand",
"value": "<string>"
},
{
"key": "expand",
"value": "<string>"
}
]
}
},
"status": "Forbidden",
"code": 403,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/plain"
}
],
"cookie": [
],
"body": ""
}
]
}