Created
December 5, 2014 05:46
-
-
Save dstreefkerk/0678538586a8682b3252 to your computer and use it in GitHub Desktop.
Tickets Open widget update code. To be used with a "Number and Secondary Stat" widget: https://developer.geckoboard.com/#number-and-secondary-stat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$apikey = "paste in your API key here" | |
$geckoPushUrl = "paste in your push URL here" | |
# Get the count of open tickets from the database | |
$openTickets = Invoke-Item spiceworks: -sql 'select count() as "count" from tickets where status == "open"' | |
#Construct a here-string with the required json format | |
$jsonstream = @" | |
{ | |
"api_key":"APIKEY", | |
"data": { | |
"type" : "reverse", | |
"item" : | |
[ | |
{ "text" : "TICKETTEXT","value" : TICKETSOPENVALUE} | |
] | |
} | |
} | |
"@ | |
$ticketText = if ($newToday.count -eq 1) { "Ticket Open" } else { "Tickets Open" } | |
$jsonstream = $jsonstream.Replace("TICKETSOPENVALUE",$($openTickets.count)) | |
$jsonstream = $jsonstream.Replace("APIKEY",$apikey) | |
$jsonstream = $jsonstream.Replace("TICKETTEXT",$ticketText) | |
#The line of code will only work in PowerShell V3 | |
#Invoke-WebRequest -Method Post -Body $jsonstream -Uri $geckoPushUrl | |
#This should work in V2 also | |
$client = new-object system.net.webclient | |
$client.UploadString($geckoPushUrl,$jsonstream) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment