Chilkat Online Tools

Foxpro / Atlassian Confluence Cloud / Add restrictions

Back to Collection Items

LOCAL loHttp
LOCAL lnSuccess
LOCAL loJarr
LOCAL loJsonObj_1
LOCAL loSbRequestBody
LOCAL loResp
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcOperation
LOCAL lcRestrictions
LOCAL lcContent
LOCAL lcValue
LOCAL lcStartValue
LOCAL lcLimitValue
LOCAL lcSizeValue
LOCAL lcResultsValue
LOCAL lcUser
LOCAL lcGroup
LOCAL lcContentValue
LOCAL lnStart
LOCAL lnLimit
LOCAL lnSize
LOCAL lcRestrictionsHash
LOCAL i
LOCAL lnCount_i

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

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http')
loHttp = CreateObject('Chilkat.Http')

* Use this online tool to generate code from sample JSON: Generate Code to Create JSON

* The following JSON is sent in the request body.

* [
*   {
*     "operation": "<string>",
*     "restrictions": {
*       "user": [
*         {
*           "type": "<string>",
*           "accountId": "<string>",
*           "username": "<string>",
*           "userKey": "<string>"
*         },
*         {
*           "type": "<string>",
*           "accountId": "<string>",
*           "username": "<string>",
*           "userKey": "<string>"
*         }
*       ],
*       "group": [
*         {
*           "type": "<string>",
*           "name": "<string>"
*         },
*         {
*           "type": "<string>",
*           "name": "<string>"
*         }
*       ]
*     }
*   },
*   {
*     "operation": "<string>",
*     "restrictions": {
*       "user": [
*         {
*           "type": "<string>",
*           "accountId": "<string>",
*           "username": "<string>",
*           "userKey": "<string>"
*         },
*         {
*           "type": "<string>",
*           "accountId": "<string>",
*           "username": "<string>",
*           "userKey": "<string>"
*         }
*       ],
*       "group": [
*         {
*           "type": "<string>",
*           "name": "<string>"
*         },
*         {
*           "type": "<string>",
*           "name": "<string>"
*         }
*       ]
*     }
*   }
* ]

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonArray')
loJarr = CreateObject('Chilkat.JsonArray')

loJarr.AddObjectAt(-1)
loJsonObj_1 = loJarr.ObjectAt(loJarr.Size - 1)
loJsonObj_1.UpdateString("operation","<string>")
loJsonObj_1.UpdateString("restrictions.user[0].type","<string>")
loJsonObj_1.UpdateString("restrictions.user[0].accountId","<string>")
loJsonObj_1.UpdateString("restrictions.user[0].username","<string>")
loJsonObj_1.UpdateString("restrictions.user[0].userKey","<string>")
loJsonObj_1.UpdateString("restrictions.user[1].type","<string>")
loJsonObj_1.UpdateString("restrictions.user[1].accountId","<string>")
loJsonObj_1.UpdateString("restrictions.user[1].username","<string>")
loJsonObj_1.UpdateString("restrictions.user[1].userKey","<string>")
loJsonObj_1.UpdateString("restrictions.group[0].type","<string>")
loJsonObj_1.UpdateString("restrictions.group[0].name","<string>")
loJsonObj_1.UpdateString("restrictions.group[1].type","<string>")
loJsonObj_1.UpdateString("restrictions.group[1].name","<string>")
RELEASE loJsonObj_1

loJarr.AddObjectAt(-1)
loJsonObj_1 = loJarr.ObjectAt(loJarr.Size - 1)
loJsonObj_1.UpdateString("operation","<string>")
loJsonObj_1.UpdateString("restrictions.user[0].type","<string>")
loJsonObj_1.UpdateString("restrictions.user[0].accountId","<string>")
loJsonObj_1.UpdateString("restrictions.user[0].username","<string>")
loJsonObj_1.UpdateString("restrictions.user[0].userKey","<string>")
loJsonObj_1.UpdateString("restrictions.user[1].type","<string>")
loJsonObj_1.UpdateString("restrictions.user[1].accountId","<string>")
loJsonObj_1.UpdateString("restrictions.user[1].username","<string>")
loJsonObj_1.UpdateString("restrictions.user[1].userKey","<string>")
loJsonObj_1.UpdateString("restrictions.group[0].type","<string>")
loJsonObj_1.UpdateString("restrictions.group[0].name","<string>")
loJsonObj_1.UpdateString("restrictions.group[1].type","<string>")
loJsonObj_1.UpdateString("restrictions.group[1].name","<string>")
RELEASE loJsonObj_1

