-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClickUp-UpdateStatus.ps1
More file actions
165 lines (113 loc) · 3.36 KB
/
ClickUp-UpdateStatus.ps1
File metadata and controls
165 lines (113 loc) · 3.36 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<#
.NOTES
===========================================================================
Created on: 05/25/2021
Updated on: 05/27/2021
Created by: James Krolik
Filename: ClickUp-UpdateStatus.ps1
===========================================================================
.DESCRIPTION
This script is part of a collection of scripts meant to interact with ClickUp via PowerShell.
This script is intended to update the status of an existing ticket and currently supports 'Open', 'Pending', 'New', and 'Complete' Statuses.
Additionally, the script can accept a parameter to use Custom ticket (xx-xxxxxx) identifier by passing in -customID with $true.
.USAGE
ClickUp-UpdateStatus.ps1 -taskID ""a1b2c3d"" -newStatus "Complete"
ClickUp-UpdateStatus.ps1 -taskID "JT-12345" -newStatus "New" -customID $true
.ADDITIONAL NOTES
For ClickUp's API, please see their website here:
https://clickup.com/api
This was built with the OAuth2 authorization code and access token steps in mind.
You could also sub out the access token with the personal key that they mention (pk_) and it would work just the same as the authorization key.
#>
<##########################
Site Specific Information
###########################>
$authorizationKey = ""
$teamID = ""
$flagPath = "C:\Windows\Temp"
<#######################
# Parameter Block #
#######################>
Param(
[Parameter(Mandatory=$false)]
[String]$taskID,
[Parameter(Mandatory=$true)]
[String]$newStatus,
[Parameter(Mandatory=$false)]
[Bool]$customID=$false,
[Parameter(Mandatory=$false)]
[String]$flag
)
<#######################
# Header Block #
#######################>
$headers = @{
Authorization=$authorizationKey
"Content-Type" = "application/json"
}
<######################
# Function Block #
#######################>
Function updateStatus {
Param (
[Parameter(Mandatory=$true)]
[String]$taskID,
[Parameter(Mandatory=$true)]
[String]$newStatus
)
<#######################
Status Payload
#######################>
$body = ""
if ($newStatus -match "New") {
$body = @'
{
"status":"New"
}
'@
}
if ($newStatus -match "Open") {
$body = @'
{
"status":"Open"
}
'@
}
if ($newStatus -match "Pending") {
$body = @'
{
"status":"Pending"
}
'@
}
if ($newStatus -match "Complete") {
$body = @'
{
"status":"Complete"
}
'@
}
<####################
Parameter Payload
####################>
if ($customID -eq $true) {
$SendParameters = @{
"URI"="https://api.clickup.com/api/v2/task/$taskID/?custom_task_ids=true&team_id=$teamID"
"Method"= 'PUT'
}
Invoke-RestMethod @SendParameters -headers $headers -Body $body
}
if ($customID -eq $false) {
$SendParameters = @{
"URI"="https://api.clickup.com/api/v2/task/$taskID/"
"Method"= 'PUT'
}
Invoke-RestMethod @SendParameters -headers $headers -Body $body
}
}
#If the flag has been set, grab the ticket number from it.
if (!([String]::IsNullOrEmpty($flag))) {
$flagDataToRead = "$flagPath\Flags\$flag.flag"
$taskID = Get-Content -Path $flagDataToRead
}
updateStatus -taskid $taskID -newstatus $newStatus