-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwrike.ps1
152 lines (103 loc) · 4.33 KB
/
wrike.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
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
#requires -version 3
#====================================#
# Wrike - PowerShell API Integration #
# LogRhythm Security Operations #
# greg . foss @ logrhythm . com #
# v0.1 -- June, 2017 #
#====================================#
# Copyright 2017 LogRhythm Inc.
# Licensed under the MIT License. See LICENSE file in the project root for full license information.
function wrike {
<#
.SYNOPSIS
Open Wrike in Application Mode in Chrome
Create new tasks
Integrate with automation tools and dynamically generate tasks
.USAGE
Ensure that you have the Wrike functions imported
PS C:\> Import-Module .\wrike.ps1
Open Wrike in Chrome's Application Mode
PS C:\> wrike
#>
$wrike = "https://www.wrike.com/workspace.htm"
Start-Process 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe' --app=$wrike
}
function Invoke-Wrike {
<#
.SYNOPSIS
Query the Wrike API and Create Tasks
.INSTALL
Obtain an API token from the Wrike and hardcode / append during function calls:
https://www.wrike.com/frontend/apps/index.html#/api
.USAGE
Ensure that you have the Wrike functions imported
PS C:\> Import-Module .\wrike.ps1
Interact with the Wrike API
PS C:\> invoke-wrike -connectionTest -accessToken <api key>
PS C:\> invoke-wrike -adminSearch -accessToken <api key>
PS C:\> invoke-wrike -newTask <"Task Title"> -user <"assigned user (first name)"> -folder <"where to add that task?"> -accessToken <api key>
Hardcode variables for quick access from the command line
PS C:\> invoke-wrike -newTask <"Task Title">
#>
[CmdLetBinding()]
param(
[string]$accessToken,
[string]$folder,
[string]$user,
[switch]$connectionTest,
[string]$newTask,
[string]$description = "API - Generated Task",
[switch]$adminSearch
)
if ( -Not $accessToken ) {
Write-Host "Wrike API Key Required..."
Write-Host ""
Exit 1
}
if ( -Not $folder ) {
Write-Host "Wrike Folder Name Required..."
Write-Host ""
Exit 1
}
if ( -Not $user ) {
Write-Host "Wrike User Required..."
Write-Host ""
Exit 1
}
$today = "{0:MM-dd-yyyy}" -f (Get-Date).ToUniversalTime()
$twoDays = "{0:MM-dd-yyyy}" -f ((Get-Date).ToUniversalTime()).AddDays(2)
# Test credentials and gather high-level details about your Wrike account
if ( $connectionTest ) {
$accountRequestData = Invoke-RestMethod -uri https://www.wrike.com/api/v3/accounts -Headers @{'Authorization' = ' bearer '+$accessToken}
$result = $accountRequestData.data
$result
}
# Create and assign a new task
if ( $newTask ) {
# Folder Query
$folderQuery = Invoke-RestMethod -uri https://www.wrike.com/api/v3/folders -Headers @{'Authorization' = ' bearer '+$accessToken}
$folderData = $folderQuery.data | Select-Object Id,title
$wrikeID = @($folderData | findstr -i "$folder").split(" ")[0]
# User Query
$userQuery = Invoke-RestMethod -uri https://www.wrike.com/api/v3/contacts -Headers @{'Authorization' = ' bearer '+$accessToken}
$userData = $userQuery.data | Select-Object id,firstName,lastName
$ownerID = @($userData | findstr -i "$user").split(" ")[0]
$ownerName = @($userData | findstr -i "$user").split(" ")[1]
# Create Basic Task
$payload = "title=$newTask&description=$description&responsibles=[`"$ownerID`"]" #&dates=@{'start':$today, 'due':$twoDays}"
$output = Invoke-RestMethod -uri https://www.wrike.com/api/v3/folders/$wrikeID/tasks -Headers @{'Authorization' = ' bearer '+$accessToken} -Method Post -body $payload
Write-Host ""
Write-Host "Task: `"$newTask`" created, and assigned to $ownerName..."
Write-Host ""
}
# Search for all Wrike admins within your organization
if ( $adminSearch ) {
$adminSearchData = Invoke-RestMethod -uri https://www.wrike.com/api/v3/contacts -Headers @{'Authorization' = ' bearer '+$accessToken}
$result = $adminSearchData.data | Select-Object profiles | findstr -i "admin=true"
Write-Host ""
$result
Write-Host ""
}
# Clear assigned variables
Get-Variable | Remove-Variable -EA 0
}