* Adds the "Authorization: Bearer <access_token>" header.
loHttp.AuthToken = "<access_token>"
loHttp.SetRequestHeader("Content-Type","application/json")

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder')
loSbRequestBody = CreateObject('Chilkat.StringBuilder')
loJarr.EmitSb(loSbRequestBody)

loResp = loHttp.PTextSb("POST","https://your-domain.atlassian.net/wiki/rest/api/content/:id/restriction?expand=<string>&expand=<string>",loSbRequestBody,"utf-8","application/json",0,0)
IF (loHttp.LastMethodSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loJarr
    RELEASE loSbRequestBody
    CANCEL
ENDIF

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder')
loSbResponseBody = CreateObject('Chilkat.StringBuilder')
loResp.GetBodySb(loSbResponseBody)

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJResp = CreateObject('Chilkat.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0

? "Response Body:"
? loJResp.Emit()

lnRespStatusCode = loResp.StatusCode
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
    ? "Response Header:"
    ? loResp.Header
    ? "Failed."
    RELEASE loResp
    RELEASE loHttp
    RELEASE loJarr
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    RELEASE loJResp
    CANCEL
ENDIF

RELEASE loResp

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

* {
*   "results": [
*     {
*       "operation": "purge",
*       "_expandable": {
*         "restrictions": "Excepteur dolore Ut labore",
*         "content": "tempor esse officia"
*       },
*       "_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": "in in mollit Ut occaecat",
*           "group": "irure qui consectetur incididunt"
*         }
*       },
*       "content": {
*         "value": "<Circular reference to #/components/schemas/Content detected>"
*       }
*     },
*     {
*       "operation": "delete",
*       "_expandable": {
*         "restrictions": "nisi id",
*         "content": "ut in mollit enim"
*       },
*       "_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": "est voluptate",
*           "group": "in"
*         }
*       },
*       "content": {
*         "value": "<Circular reference to #/components/schemas/Content detected>"
*       }
*     }
*   ],
*   "start": 17789838,
*   "limit": 13313455,
*   "size": -47874490,
*   "restrictionsHash": "Lorem commodo pariatur Ut eiusmod",
*   "_links": {}
* }

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

lnStart = loJResp.IntOf("start")
lnLimit = loJResp.IntOf("limit")
lnSize = loJResp.IntOf("size")
lcRestrictionsHash = loJResp.StringOf("restrictionsHash")
i = 0
lnCount_i = loJResp.SizeOfArray("results")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcOperation = loJResp.StringOf("results[i].operation")
    lcRestrictions = loJResp.StringOf("results[i]._expandable.restrictions")
    lcContent = loJResp.StringOf("results[i]._expandable.content")
    lcValue = loJResp.StringOf("results[i].restrictions.user.results.value")
    lcStartValue = loJResp.StringOf("results[i].restrictions.user.start.value")
    lcLimitValue = loJResp.StringOf("results[i].restrictions.user.limit.value")
    lcSizeValue = loJResp.StringOf("results[i].restrictions.user.size.value")
    lcResultsValue = loJResp.StringOf("results[i].restrictions.group.results.value")
    lcStartValue = loJResp.StringOf("results[i].restrictions.group.start.value")
    lcLimitValue = loJResp.StringOf("results[i].restrictions.group.limit.value")
    lcSizeValue = loJResp.StringOf("results[i].restrictions.group.size.value")
    lcUser = loJResp.StringOf("results[i].restrictions._expandable.user")
    lcGroup = loJResp.StringOf("results[i].restrictions._expandable.group")
    lcContentValue = loJResp.StringOf("results[i].content.value")
    i = i + 1
ENDDO

