-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdd-CommunityPostToProblem.ps1
More file actions
60 lines (51 loc) · 2.02 KB
/
Copy pathAdd-CommunityPostToProblem.ps1
File metadata and controls
60 lines (51 loc) · 2.02 KB
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
function Add-CommunityPostToProblem {
[CmdletBinding()]
param (
<#
.SYNOPSIS
Creates a problem ticket from a community post.
.DESCRIPTION
This function extracts the contents of a community post and creates a
new Zendesk "Problem" ticket on behalf of the post's author.
.PARAMETER PostId
The ID of the community post.
#>
[Parameter(Mandatory = $true)]
[long]$PostId
)
Test-ZendeskEnvironment
# 1. Retrieve Community Post data
try {
Write-Verbose "Fetching Community Post $PostId..."
$postResponse = Invoke-ZendeskApiCall -UriPath "api/v2/community/posts/$PostId.json" -Method 'GET'
$post = ($postResponse.Content | ConvertFrom-Json).post
}
catch {
Write-Error "Could not retrieve Community Post $PostId : $_"
throw $_
}
# 2. Create Problem Ticket
# We use html_body to retain the rich formatting of the original community post.
$newDescription = "Ticket created from <a href='$($post.html_url)'>Community Post #$PostId</a>.<br><br>" + $post.details
$ticketData = @{
subject = "Community Escalation: $($post.title)"
type = "problem"
requester_id = $post.author_id
tags = @("community_escalation")
comment = @{
html_body = $newDescription
}
}
$body = @{ ticket = $ticketData } | ConvertTo-Json -Depth 10
try {
Write-Verbose "Creating problem ticket for Post $PostId..."
$ticketResponse = Invoke-ZendeskApiCall -UriPath "api/v2/tickets.json" -Method 'POST' -Body $body
$newTicket = ($ticketResponse.Content | ConvertFrom-Json).ticket
Write-Host "Problem Ticket #$($newTicket.id) created from community post #$PostId! See $($env:ZendeskUrl)/agent/tickets/$($newTicket.id)"
return $newTicket
}
catch {
Write-Error "Failed to create ticket for Community Post $PostId : $_"
throw $_
}
}