Chilkat Online Tools

PureBasic / Atlassian Confluence Cloud / Get restrictions

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    queryParams.i = CkJsonObject::ckCreate()
    If queryParams.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(queryParams,"expand","<string>")
    CkJsonObject::ckUpdateString(queryParams,"expand","<string>")
    CkJsonObject::ckUpdateInt(queryParams,"start",0)
    CkJsonObject::ckUpdateInt(queryParams,"limit",100)

    ; Adds the "Authorization: Bearer <access_token>" header.
    CkHttp::setCkAuthToken(http, "<access_token>")

    resp.i = CkHttp::ckQuickRequestParams(http,"GET","https://your-domain.atlassian.net/wiki/rest/api/content/:id/restriction",queryParams)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(queryParams)
        ProcedureReturn
    EndIf

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkHttpResponse::ckGetBodySb(resp,sbResponseBody)

    jResp.i = CkJsonObject::ckCreate()
    If jResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jResp,sbResponseBody)
    CkJsonObject::setCkEmitCompact(jResp, 0)

    Debug "Response Body:"
    Debug CkJsonObject::ckEmit(jResp)

    respStatusCode.i = CkHttpResponse::ckStatusCode(resp)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttpResponse::ckHeader(resp)
        Debug "Failed."
        CkHttpResponse::ckDispose(resp)

        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(queryParams)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

    CkHttpResponse::ckDispose(resp)

    ; Sample JSON response:
    ; (Sample code for parsing the JSON response is shown below)

    ; {
    ;   "results": [
    ;     {
    ;       "operation": "copy",
    ;       "_expandable": {
    ;         "restrictions": "incididunt anim ut id nulla",
    ;         "content": "cupidatat"
    ;       },
    ;       "_links": {},
    ;       "restrictions": {
    ;         "user": {
    ;           "results": {
    ;             "value": "<Error: Too many levels of nesting to fake this schema>"
    ;           },
    ;           "start": {
    ;             "value": "<Error: Too many levels of nesting to fake this schema>"
    ;           },
    ;           "limit": {
    ;             "value": "<Error: Too many levels of nesting to fake this schema>"
    ;           },
    ;           "size": {
    ;             "value": "<Error: Too many levels of nesting to fake this schema>"
    ;           }
    ;         },
    ;         "group": {
    ;           "results": {
    ;             "value": "<Error: Too many levels of nesting to fake this schema>"
    ;           },
    ;           "start": {
    ;             "value": "<Error: Too many levels of nesting to fake this schema>"
    ;           },
    ;           "limit": {
    ;             "value": "<Error: Too many levels of nesting to fake this schema>"
    ;           },
    ;           "size": {
    ;             "value": "<Error: Too many levels of nesting to fake this schema>"
    ;           }
    ;         },
    ;         "_expandable": {
    ;           "user": "et laborum",
    ;           "group": "qui consequat"
    ;         }
    ;       },
    ;       "content": {
    ;         "value": "<Circular reference to #/components/schemas/Content detected>"
    ;       }
    ;     },
    ;     {
    ;       "operation": "copy",
    ;       "_expandable": {
    ;         "restrictions": "ullamco velit Lorem",
    ;         "content": "culpa esse sit anim aliqua"
    ;       },
    ;       "_links": {},
    ;       "restrictions": {
    ;         "user": {
    ;           "results": {
    ;             "value": "<Error: Too many levels of nesting to fake this schema>"
    ;           },
    ;           "start": {
    ;             "value": "<Error: Too many levels of nesting to fake this schema>"
    ;           },
    ;           "limit": {
    ;             "value": "<Error: Too many levels of nesting to fake this schema>"
    ;           },
    ;           "size": {
    ;             "value": "<Error: Too many levels of nesting to fake this schema>"
    ;           }
    ;         },
    ;         "group": {
    ;           "results": {
    ;             "value": "<Error: Too many levels of nesting to fake this schema>"
    ;           },
    ;           "start": {
    ;             "value": "<Error: Too many levels of nesting to fake this schema>"
    ;           },
    ;           "limit": {
    ;             "value": "<Error: Too many levels of nesting to fake this schema>"
    ;           },
    ;           "size": {
    ;             "value": "<Error: Too many levels of nesting to fake this schema>"
    ;           }
    ;         },
    ;         "_expandable": {
    ;           "user": "ut",
    ;           "group": "ad Ut"
    ;         }
    ;       },
    ;       "content": {
    ;         "value": "<Circular reference to #/components/schemas/Content detected>"
    ;       }
    ;     }
    ;   ],
    ;   "start": 8238998,
    ;   "limit": -43753388,
    ;   "size": -64805454,
    ;   "restrictionsHash": "ut commodo",
    ;   "_links": {}
    ; }

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

    operation.s
    Restrictions.s
    Content.s
    Value.s
    StartValue.s
    LimitValue.s
    SizeValue.s
    ResultsValue.s
    User.s
    Group.s
    contentValue.s

    start.i = CkJsonObject::ckIntOf(jResp,"start")
    limit.i = CkJsonObject::ckIntOf(jResp,"limit")
    size.i = CkJsonObject::ckIntOf(jResp,"size")
    restrictionsHash.s = CkJsonObject::ckStringOf(jResp,"restrictionsHash")
    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"results")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        operation = CkJsonObject::ckStringOf(jResp,"results[i].operation")
        Restrictions = CkJsonObject::ckStringOf(jResp,"results[i]._expandable.restrictions")
        Content = CkJsonObject::ckStringOf(jResp,"results[i]._expandable.content")
        Value = CkJsonObject::ckStringOf(jResp,"results[i].restrictions.user.results.value")
        StartValue = CkJsonObject::ckStringOf(jResp,"results[i].restrictions.user.start.value")
        LimitValue = CkJsonObject::ckStringOf(jResp,"results[i].restrictions.user.limit.value")
        SizeValue = CkJsonObject::ckStringOf(jResp,"results[i].restrictions.user.size.value")
        ResultsValue = CkJsonObject::ckStringOf(jResp,"results[i].restrictions.group.results.value")
        StartValue = CkJsonObject::ckStringOf(jResp,"results[i].restrictions.group.start.value")
        LimitValue = CkJsonObject::ckStringOf(jResp,"results[i].restrictions.group.limit.value")
        SizeValue = CkJsonObject::ckStringOf(jResp,"results[i].restrictions.group.size.value")
        User = CkJsonObject::ckStringOf(jResp,"results[i].restrictions._expandable.user")
        Group = CkJsonObject::ckStringOf(jResp,"results[i].restrictions._expandable.group")
        contentValue = CkJsonObject::ckStringOf(jResp,"results[i].content.value")
        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(queryParams)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure

