-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopen-tickets.rb
33 lines (31 loc) · 867 Bytes
/
open-tickets.rb
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
require 'csv'
require 'zendesk_api'
z = ZendeskAPI::Client.new do |c|
c.url = ENV['ZENDESK_URL'] || 'https://filmhub.zendesk.com/api/v2'
c.username = ENV['ZENDESK_USERNAME']
c.password = ENV['ZENDESK_PASSWORD']
c.retry = true
end
CSV.open('open-tickets.csv','wb') do |csv|
i = 0
csv << %w{ Date Ticket_ID From Comment Ticket_Date Subject Description Status Channel Tags }
search = ZendeskAPI::Search.search z, query: "type:ticket status<solved"
puts "Exporting #{search.count} tickets"
search.all! do |t|
print "\r#{i += 1} Tickets exported..."
t.comments.each do |c|
csv << [
c.created_at,
t.id,
c.via&.source&.from&.address,
c.body,
t.created_at,
t.subject,
t.description,
t.status,
t.via.channel,
t.tags.map(&:id).join("|")
]
end
end
end