RELEASE loHttp
RELEASE loJarr
RELEASE loSbRequestBody
RELEASE loSbResponseBody
RELEASE loJResp

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-d '[
    {
        "operation": "<string>",
        "restrictions": {
            "user": [
                {
                    "type": "<string>",
                    "accountId": "<string>",
                    "username": "<string>",
                    "userKey": "<string>"
                },
                {
                    "type": "<string>",
                    "accountId": "<string>",
                    "username": "<string>",
                    "userKey": "<string>"
                }
            ],
            "group": [
                {
                    "type": "<string>",
                    "name": "<string>"
                },
                {
                    "type": "<string>",
                    "name": "<string>"
                }
            ]
        }
    },
    {
        "operation": "<string>",
        "restrictions": {
            "user": [
                {
                    "type": "<string>",
                    "accountId": "<string>",
                    "username": "<string>",
                    "userKey": "<string>"
                },
                {
                    "type": "<string>",
                    "accountId": "<string>",
                    "username": "<string>",
                    "userKey": "<string>"
                }
            ],
            "group": [
                {
                    "type": "<string>",
                    "name": "<string>"
                },
                {
                    "type": "<string>",
                    "name": "<string>"
                }
            ]
        }
    }
]'
https://your-domain.atlassian.net/wiki/rest/api/content/:id/restriction?expand=<string>&expand=<string>

Postman Collection Item JSON

