2

Atlassian Confluence/Jira インスタンスからユーザーのリストを取得しようとしています。しかし、利用可能な REST サービスに関する適切なドキュメントを見つけるのに苦労しており、SOAP サービスは非推奨になっているようです。

次のコードは結果を取得しますが、ユーザーが 100 人を超えているため、0 が返されます。

if(-not ($credentials)) { #put this here so I can rerun the same script in the same IDE session without having to reinput credentials each time
    $credentials = get-credential 'myAtlassianUsername'
}
$tenant = 'myCompany'
invoke-restmethod -Method Get -Uri ('https://{0}.atlassian.net/rest/api/2/groupuserpicker?query=users' -f $tenant) -Credential $credentials | ConvertTo-Json -Depth 5

(これConvertTo-Jsonは、展開された結果セットを簡単に確認できるようにするためのものです)。

{
    "users":  {
                  "users":  [

                            ],
                  "total":  0,
                  "header":  "Showing 0 of 0 matching users"
              },
    "groups":  {
                   "header":  "Showing 2 of 2 matching groups",
                   "total":  2,
                   "groups":  [
                                  {
                                      "name":  "confluence-users",
                                      "html":  "confluence-\u003cb\u003eusers\u003c/b\u003e",
                                      "labels":  [

                                                 ]
                                  },
                                  {
                                      "name":  "jira-users",
                                      "html":  "jira-\u003cb\u003eusers\u003c/b\u003e",
                                      "labels":  [

                                                 ]
                                  }
                              ]
               }
}

結果は、JIRA および Confluence ユーザー API の URL を取得しようとしていると思います。404しかし、これらの相対 URL がルート URL にどのようにマップされるのかわかりません (URL のさまざまな位置に追加しようとしましたが、そのすべてでdead linkエラーが発生しました)。

4

2 に答える 2

1

次の呼び出しのクエリパラメータは、名前または電子メール アドレスに対する検索クエリです。参照: https://docs.atlassian.com/jira/REST/cloud/#api/2/groupuserpicker .

maxResultsパラメータを使用して、50 を超える結果を取得できます。

残念ながら、この REST API 呼び出しでは、1 回の呼び出しですべてのユーザーを取得することはできません。

すべてのユーザーを取得するために Jira を使用する唯一の方法は、文字を開始して 1 つの呼び出しを行うことです (文字ごとに繰り返します)。

GET .../rest/api/2/user/search?username=a&maxResults=1000
GET .../rest/api/2/user/search?username=b&maxResults=1000
GET .../rest/api/2/user/search?username=c&maxResults=1000
...

参照: https://docs.atlassian.com/jira/REST/cloud/#api/2/user-findUsers

サンプルコード

function Get-AtlassianCloudUsers {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)][string]$Tenant
        ,
        [Parameter(Mandatory)][System.Management.Automation.Credential()]$Credential
        ,
        [Parameter(Mandatory=$false)][string]$UserFilter = '%' 
        ,
        [Parameter(Mandatory=$false)][int]$MaxResults = 9999
    )
    process {
        #refer to http://stackoverflow.com/questions/40424377/get-a-list-of-users-from-atlassians-cloud-on-demand-service for additional notes
        [string]$uri = 'https://{0}.atlassian.net/rest/api/2/user/search?username={1}&maxResults={2}' -f $Tenant, $UserFilter, $MaxResults
        Invoke-RestMethod -Method Get -Uri $Uri -Credential $credential | select -Expand syncRoot | Select-Object name, displayName, active, self 
        #| ConvertTo-Json -Depth 5
    }
}

Get-AtlassianCloudUsers -Tenant 'MyCompany' -credential (Get-Credential 'MyUsername') | ft -AutoSize
于 2016-11-07T13:41:30.313 に答える