forked from lwhitelock/HuduAutomation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hudu-Crewhu-Stats.ps1
52 lines (43 loc) · 1.92 KB
/
Hudu-Crewhu-Stats.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
#####################################################################
# Get a Hudu API Key from https://yourhududomain.com/admin/api_keys
$HuduAPIKey = "Your Hudu API Key"
# Set the base domain of your Hudu instance without a trailing /
$HuduBaseDomain = "https://your.hudu.domain"
######################### Crewhu Settings ###########################
$CrewHuHuduViewedToken = "hududocsviewed"
$CrewHuHuduCreatedToken = "hududocscreated"
$CrewHuAPIToken = "YourCrewHuAPIToken"
#####################################################################
#Get the Hudu API Module if not installed
if (Get-Module -ListAvailable -Name HuduAPI) {
Import-Module HuduAPI
} else {
Install-Module HuduAPI -Force
Import-Module HuduAPI
}
#Set Hudu logon information
New-HuduAPIKey $HuduAPIKey
New-HuduBaseUrl $HuduBaseDomain
#Get Hudu Data
$HuduViewed = Get-HuduActivityLogs -start_date (get-date).adddays(-7) | where -filter {$_.action -eq "viewed"} |group user_email | select @{N="identificator"; E={$_.name}}, @{N='value'; E={$_.count}}
$HuduCreated = Get-HuduActivityLogs -start_date (get-date).adddays(-7) | where -filter {$_.action -eq "created"} |group user_email | select @{N="identificator"; E={$_.name}}, @{N='value'; E={$_.count}}
$Viewed = @{
'metricToken' = $CrewHuHuduViewedToken
'timeframe' = 'WK'
'data' = $HuduViewed
}
$Created = @{
'metricToken' = $CrewHuHuduCreatedToken
'timeframe' = 'WK'
'data' = $HuduCreated
}
$ViewedJSON = $Viewed | ConvertTo-JSON -Depth 2
$CreatedJSON = $Created | ConvertTo-JSON -Depth 2
Invoke-RestMethod -method POST -uri ("https://api.crewhu.com/api/v1/contest/metrics") `
-headers @{'X_CREWHU_APITOKEN' = $CrewHuAPIToken} `
-ContentType 'application/json' `
-Body $ViewedJSON
Invoke-RestMethod -method POST -uri ("https://api.crewhu.com/api/v1/contest/metrics") `
-headers @{'X_CREWHU_APITOKEN' = $CrewHuAPIToken} `
-ContentType 'application/json' `
-Body $CreatedJSON