{
  "name": "Add restrictions",
  "request": {
    "auth": {
      "type": "oauth2"
    },
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "[\n    {\n        \"operation\": \"<string>\",\n        \"restrictions\": {\n            \"user\": [\n                {\n                    \"type\": \"<string>\",\n                    \"accountId\": \"<string>\",\n                    \"username\": \"<string>\",\n                    \"userKey\": \"<string>\"\n                },\n                {\n                    \"type\": \"<string>\",\n                    \"accountId\": \"<string>\",\n                    \"username\": \"<string>\",\n                    \"userKey\": \"<string>\"\n                }\n            ],\n            \"group\": [\n                {\n                    \"type\": \"<string>\",\n                    \"name\": \"<string>\"\n                },\n                {\n                    \"type\": \"<string>\",\n                    \"name\": \"<string>\"\n                }\n            ]\n        }\n    },\n    {\n        \"operation\": \"<string>\",\n        \"restrictions\": {\n            \"user\": [\n                {\n                    \"type\": \"<string>\",\n                    \"accountId\": \"<string>\",\n                    \"username\": \"<string>\",\n                    \"userKey\": \"<string>\"\n                },\n                {\n                    \"type\": \"<string>\",\n                    \"accountId\": \"<string>\",\n                    \"username\": \"<string>\",\n                    \"userKey\": \"<string>\"\n                }\n            ],\n            \"group\": [\n                {\n                    \"type\": \"<string>\",\n                    \"name\": \"<string>\"\n                },\n                {\n                    \"type\": \"<string>\",\n                    \"name\": \"<string>\"\n                }\n            ]\n        }\n    }\n]"
    },
    "url": {
      "raw": "{{baseUrl}}/api/content/:id/restriction?expand=<string>&expand=<string>",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "content",
        ":id",
        "restriction"
      ],
      "query": [
        {
          "key": "expand",
          "value": "<string>",
          "description": "A multi-value parameter indicating which properties of the content\nrestrictions (returned in response) to expand.\n\n- `restrictions.user` returns the piece of content that the restrictions are\napplied to. Expanded by default.\n- `restrictions.group` returns the piece of content that the restrictions are\napplied to. Expanded by default.\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 (returned in response) to expand.\n\n- `restrictions.user` returns the piece of content that the restrictions are\napplied to. Expanded by default.\n- `restrictions.group` returns the piece of content that the restrictions are\napplied to. Expanded by default.\n- `content` returns the piece of content that the restrictions are\napplied to."
        }
      ],
      "variable": [
        {
          "key": "id",
          "value": "<string>",
          "type": "string",
          "description": "(Required) The ID of the content to add restrictions to."
        }
      ]
    },
    "description": "Adds restrictions to a piece of content. Note, this does not change any\nexisting restrictions on the content.\n\n**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:\nPermission to edit the content."
  },
  "response": [
    {
      "name": "Returned if the requested restrictions are added.",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: oauth2",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "[\n    {\n        \"operation\": \"<string>\",\n        \"restrictions\": {\n            \"user\": [\n                {\n                    \"type\": \"<string>\",\n                    \"accountId\": \"<string>\",\n                    \"username\": \"<string>\",\n                    \"userKey\": \"<string>\"\n                },\n                {\n                    \"type\": \"<string>\",\n                    \"accountId\": \"<string>\",\n                    \"username\": \"<string>\",\n                    \"userKey\": \"<string>\"\n                }\n            ],\n            \"group\": [\n                {\n                    \"type\": \"<string>\",\n                    \"name\": \"<string>\"\n                },\n                {\n                    \"type\": \"<string>\",\n                    \"name\": \"<string>\"\n                }\n            ]\n        }\n    },\n    {\n        \"operation\": \"<string>\",\n        \"restrictions\": {\n            \"user\": [\n                {\n                    \"type\": \"<string>\",\n                    \"accountId\": \"<string>\",\n                    \"username\": \"<string>\",\n                    \"userKey\": \"<string>\"\n                },\n                {\n                    \"type\": \"<string>\",\n                    \"accountId\": \"<string>\",\n                    \"username\": \"<string>\",\n                    \"userKey\": \"<string>\"\n                }\n            ],\n            \"group\": [\n                {\n                    \"type\": \"<string>\",\n                    \"name\": \"<string>\"\n                },\n                {\n                    \"type\": \"<string>\",\n                    \"name\": \"<string>\"\n                }\n            ]\n        }\n    }\n]"
        },
        "url": {
          "raw": "{{baseUrl}}/api/content/:id/restriction?expand=<string>&expand=<string>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "content",
            ":id",
            "restriction"
          ],
          "query": [
            {
              "key": "expand",
              "value": "<string>"
            },
            {
              "key": "expand",
              "value": "<string>"
            }
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"results\": [\n  {\n   \"operation\": \"purge\",\n   \"_expandable\": {\n    \"restrictions\": \"Excepteur dolore Ut labore\",\n    \"content\": \"tempor esse officia\"\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\": \"in in mollit Ut occaecat\",\n     \"group\": \"irure qui consectetur incididunt\"\n    }\n   },\n   \"content\": {\n    \"value\": \"<Circular reference to #/components/schemas/Content detected>\"\n   }\n  },\n  {\n   \"operation\": \"delete\",\n   \"_expandable\": {\n    \"restrictions\": \"nisi id\",\n    \"content\": \"ut in mollit enim\"\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\": \"est voluptate\",\n     \"group\": \"in\"\n    }\n   },\n   \"content\": {\n    \"value\": \"<Circular reference to #/components/schemas/Content detected>\"\n   }\n  }\n ],\n \"start\": 17789838,\n \"limit\": 13313455,\n \"size\": -47874490,\n \"restrictionsHash\": \"Lorem commodo pariatur Ut eiusmod\",\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 add restrictions to\nthe content.",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: oauth2",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "[\n    {\n        \"operation\": \"<string>\",\n        \"restrictions\": {\n            \"user\": [\n                {\n                    \"type\": \"<string>\",\n                    \"accountId\": \"<string>\",\n                    \"username\": \"<string>\",\n                    \"userKey\": \"<string>\"\n                },\n                {\n                    \"type\": \"<string>\",\n                    \"accountId\": \"<string>\",\n                    \"username\": \"<string>\",\n                    \"userKey\": \"<string>\"\n                }\n            ],\n            \"group\": [\n                {\n                    \"type\": \"<string>\",\n                    \"name\": \"<string>\"\n                },\n                {\n                    \"type\": \"<string>\",\n                    \"name\": \"<string>\"\n                }\n            ]\n        }\n    },\n    {\n        \"operation\": \"<string>\",\n        \"restrictions\": {\n            \"user\": [\n                {\n                    \"type\": \"<string>\",\n                    \"accountId\": \"<string>\",\n                    \"username\": \"<string>\",\n                    \"userKey\": \"<string>\"\n                },\n                {\n                    \"type\": \"<string>\",\n                    \"accountId\": \"<string>\",\n                    \"username\": \"<string>\",\n                    \"userKey\": \"<string>\"\n                }\n            ],\n            \"group\": [\n                {\n                    \"type\": \"<string>\",\n                    \"name\": \"<string>\"\n                },\n                {\n                    \"type\": \"<string>\",\n                    \"name\": \"<string>\"\n                }\n            ]\n        }\n    }\n]"
        },
        "url": {
          "raw": "{{baseUrl}}/api/content/:id/restriction?expand=<string>&expand=<string>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "content",
            ":id",
            "restriction"
          ],
          "query": [
            {
              "key": "expand",
              "value": "<string>"
            },
            {
              "key": "expand",
              "value": "<string>"
            }
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}