Chilkat Online Tools

PowerBuilder / Atlassian Confluence Cloud / Check content permissions

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_Translation
integer j
integer li_Count_j
integer li_HasPermission
integer i
integer li_Count_i

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

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","<string>")

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

loo_Resp = loo_Http.PostJson3("https://your-domain.atlassian.net/wiki/rest/api/content/:id/permission/check","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)

// {
//   "hasPermission": true,
//   "errors": [
//     {
//       "translation": "anim ex commodo nulla quis",
//       "args": [
//       ]
//     },
//     {
//       "translation": "aute",
//       "args": [
//       ]
//     }
//   ]
// }

// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

li_HasPermission = loo_JResp.BoolOf("hasPermission")
i = 0
li_Count_i = loo_JResp.SizeOfArray("errors")
do while i < li_Count_i
    loo_JResp.I = i
    ls_Translation = loo_JResp.StringOf("errors[i].translation")
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("errors[i].args")
    do while j < li_Count_j
        loo_JResp.J = j
        j = j + 1
    loop
    i = i + 1
loop


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": "<string>"
}'
https://your-domain.atlassian.net/wiki/rest/api/content/:id/permission/check

Postman Collection Item JSON

{
  "name": "Check content permissions",
  "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\": \"<string>\"\n}"
    },
    "url": {
      "raw": "{{baseUrl}}/api/content/:id/permission/check",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "content",
        ":id",
        "permission",
        "check"
      ],
      "variable": [
        {
          "key": "id",
          "value": "<string>",
          "type": "string",
          "description": "(Required) The ID of the content to check permissions against."
        }
      ]
    },
    "description": "Check if a user or a group can perform an operation to the specified content. The `operation` to check\nmust be provided. The user’s account ID or the ID of the group can be provided in the `subject` to check\npermissions against a specified user or group. The following permission checks are done to make sure that the\nuser or group has the proper access:\n\n- site permissions\n- space permissions\n- content restrictions\n\n**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:\nPermission to access the Confluence site ('Can use' global permission) if checking permission for self,\notherwise 'Confluence Administrator' global permission is required."
  },
  "response": [
    {
      "name": "Returned if the permission check completed successfully",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"subject\": {\n        \"type\": \"<string>\",\n        \"identifier\": \"<string>\"\n    },\n    \"operation\": \"<string>\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/content/:id/permission/check",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "content",
            ":id",
            "permission",
            "check"
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"hasPermission\": true,\n \"errors\": [\n  {\n   \"translation\": \"anim ex commodo nulla quis\",\n   \"args\": []\n  },\n  {\n   \"translation\": \"aute\",\n   \"args\": []\n  }\n ]\n}"
    },
    {
      "name": "Returned if;\n\n- If any of the required fields are missing.\n- If specified `subject` or `operation` is invalid.",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"subject\": {\n        \"type\": \"<string>\",\n        \"identifier\": \"<string>\"\n    },\n    \"operation\": \"<string>\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/content/:id/permission/check",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "content",
            ":id",
            "permission",
            "check"
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "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\": \"<string>\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/content/:id/permission/check",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "content",
            ":id",
            "permission",
            "check"
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "name": "Returned if the user does not have permission perform the check.",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"subject\": {\n        \"type\": \"<string>\",\n        \"identifier\": \"<string>\"\n    },\n    \"operation\": \"<string>\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/content/:id/permission/check",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "content",
            ":id",
            "permission",
            "check"
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "name": "Returned if there is no content with the given ID.",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"subject\": {\n        \"type\": \"<string>\",\n        \"identifier\": \"<string>\"\n    },\n    \"operation\": \"<string>\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/content/:id/permission/check",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "content",
            ":id",
            "permission",
            "check"
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}