3

I'm not very savvy with web API calls, but I've been using the following powershell code (this site in this example is one I found that has some public data... my site is internal and requires I pass the credential, which has been working for me without issue):

If(-not (Get-InstalledModule -Name 'ConfluencePS')){Install-Module ConfluencePS}
Import-Module ConfluencePS

Set-ConfluenceInfo -BaseUri "https://wiki.opnfv.org"

$space = Get-confluencepage -Spacekey ds

ForEach($item in $space)
{
    $splatParams = @{
                        Uri = "https://wiki.opnfv.org/rest/api/content/$($item.ID)/restriction"
                        ContentType = 'application/json'
                        method = 'GET'
                    }
    #reference https://developer.atlassian.com/cloud/confluence/rest/#api-api-content-id-restriction-get
    Invoke-RestMethod @splatParams
}

The documentation for the ConfluencePS shows that restrictions is still an open feature request but I need to get this working for a project.

I put a breakpoint in on line 982 from ConfluencePS.psm1 and was able to see the various calls and how the params are structured but when I try to mimic it (and change the URI based on the confluence documentation) I get an error "HTTP error 405 - MethodNotAllowed". Anyone have suggestions on how I can get this working? I'm trying to return back the permissions applied for all pages in a specific space.

Xanderu
  • 747
  • 1
  • 8
  • 30
  • 1. What is the version of your internal server? it **could** be a bug in a specific version; The version of `wiki.opnfv.org` is `6.15.9`. 2. On `developer.atlassian.com` documentation for the latest version, it says that we should add `/wiki` before `/rest/api/content`. have you tried that? – itsho Dec 16 '19 at 16:00
  • my internal server is 6.5.0. I've also updated my code above to provide a functional response. When I add /wiki it gives a 404 error so I think that is going the wrong direction. When you open the URI generated by the above code (just drop /restrictions) you can see in the web response and even in the expandable ""restrictions":"/rest/api/content/8689708/restriction/byOperation"" – Xanderu Dec 16 '19 at 18:39

1 Answers1

7

Get Restrictions by Content ID

As you found out by yourself, it is required to add "byOperation".

I was able to get the restrictions of a specific page with the following code:

# for testing purposes ONLY, I've specified the URL and ID
$wikiUrl = "https://wiki.opnfv.org"
$itemId = "6820746"

$splatParams = @{
                    Uri = "$wikiUrl/rest/api/content/$itemId/restriction/byOperation"
                    ContentType = 'application/json'
                    method = 'GET'
                }
$result = Invoke-RestMethod @splatParams

Tested on version 6.0.4 and 6.15.9

Filter by user name

If you like to filter the result by a specific username, you can use the following URI: "$wikiUrl/rest/api/content/$itemId/restriction/byOperation/.../user?userName=".

Bt, there's an open bug on this way of action: restriction returns ambiguous responses

itsho
  • 4,640
  • 3
  • 46
  • 68