public/api-v1/space/Invoke-ConfluenceGetSpaces.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
$ConfluenceSpaceExpand = @("settings","metadata.labels","operations","lookAndFeel"
                           "permissions","icon","description.plain","description.view"
                           "theme","homepage")

#https://developer.atlassian.com/cloud/confluence/rest/#api-api-space-get
function Invoke-ConfluenceGetSpaces {
    [CmdletBinding()]
    param (
        # Space keys of specific spaces to return
        [Parameter(Position=0,ValueFromPipeline,ValueFromPipelineByPropertyName)]
        [Alias("Keys")]
        [string[]]
        $SpaceKeys,

        # Filter results by the provided type
        [Parameter(Position=1)]
        [ValidateSet("global","personal")]
        [string]
        $Type,

        # Filter results by the provide status
        [Parameter(Position=2)]
        [ValidateSet("current","archived")]
        [string]
        $Status,

        # Filter results by labels
        [Parameter(Position=3)]
        [string[]]
        $Labels,

        # Filter by this user's favourites (if not provided, the favourite filter will act on the current user)
        [Parameter(Position=4)]
        [string]
        $FavouriteUserKey,

        # The index of the first item to return in the page of results (page offset). The base index is 0.
        [Parameter(Position=5)]
        [int32]
        $StartAt=0,

        # The maximum number of items to return per page. The default is 25 and the maximum is 100.
        [Parameter(Position=6)]
        [ValidateRange(1,100)]
        [int32]
        $MaxResults=25,

        # Used to expand additional attributes
        [Parameter(Position=7)]
        [ValidateScript({ Compare-StringArraySubset $ConfluenceSpaceExpand $_ })]
        [string[]]
        $Expand,

        # Filter results by favourites of a user
        [Parameter()]
        [switch]
        $Favourite,

        # The AtlassianContext object to use for the request (use New-AtlassianContext)
        [Parameter()]
        [object]
        $RequestContext
    )
    begin {
        $results = @()
    }
    process {
        $functionPath = "/wiki/rest/api/space"
        $verb = "GET"

        $query = New-PACRestMethodQueryParams @{
            start = $StartAt
            limit = $MaxResults
        }
        if($null -ne $SpaceKeys -and $SpaceKeys.Count -gt 0) { $SpaceKeys | ForEach-Object { $query.Add("spaceKey", $_) } }
        if($PSBoundParameters.ContainsKey("Expand")){$query.Add("expand", ($Expand -join ","))}
        if($PSBoundParameters.ContainsKey("Type")){$query.Add("type", $Type)}
        if($PSBoundParameters.ContainsKey("Status")){$query.Add("status", $Status)}
        if($PSBoundParameters.ContainsKey("Labels")){$query.Add("label", ($Labels -join ","))}
        if($PSBoundParameters.ContainsKey("Favourite")){$query.Add("favourite", $Favourite)}
        if($PSBoundParameters.ContainsKey("FavouriteUserKey")){$query.Add("favouriteUserKey", $FavouriteUserKey)}

        $method = New-PACRestMethod $functionPath $verb $query
        $results += $method.Invoke($RequestContext)
    }
    end {
        $results
    }
}