-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClickUp-CreateTicket.ps1
More file actions
197 lines (129 loc) · 4.34 KB
/
ClickUp-CreateTicket.ps1
File metadata and controls
197 lines (129 loc) · 4.34 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<#
.NOTES
===========================================================================
Created on: 05/25/2021
Updated on: 05/25/2021
Created by: James Krolik
Filename: ClickUp-CreateTicket.ps1
===========================================================================
.DESCRIPTION
This script is part of a collection of scripts meant to interact with ClickUp via PowerShell.
This script is intended to create a ticket and assign a tag for easier viewing.
As part of its functionality, it will create a flag file that will be referenced by the ClickUp-UpdateStatus.ps1 script.
.USAGE
ClickUp-CreateTicket.ps1 -title "MyServer disk C space is under 12% free" -description "Disk space under 12%"
ClickUp-CreateTicket.ps1 -title "MyServer disk C has less than 2GB free" -description "Disk space is under 2GB" -priority 2 -tag "server critical space" -flagName "lowDiskSpace"
.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 = ""
$listID = ""
$flagPath = "C:\Windows\Temp"
<#######################
# Parameter Block #
#######################>
Param(
[Parameter(Mandatory=$true)]
[String]$description,
[Parameter(Mandatory=$true)]
[String]$ticketTitle,
[Parameter(Mandatory=$false)]
[Int]$priority = 3,
[Parameter(Mandatory=$false)]
[String]$tag,
[Parameter(Mandatory=$false)]
[String]$flagName
)
<#######################
# Header Block #
#######################>
$headers = @{
Authorization=$authorizationKey
"Content-Type" = "application/json"
}
<######################
# Function Block #
#######################>
Function CreateTicket {
Param (
[Parameter(Mandatory=$true)]
[String]$ticketTitle,
[Parameter(Mandatory=$true)]
[String]$description,
[Parameter(Mandatory=$false)]
[Int]$priority = 3
)
$body = ""
$body = @{
name=$ticketTitle
description=$description
priority=$priority
}
$json = convertto-json $body
$SendParameters = @{
"URI"="https://api.clickup.com/api/v2/list/$listID/task"
"Method"= 'POST'
}
Invoke-RestMethod @SendParameters -headers $headers -Body $json
}
Function SetTag {
Param (
[Parameter(Mandatory=$true)]
[String]$ticketID,
[Parameter(Mandatory=$true)]
[String]$tag
)
$body = ""
$body = @{
task_id=$ticketID
tag_name=$tag
}
$json = convertto-json $body
$SendParameters = @{
"URI"="https://api.clickup.com/api/v2/task/$ticketID/tag/$tag/"
"Method"= 'POST'
}
Invoke-RestMethod @SendParameters -headers $headers -Body $json
}
#Create ticket and sleep for creation.
$newTicket = createTicket -ticketTitle $ticketTitle -description $description -priority $priority
Start-Sleep 5
#Create folder for flag file.
if ((Test-Path -Path $flagPath) -eq $false) {
New-Item -ItemType "Directory" -Name "Flags" -Path $flagPath
}
#Extract ticket ID from newly created ticket.
$splitInfo = $newTicket
$splitinfo = $splitinfo -replace "[{}]",""
$splitInfo = $splitInfo -replace "[;]","`n"
$splitinfo = $splitInfo -replace "[@]",""
$splitinfo = $splitInfo | ConvertFrom-StringData
$idNumber = $splitInfo.get_item("id")
#Create flag file with ticket number for later referencing.
#If a flag parameter was specified, assign it now.
if (!([String]::IsNullOrEmpty($flagName))) {
$flag = "$flagPath\Flags\$flagName.flag"
}
#If not, default to the ticket title.
else {
$flag = "$flagPath\Flags\$ticketTitle.flg"
}
#If the flag file still exists after the resolve script ran, delete it.
if ((Test-Path -Path $flag) -eq $true) {
Remove-Item -Path $flag -Force
}
#Create the new flag.
New-Item $flag
Add-Content $flag $idNumber
#Assign tag if one was supplied.
if (!([String]::IsNullOrEmpty($tag))) {
SetTag -ticketID $idNumber -tag $tag
}