Skip to content

Instantly share code, notes, and snippets.

@jdmills-edu
Created September 20, 2017 20:26
Show Gist options
  • Save jdmills-edu/e8b9272f07e946a73682a6977dce4696 to your computer and use it in GitHub Desktop.
Save jdmills-edu/e8b9272f07e946a73682a6977dce4696 to your computer and use it in GitHub Desktop.
This PowerShell script updates a custom field on a given Zendesk ticket.
param(
[Parameter(Mandatory=$true)][Int32]$ticketID,
[Parameter(Mandatory=$true)][Int32]$fieldID,
[Parameter(Mandatory=$true)][string]$fieldValue
)
#Zendesk API Connection Headers Referencing System Environmental Variables for username and API token.
$headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($env:ZendeskAPI_Username):$($env:ZendeskAPI_Token)"));}
#Zendesk API: Update Ticket
$uri = "https://yourdomain.zendesk.com/api/v2/tickets/$ticketID.json"
$json = '{
"ticket": {
"custom_fields": [
{ "'+$fieldID+'": "'+$fieldValue+'" }
]
}
}'
Invoke-RestMethod -Uri $uri -Method Put -Headers $headers -ContentType "application/json" -Body $json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment