public/api-v1/content/Invoke-ConfluenceCreateOrUpdateAttachment.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
#https://developer.atlassian.com/cloud/confluence/rest/#api-content-id-child-attachment-post
function Invoke-ConfluenceCreateOrUpdateAttachment {
    [CmdletBinding()]
    param (
        # The ID of the content to create an attachment for
        [Parameter(Mandatory,Position=0,ValueFromPipelineByPropertyName)]
        [Alias("Id")]
        [int32]
        $ContentId,

        # The file to be added
        [Parameter(Mandatory,Position=1,ValueFromPipeline,ValueFromPipelineByPropertyName)]
        [object]
        $Attachment,

        # A comment to go with the attachment
        [Parameter(Position=2,ValueFromPipelineByPropertyName)]
        [string]
        $Comment,

        # The status of the content that the attachment is to be added to
        [Parameter(Position=3,ValueFromPipelineByPropertyName)]
        [ValidateSet("current","draft")]
        [string]
        $Status="current",

        # Set this flag to indicate that this change should not trigger notifications or activity feed updates
        [Parameter(ValueFromPipelineByPropertyName)]
        [switch]
        $MinorEdit,

        # Set this flag to force a create, throwing an error if the attachment already exists
        [Parameter(ValueFromPipelineByPropertyName)]
        [switch]
        $ForceCreate,

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

        $query = New-PACRestMethodQueryParams @{
            status = $Status
        }

        $body = @{
            file = $Attachment
            minorEdit = $MinorEdit
        }
        if($PSBoundParameters.ContainsKey("Comment")){$body.Add("comment",$Comment)}

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