11<#
22. SYNOPSIS
3- Upload an attachment to a ClickUp task.
3+ Uploads an attachment to a specified ClickUp task.
4+
45. DESCRIPTION
5- Upload an attachment to a ClickUp task.
6+ The New-ClickUpTaskAttachment cmdlet uploads a file as an attachment to a ClickUp task.
7+ You can specify the task by its ID or by using custom task IDs (requires Team ID).
8+
9+ . PARAMETER TaskID
10+ The ID of the task to upload the attachment to.
11+ This parameter is mandatory when not using Custom Task IDs.
12+
13+ . PARAMETER AttachmentPath
14+ The local file path of the attachment to be uploaded.
15+ This parameter is mandatory.
16+
17+ . PARAMETER CustomTaskIDs
18+ Indicates that the provided TaskID is a custom task ID.
19+ If set to $true, the TeamID parameter is also required.
20+
21+ . PARAMETER TeamID
22+ The ID of the team (workspace) where the custom task ID exists.
23+ This parameter is mandatory when CustomTaskIDs is set to $true.
24+
25+ . EXAMPLE
26+ New-ClickUpTaskAttachment -TaskID "8675309" -AttachmentPath "C:\Reports\Status.pdf"
27+
28+ Uploads the file "Status.pdf" to the task with ID "8675309".
29+
630. EXAMPLE
7- PS C:\> New-ClickUpTaskAttachment
31+ New-ClickUpTaskAttachment -TaskID "CUST-123" -AttachmentPath "C:\Images\Design.png" -CustomTaskIDs $true -TeamID 123456
32+
33+ Uploads the file "Design.png" to the task with custom ID "CUST-123" in team 123456.
34+
835. INPUTS
9- None
36+ None. You cannot pipe objects to this cmdlet.
37+
1038. OUTPUTS
11- System.Management.Automation.PSCustomObject.
39+ None. The cmdlet does not return any output.
40+
1241. NOTES
13- See the link for information.
42+ API Reference: https://developer.clickup.com/reference/createtaskattachment
43+
1444. LINK
15- https://jsapi.apiary.io/apis/clickup20/ reference/0/attachments/create-task-attachment.html
45+ https://developer.clickup.com/ reference/createtaskattachment
1646#>
1747function New-ClickUpTaskAttachment {
18- [CmdletBinding ()]
48+ [CmdletBinding (DefaultParameterSetName = ' TaskID ' )]
1949 [OutputType ([System.Management.Automation.PSCustomObject ])]
2050 param (
21- [Parameter (Mandatory = $true )]
51+ [Parameter (Mandatory = $true , ParameterSetName = ' TaskID' )]
52+ [Parameter (Mandatory = $true , ParameterSetName = ' CustomTaskIDs' )]
2253 [string ]$TaskID ,
23- [Parameter (Mandatory = $true )]
24- [string ]$AttachmentPath
54+ [Parameter (Mandatory = $true , ParameterSetName = ' TaskID' )]
55+ [Parameter (Mandatory = $true , ParameterSetName = ' CustomTaskIDs' )]
56+ [string ]$AttachmentPath ,
57+ [Parameter (Mandatory = $true , ParameterSetName = ' CustomTaskIDs' )]
58+ [bool ]$CustomTaskIDs ,
59+ [Parameter (Mandatory = $true , ParameterSetName = ' CustomTaskIDs' )]
60+ [ulong ]$TeamID
2561 )
2662
27- $FileBytes = [System.IO.File ]::ReadAllBytes($AttachmentPath );
63+ Write-Verbose " Reading attachment from: $AttachmentPath "
64+ try {
65+ $FileBytes = [System.IO.File ]::ReadAllBytes($AttachmentPath )
66+ } catch {
67+ throw " Failed to read attachment file at '$AttachmentPath '. Error: $_ "
68+ }
69+
2870 $FileName = $AttachmentPath | Split-Path - Leaf
29- $FileEnc = [System.Text.Encoding ]::GetEncoding(' ISO-8859-1' ).GetString($FileBytes );
30- $Boundary = [System.Guid ]::NewGuid().ToString();
31- $LF = " `r`n " ;
71+ $FileEnc = [System.Text.Encoding ]::GetEncoding(' ISO-8859-1' ).GetString($FileBytes )
72+ $Boundary = [System.Guid ]::NewGuid().ToString()
73+ $LF = " `r`n "
3274
75+ Write-Verbose " Constructing multipart form data with boundary: $Boundary "
3376 $Body = (
3477 " --$Boundary " ,
3578 " Content-Disposition: form-data; name=`" attachment`" ; filename=`" $FileName `" " ,
@@ -41,5 +84,20 @@ function New-ClickUpTaskAttachment {
4184 " --$Boundary --$LF "
4285 ) -join $LF
4386
44- Invoke-ClickUpAPIPostAttachment - Endpoint " task/$TaskID /attachment" - Body $Body - Boundary $Boundary
87+ if ($PSBoundParameters.ContainsKey (' CustomTaskIDs' )) {
88+ $QueryString = @ {
89+ custom_task_ids = $CustomTaskIDs
90+ team_id = $TeamID
91+ }
92+ } else {
93+ $QueryString = @ {}
94+ }
95+
96+ Write-Verbose " Uploading attachment '$FileName ' to task '$TaskID '"
97+ try {
98+ $Null = Invoke-ClickUpAPIPostAttachment - Arguments $QueryString - Endpoint " task/$TaskID /attachment" - Body $Body - Boundary $Boundary
99+ } catch {
100+ Write-Error " Failed to upload attachment to task '$TaskID '. Error: $_ "
101+ throw
102+ }
45103}
0 commit comments