Chilkat Online Tools

PowerBuilder / Atlassian Confluence Cloud / Add new permission to space

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_V_Type
string ls_Identifier
string ls_Key
string ls_Target
string ls_Id

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// 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": {}
// }

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_Json.UpdateString("subject.type","<string>")
loo_Json.UpdateString("subject.identifier","<string>")
loo_Json.UpdateString("operation.key","<string>")
loo_Json.UpdateString("operation.target","<string>")
loo_Json.UpdateString("id","<long>")
loo_Json.UpdateNewObject("_links")

loo_Http.SetRequestHeader("Content-Type","application/json")

loo_Resp = loo_Http.PostJson3("https://your-domain.atlassian.net/wiki/rest/api/space/:spaceKey/permission","application/json",loo_Json)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Json
    return
end if

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_Resp.GetBodySb(loo_SbResponseBody)

loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Resp.Header
    Write-Debug "Failed."
    destroy loo_Resp
    destroy loo_Http
    destroy loo_Json
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

destroy loo_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

ls_V_Type = loo_JResp.StringOf("subject.type")
ls_Identifier = loo_JResp.StringOf("subject.identifier")
ls_Key = loo_JResp.StringOf("operation.key")
ls_Target = loo_JResp.StringOf("operation.target")
ls_Id = loo_JResp.StringOf("id")


destroy loo_Http
destroy loo_Json
destroy loo_SbResponseBody
destroy loo_JResp

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": ""
    }
  ]
}