【问题标题】:Getting restrictions from Confluence page从 Confluence 页面获取限制
【发布时间】:2019-12-12 14:05:19
【问题描述】:

我对 Web API 调用不是很精通,但我一直在使用以下 powershell 代码(本示例中的这个站点是我发现有一些公共数据的站点...我的站点是内部的,需要我通过凭证,它一直在为我工作而没有问题):

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
}

ConfluencePS 的 documentation 表明限制仍然是一个开放的功能请求,但我需要让它为一个项目工作。

我在 ConfluencePS.psm1 的第 982 行设置了一个断点,并且能够看到各种调用以及参数的结构,但是当我尝试模仿它时(并根据 confluence documentation 更改 URI)我收到错误“HTTP 错误 405 - MethodNotAllowed”。有人对我如何使这项工作有建议吗?我正在尝试返回应用于特定空间中所有页面的权限。

【问题讨论】:

  • 1.您的内部服务器的版本是多少?它可能是特定版本中的错误; wiki.opnfv.org 的版本是6.15.9。 2. 在最新版本的developer.atlassian.com 文档中,它说我们应该在/rest/api/content 之前添加/wiki。你试过吗?
  • 我的内部服务器是 6.5.0.我还更新了上面的代码以提供功能响应。当我添加 /wiki 时,它会给出 404 错误,所以我认为这是错误的方向。当您打开由上述代码生成的 URI(只需删除 /restrictions)时,您可以在 Web 响应中看到,甚至可以在可扩展的 ""restrictions":"/rest/api/content/8689708/restriction/byOperation"" 中看到跨度>

标签: powershell confluence-rest-api


【解决方案1】:

按内容 ID 获取限制

你自己发现,需要加上“byOperation”。

我能够使用以下代码获得特定页面的限制:

# 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

在版本 6.0.4 和 6.15.9 上测试

按用户名过滤

如果您想按特定用户名过滤结果,可以使用以下 URI: "$wikiUrl/rest/api/content/$itemId/restriction/byOperation/.../user?userName=".

Bt,这种操作方式存在一个未解决的错误: restriction returns ambiguous responses

【讨论】:

  • 这正是我想要做的!谢谢!!
猜你喜欢
  • 2016-12-21
  • 1970-01-01
  • 1970-01-01
  • 2021-02-27
  • 2013-10-18
  • 1970-01-01
  • 2019-03-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多