Chilkat Online Tools

C++ / Atlassian Confluence Cloud / Check content permissions

Back to Collection Items

#include <CkHttp.h>
#include <CkJsonObject.h>
#include <CkHttpResponse.h>
#include <CkStringBuilder.h>

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

    CkHttp http;
    bool success;

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

    CkJsonObject json;
    json.UpdateString("subject.type","<string>");
    json.UpdateString("subject.identifier","<string>");
    json.UpdateString("operation","<string>");

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

    CkHttpResponse *resp = http.PostJson3("https://your-domain.atlassian.net/wiki/rest/api/content/:id/permission/check","application/json",json);
    if (http.get_LastMethodSuccess() == false) {
        std::cout << http.lastErrorText() << "\r\n";
        return;
    }

    CkStringBuilder sbResponseBody;
    resp->GetBodySb(sbResponseBody);

    CkJsonObject jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    std::cout << "Response Body:" << "\r\n";
    std::cout << jResp.emit() << "\r\n";

    int respStatusCode = resp->get_StatusCode();
    std::cout << "Response Status Code = " << respStatusCode << "\r\n";
    if (respStatusCode >= 400) {
        std::cout << "Response Header:" << "\r\n";
        std::cout << resp->header() << "\r\n";
        std::cout << "Failed." << "\r\n";
        delete resp;
        return;
    }

    delete 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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    const char *translation = 0;
    int j;
    int count_j;

    bool hasPermission = jResp.BoolOf("hasPermission");
    int i = 0;
    int count_i = jResp.SizeOfArray("errors");
    while (i < count_i) {
        jResp.put_I(i);
        translation = jResp.stringOf("errors[i].translation");
        j = 0;
        count_j = jResp.SizeOfArray("errors[i].args");
        while (j < count_j) {
            jResp.put_J(j);
            j = j + 1;
        }

        i = i + 1;
    }
    }

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