Last active
September 20, 2017 19:16
-
-
Save jdmills-edu/0fec6e3b4dfdffbf3892b42fa4604110 to your computer and use it in GitHub Desktop.
A PowerShell script that creates a Zendesk ticket based on the parameters supplied when calling it.
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
param( | |
[Parameter(Mandatory=$true)][String]$subject, | |
[Parameter(Mandatory=$true)][String]$description, | |
[Parameter(Mandatory=$true)][String]$requesterID, | |
[Parameter(Mandatory=$true)][String]$assignedGroupID, | |
[String]$tag | |
) | |
#Zendesk API Connection Headers Referencing System Environmental Variables for username and API token. | |
$headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($ZendeskAPI_Username):$($ZendeskAPI_Token)"));} | |
$createURI = "https://yourdomain.zendesk.com/api/v2/tickets.json" | |
#Dumb hack to swap out unfriendly characters in the description. | |
$description = $description.trim().replace("\","/").replace("`n","\n").replace("`r","\n").replace(" ","").replace("`"","`'").replace("*","") | |
$createJSON = '{ | |
"ticket": { | |
"subject": "'+$subject+'", | |
"comment": "'+$description+'", | |
"requester_id": "'+$requesterID+'", | |
"group_id": "'+$assignedGroupID+'", | |
"tags": ["'+$tag+'"] | |
} | |
}' | |
$result = Invoke-RestMethod -Uri $createURI -Method Post -Headers $headers -ContentType "application/json" -Body $createJson | |
return $result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment