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.
-- [
-- {
-- "prefix": "<string>",
-- "name": "<string>"
-- },
-- {
-- "prefix": "<string>",
-- "name": "<string>"
-- }
-- ]
DECLARE @jarr int
-- Use "Chilkat_9_5_0.JsonArray" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonArray', @jarr OUT
EXEC sp_OAMethod @jarr, 'AddObjectAt', @success OUT, -1
DECLARE @jsonObj_1 int
EXEC sp_OAGetProperty @jarr, 'Size', @iTmp0 OUT
EXEC sp_OAMethod @jarr, 'ObjectAt', @jsonObj_1 OUT, @iTmp0 - 1
EXEC sp_OAMethod @jsonObj_1, 'UpdateString', @success OUT, 'prefix', '<string>'
EXEC sp_OAMethod @jsonObj_1, 'UpdateString', @success OUT, 'name', '<string>'
EXEC @hr = sp_OADestroy @jsonObj_1
EXEC sp_OAMethod @jarr, 'AddObjectAt', @success OUT, -1
EXEC sp_OAGetProperty @jarr, 'Size', @iTmp0 OUT
EXEC sp_OAMethod @jarr, 'ObjectAt', @jsonObj_1 OUT, @iTmp0 - 1
EXEC sp_OAMethod @jsonObj_1, 'UpdateString', @success OUT, 'prefix', '<string>'
EXEC sp_OAMethod @jsonObj_1, 'UpdateString', @success OUT, 'name', '<string>'
EXEC @hr = sp_OADestroy @jsonObj_1
-- 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 @jarr, 'EmitSb', @success OUT, @sbRequestBody
DECLARE @resp int
EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'POST', 'https://your-domain.atlassian.net/wiki/rest/api/content/:id/label', @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 @jarr
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 @jarr
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)
-- {
-- "results": [
-- {
-- "prefix": "Duis elit dolor officia",
-- "name": "non sunt",
-- "id": "nulla veniam",
-- "label": "deserunt Ut Excepteur magna"
-- },
-- {
-- "prefix": "in consequat deserun",
-- "name": "officia cillum enim",
-- "id": "Lorem quis esse amet",
-- "label": "dolore esse"
-- }
-- ],
-- "start": -32316568,
-- "limit": -3993073,
-- "size": -78086889,
-- "_links": {}
-- }
-- 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 @name nvarchar(4000)
DECLARE @id nvarchar(4000)
DECLARE @label 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', @prefix OUT, 'results[i].prefix'
EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'results[i].name'
EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'results[i].id'
EXEC sp_OAMethod @jResp, 'StringOf', @label OUT, 'results[i].label'
SELECT @i = @i + 1
END
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @jarr
EXEC @hr = sp_OADestroy @sbRequestBody
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 '[
{
"prefix": "<string>",
"name": "<string>"
},
{
"prefix": "<string>",
"name": "<string>"
}
]'
https://your-domain.atlassian.net/wiki/rest/api/content/:id/label
Postman Collection Item JSON
{
"name": "Add labels to content",
"request": {
"auth": {
"type": "oauth2"
},
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "[\n {\n \"prefix\": \"<string>\",\n \"name\": \"<string>\"\n },\n {\n \"prefix\": \"<string>\",\n \"name\": \"<string>\"\n }\n]"
},
"url": {
"raw": "{{baseUrl}}/api/content/:id/label",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"content",
":id",
"label"
],
"variable": [
{
"key": "id",
"value": "<string>",
"type": "string",
"description": "(Required) The ID of the content that will have labels added to it."
}
]
},
"description": "Adds labels to a piece of content. Does not modify the existing labels.\n\nNotes:\n\n- Labels can also be added when creating content ([Create content](#api-content-post)).\n- Labels can be updated when updating content ([Update content](#api-content-id-put)).\nThis will delete the existing labels and replace them with the labels in\nthe request.\n\n**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:\nPermission to update the content."
},
"response": [
{
"name": "Returned if the labels are added to the content.",
"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 {\n \"prefix\": \"<string>\",\n \"name\": \"<string>\"\n },\n {\n \"prefix\": \"<string>\",\n \"name\": \"<string>\"\n }\n]"
},
"url": {
"raw": "{{baseUrl}}/api/content/:id/label",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"content",
":id",
"label"
],
"variable": [
{
"key": "id"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"results\": [\n {\n \"prefix\": \"Duis elit dolor officia\",\n \"name\": \"non sunt\",\n \"id\": \"nulla veniam\",\n \"label\": \"deserunt Ut Excepteur magna\"\n },\n {\n \"prefix\": \"in consequat deserun\",\n \"name\": \"officia cillum enim\",\n \"id\": \"Lorem quis esse amet\",\n \"label\": \"dolore esse\"\n }\n ],\n \"start\": -32316568,\n \"limit\": -3993073,\n \"size\": -78086889,\n \"_links\": {}\n}"
},
{
"name": "Returned if;\n\n- There is no content with the given ID.\n- The calling user does not have permission to view the content.",
"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 {\n \"prefix\": \"<string>\",\n \"name\": \"<string>\"\n },\n {\n \"prefix\": \"<string>\",\n \"name\": \"<string>\"\n }\n]"
},
"url": {
"raw": "{{baseUrl}}/api/content/:id/label",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"content",
":id",
"label"
],
"variable": [
{
"key": "id"
}
]
}
},
"status": "Not Found",
"code": 404,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/plain"
}
],
"cookie": [
],
"body": ""
}
]
}