Curl Command

curl -G -d "expand=%3Cstring%3E"
	-d "expand=%3Cstring%3E"
	-d "start=0"
	-d "limit=100"
	-H "Authorization: Bearer <access_token>"
https://your-domain.atlassian.net/wiki/rest/api/content/:id/restriction

Postman Collection Item JSON

{
  "name": "Get restrictions",
  "request": {
    "auth": {
      "type": "oauth2"
    },
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{baseUrl}}/api/content/:id/restriction?expand=<string>&expand=<string>&start=0&limit=100",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "content",
        ":id",
        "restriction"
      ],
      "query": [
        {
          "key": "expand",
          "value": "<string>",
          "description": "A multi-value parameter indicating which properties of the content\nrestrictions to expand. By default, the following objects are expanded:\n`restrictions.user`, `restrictions.group`.\n\n- `restrictions.user` returns the piece of content that the restrictions are\napplied to.\n- `restrictions.group` returns the piece of content that the restrictions are\napplied to.\n- `content` returns the piece of content that the restrictions are\napplied to."
        },
        {
          "key": "expand",
          "value": "<string>",
          "description": "A multi-value parameter indicating which properties of the content\nrestrictions to expand. By default, the following objects are expanded:\n`restrictions.user`, `restrictions.group`.\n\n- `restrictions.user` returns the piece of content that the restrictions are\napplied to.\n- `restrictions.group` returns the piece of content that the restrictions are\napplied to.\n- `content` returns the piece of content that the restrictions are\napplied to."
        },
        {
          "key": "start",
          "value": "0",
          "description": "The starting index of the users and groups in the returned restrictions."
        },
        {
          "key": "limit",
          "value": "100",
          "description": "The maximum number of users and the maximum number of groups, in the\nreturned restrictions, to return per page. Note, this may be restricted\nby fixed system limits."
        }
      ],
      "variable": [
        {
          "key": "id",
          "value": "<string>",
          "type": "string",
          "description": "(Required) The ID of the content to be queried for its restrictions."
        }
      ]
    },
    "description": "Returns the restrictions on a piece of content.\n\n**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:\nPermission to view the content."
  },
  "response": [
    {
      "name": "Returned if the requested restrictions are returned.",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: oauth2",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/content/:id/restriction?expand=<string>&expand=<string>&start=0&limit=100",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "content",
            ":id",
            "restriction"
          ],
          "query": [
            {
              "key": "expand",
              "value": "<string>"
            },
            {
              "key": "expand",
              "value": "<string>"
            },
            {
              "key": "start",
              "value": "0"
            },
            {
              "key": "limit",
              "value": "100"
            }
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"results\": [\n  {\n   \"operation\": \"copy\",\n   \"_expandable\": {\n    \"restrictions\": \"incididunt anim ut id nulla\",\n    \"content\": \"cupidatat\"\n   },\n   \"_links\": {},\n   \"restrictions\": {\n    \"user\": {\n     \"results\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     },\n     \"start\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     },\n     \"limit\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     },\n     \"size\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     }\n    },\n    \"group\": {\n     \"results\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     },\n     \"start\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     },\n     \"limit\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     },\n     \"size\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     }\n    },\n    \"_expandable\": {\n     \"user\": \"et laborum\",\n     \"group\": \"qui consequat\"\n    }\n   },\n   \"content\": {\n    \"value\": \"<Circular reference to #/components/schemas/Content detected>\"\n   }\n  },\n  {\n   \"operation\": \"copy\",\n   \"_expandable\": {\n    \"restrictions\": \"ullamco velit Lorem\",\n    \"content\": \"culpa esse sit anim aliqua\"\n   },\n   \"_links\": {},\n   \"restrictions\": {\n    \"user\": {\n     \"results\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     },\n     \"start\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     },\n     \"limit\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     },\n     \"size\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     }\n    },\n    \"group\": {\n     \"results\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     },\n     \"start\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     },\n     \"limit\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     },\n     \"size\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n     }\n    },\n    \"_expandable\": {\n     \"user\": \"ut\",\n     \"group\": \"ad Ut\"\n    }\n   },\n   \"content\": {\n    \"value\": \"<Circular reference to #/components/schemas/Content detected>\"\n   }\n  }\n ],\n \"start\": 8238998,\n \"limit\": -43753388,\n \"size\": -64805454,\n \"restrictionsHash\": \"ut commodo\",\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": "GET",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: oauth2",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/content/:id/restriction?expand=<string>&expand=<string>&start=0&limit=100",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "content",
            ":id",
            "restriction"
          ],
          "query": [
            {
              "key": "expand",
              "value": "<string>"
            },
            {
              "key": "expand",
              "value": "<string>"
            },
            {
              "key": "start",
              "value": "0"
            },
            {
              "key": "limit",
              "value": "100"
            }
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}