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.
-- {
-- "subject": {
-- "type": "<string>",
-- "identifier": "<string>"
-- },
-- "operation": {
-- "key": "<string>",
-- "target": "<string>"
-- },
-- "id": "<long>",
-- "_links": {}
-- }
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, 'subject.type', '<string>'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'subject.identifier', '<string>'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'operation.key', '<string>'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'operation.target', '<string>'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'id', '<long>'
EXEC sp_OAMethod @json, 'UpdateNewObject', @success OUT, '_links'
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/space/:spaceKey/permission', '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)
-- {
-- "subject": {
-- "type": "<string>",
-- "identifier": "<string>"
-- },
-- "operation": {
-- "key": "<string>",
-- "target": "<string>"
-- },
-- "id": "<long>",
-- "_links": {}
-- }
-- Sample code for parsing the JSON response...
-- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
DECLARE @v_Type nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @v_Type OUT, 'subject.type'
DECLARE @Identifier nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Identifier OUT, 'subject.identifier'
DECLARE @Key nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Key OUT, 'operation.key'
DECLARE @Target nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Target OUT, 'operation.target'
DECLARE @id nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'id'
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 "Content-Type: application/json"
-d '{
"subject": {
"type": "<string>",
"identifier": "<string>"
},
"operation": {
"key": "<string>",
"target": "<string>"
},
"id": "<long>",
"_links": {}
}'
https://your-domain.atlassian.net/wiki/rest/api/space/:spaceKey/permission
Postman Collection Item JSON
{
"name": "Add new permission to space",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"subject\": {\n \"type\": \"<string>\",\n \"identifier\": \"<string>\"\n },\n \"operation\": {\n \"key\": \"<string>\",\n \"target\": \"<string>\"\n },\n \"id\": \"<long>\",\n \"_links\": {}\n}"
},
"url": {
"raw": "{{baseUrl}}/api/space/:spaceKey/permission",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"space",
":spaceKey",
"permission"
],
"variable": [
{
"key": "spaceKey",
"value": "<string>",
"type": "string",
"description": "(Required) The key of the space to be queried for its content."
}
]
},
"description": "Adds new permission to space.\n\n**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:\n'Admin' permission for the space."
},
"response": [
{
"name": "Returned if the requested content is returned.",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"subject\": {\n \"type\": \"<string>\",\n \"identifier\": \"<string>\"\n },\n \"operation\": {\n \"key\": \"<string>\",\n \"target\": \"<string>\"\n },\n \"id\": \"<long>\",\n \"_links\": {}\n}"
},
"url": {
"raw": "{{baseUrl}}/api/space/:spaceKey/permission",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"space",
":spaceKey",
"permission"
],
"variable": [
{
"key": "spaceKey"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"subject\": {\n \"type\": \"<string>\",\n \"identifier\": \"<string>\"\n },\n \"operation\": {\n \"key\": \"<string>\",\n \"target\": \"<string>\"\n },\n \"id\": \"<long>\",\n \"_links\": {}\n}"
},
{
"name": "Used for various errors. Such as:\n- Permission already exists for the given user or group.\n- 'read space' permission doesn't exist for the given user or group.\n- No group found with the given groupName",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"subject\": {\n \"type\": \"<string>\",\n \"identifier\": \"<string>\"\n },\n \"operation\": {\n \"key\": \"<string>\",\n \"target\": \"<string>\"\n },\n \"id\": \"<long>\",\n \"_links\": {}\n}"
},
"url": {
"raw": "{{baseUrl}}/api/space/:spaceKey/permission",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"space",
":spaceKey",
"permission"
],
"variable": [
{
"key": "spaceKey"
}
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/plain"
}
],
"cookie": [
],
"body": ""
},
{
"name": "Returned if the authentication credentials are incorrect or missing\nfrom the request.",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"subject\": {\n \"type\": \"<string>\",\n \"identifier\": \"<string>\"\n },\n \"operation\": {\n \"key\": \"<string>\",\n \"target\": \"<string>\"\n },\n \"id\": \"<long>\",\n \"_links\": {}\n}"
},
"url": {
"raw": "{{baseUrl}}/api/space/:spaceKey/permission",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"space",
":spaceKey",
"permission"
],
"variable": [
{
"key": "spaceKey"
}
]
}
},
"status": "Unauthorized",
"code": 401,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/plain"
}
],
"cookie": [
],
"body": ""
},
{
"name": "Returned if the user isn't authorized.",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"subject\": {\n \"type\": \"<string>\",\n \"identifier\": \"<string>\"\n },\n \"operation\": {\n \"key\": \"<string>\",\n \"target\": \"<string>\"\n },\n \"id\": \"<long>\",\n \"_links\": {}\n}"
},
"url": {
"raw": "{{baseUrl}}/api/space/:spaceKey/permission",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"space",
":spaceKey",
"permission"
],
"variable": [
{
"key": "spaceKey"
}
]
}
},
"status": "Forbidden",
"code": 403,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/plain"
}
],
"cookie": [
],
"body": ""
},
{
"name": "Returned if any of the following is true:\n- There is no space with the given key.\n- The calling user does not have permission to view the space.",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"subject\": {\n \"type\": \"<string>\",\n \"identifier\": \"<string>\"\n },\n \"operation\": {\n \"key\": \"<string>\",\n \"target\": \"<string>\"\n },\n \"id\": \"<long>\",\n \"_links\": {}\n}"
},
"url": {
"raw": "{{baseUrl}}/api/space/:spaceKey/permission",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"space",
":spaceKey",
"permission"
],
"variable": [
{
"key": "spaceKey"
}
]
}
},
"status": "Not Found",
"code": 404,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/plain"
}
],
"cookie": [
],
"body": ""
}
]
}