public/api-v1/content/Invoke-ConfluenceAddContentLabels.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
#https://developer.atlassian.com/cloud/confluence/rest/#api-content-id-label-post
function Invoke-ConfluenceAddContentLabels {
    [CmdletBinding()]
    param (
        # The ID of the page
        [Parameter(Mandatory,Position=0,ValueFromPipeline,ValueFromPipelineByPropertyName)]
        [Alias("PageId")]
        [int32]
        $Id,

        # The name of the label to add
        [Parameter(Mandatory,Position=1,ValueFromPipeline,ValueFromPipelineByPropertyName)]
        [string[]]
        $Label,

        # The scope of the label
        [Parameter(Position=2,ValueFromPipelineByPropertyName)]
        [ValidateSet("global","my","team")]
        [string]
        $Scope="global",

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

        $body = @()
        $Label | ForEach-Object { $body += @{name = $_; prefix = $Scope} }
            
        $literalBody = ConvertTo-Json $body -Compress

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