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
DECLARE @queryParams int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @queryParams OUT
EXEC sp_OAMethod @queryParams, 'UpdateInt', @success OUT, 'start', 0
EXEC sp_OAMethod @queryParams, 'UpdateInt', @success OUT, 'limit', 100
DECLARE @resp int
EXEC sp_OAMethod @http, 'QuickRequestParams', @resp OUT, 'GET', 'https://your-domain.atlassian.net/wiki/rest/api/longtask', @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
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody
DECLARE @jResp int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.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": [
-- {
-- "id": "irure laborum reprehenderit",
-- "name": {
-- "key": "ea fugiat"
-- },
-- "elapsedTime": -80970955,
-- "percentageComplete": -50700695,
-- "successful": false,
-- "messages": [
-- {
-- "translation": "laboris dolore est pariatur"
-- },
-- {
-- "translation": "ut consectetur"
-- }
-- ]
-- },
-- {
-- "id": "exercitation quis occaecat pariatur",
-- "name": {
-- "key": "ipsum enim consectetur laborum ea"
-- },
-- "elapsedTime": 68022774,
-- "percentageComplete": -46095628,
-- "successful": true,
-- "messages": [
-- {
-- "translation": "ullamco officia Lorem occaecat"
-- },
-- {
-- "translation": "aliquip de"
-- }
-- ]
-- }
-- ],
-- "start": 73270285,
-- "limit": -69580683,
-- "size": 69587096,
-- "_links": {}
-- }
-- Sample code for parsing the JSON response...
-- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
DECLARE @id nvarchar(4000)
DECLARE @Key nvarchar(4000)
DECLARE @elapsedTime int
DECLARE @percentageComplete int
DECLARE @successful int
DECLARE @j int
DECLARE @count_j int
DECLARE @translation 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', @id OUT, 'results[i].id'
EXEC sp_OAMethod @jResp, 'StringOf', @Key OUT, 'results[i].name.key'
EXEC sp_OAMethod @jResp, 'IntOf', @elapsedTime OUT, 'results[i].elapsedTime'
EXEC sp_OAMethod @jResp, 'IntOf', @percentageComplete OUT, 'results[i].percentageComplete'
EXEC sp_OAMethod @jResp, 'BoolOf', @successful OUT, 'results[i].successful'
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'results[i].messages'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
EXEC sp_OAMethod @jResp, 'StringOf', @translation OUT, 'results[i].messages[j].translation'
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 "start=0"
-d "limit=100"
https://your-domain.atlassian.net/wiki/rest/api/longtask
Postman Collection Item JSON
{
"name": "Get long-running tasks",
"request": {
"method": "GET",
"header": [
],
"url": {
"raw": "{{baseUrl}}/api/longtask?start=0&limit=100",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"longtask"
],
"query": [
{
"key": "start",
"value": "0",
"description": "The starting index of the returned tasks."
},
{
"key": "limit",
"value": "100",
"description": "The maximum number of tasks to return per page. Note, this may be\nrestricted by fixed system limits."
}
]
},
"description": "Returns information about all active long-running tasks (e.g. space export),\nsuch as how long each task has been running and the percentage of each task\nthat has completed.\n\n**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:\nPermission to access the Confluence site ('Can use' global permission)."
},
"response": [
{
"name": "Returned if the requested tasks are returned.",
"originalRequest": {
"method": "GET",
"header": [
],
"url": {
"raw": "{{baseUrl}}/api/longtask?start=0&limit=100",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"longtask"
],
"query": [
{
"key": "start",
"value": "0"
},
{
"key": "limit",
"value": "100"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"results\": [\n {\n \"id\": \"irure laborum reprehenderit\",\n \"name\": {\n \"key\": \"ea fugiat\"\n },\n \"elapsedTime\": -80970955,\n \"percentageComplete\": -50700695,\n \"successful\": false,\n \"messages\": [\n {\n \"translation\": \"laboris dolore est pariatur\"\n },\n {\n \"translation\": \"ut consectetur\"\n }\n ]\n },\n {\n \"id\": \"exercitation quis occaecat pariatur\",\n \"name\": {\n \"key\": \"ipsum enim consectetur laborum ea\"\n },\n \"elapsedTime\": 68022774,\n \"percentageComplete\": -46095628,\n \"successful\": true,\n \"messages\": [\n {\n \"translation\": \"ullamco officia Lorem occaecat\"\n },\n {\n \"translation\": \"aliquip de\"\n }\n ]\n }\n ],\n \"start\": 73270285,\n \"limit\": -69580683,\n \"size\": 69587096,\n \"_links\": {}\n}"
},
{
"name": "Returned if the calling user is not logged in to Confluence.",
"originalRequest": {
"method": "GET",
"header": [
],
"url": {
"raw": "{{baseUrl}}/api/longtask?start=0&limit=100",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"longtask"
],
"query": [
{
"key": "start",
"value": "0"
},
{
"key": "limit",
"value": "100"
}
]
}
},
"status": "Unauthorized",
"code": 401,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/plain"
}
],
"cookie": [
],
"body": ""
}
]
}