从Atlassian的云/按需服务获取用户列表 [英] Get a list of users from Atlassian's Cloud / On-Demand Service

查看:85
本文介绍了从Atlassian的云/按需服务获取用户列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Atlassian Confluence/Jira实例中提取用户列表.但是,我一直在努力寻找有关可用的REST服务的良好文档,而且似乎已弃用SOAP服务.

I'm trying to pull a list of users from our Atlassian Confluence/Jira instance. However I'm struggling to find good documentation on what REST services are available, and it seems the SOAP services are deprecated.

以下代码确实获得了结果,但是我们有100多个用户,并且返回0.

The following code does get results, but we have over 100 users, and this returns 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只是为了更轻松地查看扩展的结果集).

(The ConvertTo-Json is just to make it simpler to see the expanded result set).

{
    "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;但是我无法弄清楚那些相对URL如何映射到根URL(我尝试在URL的各个位置追加,所有这些都给我一个404dead link错误).

I think the result's trying to give me the URLs for the JIRA and Confluence User APIs; but I can't figure out how those relative URLs map to the root URL (I've tried appending at various positions in the URL, all of which give me a 404 or dead link error).

推荐答案

以下呼叫中的 query 参数是对名称或电子邮件地址的搜索查询. 参考: https://docs.atlassian.com/jira/REST /cloud/#api/2/groupuserpicker .

The query parameter in your following call is a search query on the Name or E-mail address. Reference: https://docs.atlassian.com/jira/REST/cloud/#api/2/groupuserpicker.

您可以使用 maxResults 参数获取50多个结果.

You can use maxResults parameter to get more than 50 results.

遗憾的是,此REST API调用不会一次给您所有用户.

Sadly, this REST API call will not give you all users in one call.

我知道与Jira取得所有用户的唯一方法是通过打首字母(在每个字母上重复)打一个电话:

The only way that I know to do with Jira to get all users is to make one call by starting letter (iterate on each letter):

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

这篇关于从Atlassian的云/按需服务获取用户列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