Skip to content

Instantly share code, notes, and snippets.

@mrpunkin
Created June 27, 2018 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrpunkin/e16318a277fb1386ab263ddb4dad973d to your computer and use it in GitHub Desktop.
Save mrpunkin/e16318a277fb1386ab263ddb4dad973d to your computer and use it in GitHub Desktop.
ZendeskAPI code to loop through specific tickets and mark them all as spam.
class Spam
require 'zendesk_api'
def self.client
@client ||= ZendeskAPI::Client.new do |config|
config.url = "https://pediment.zendesk.com/api/v2" # e.g. https://mydesk.zendesk.com/api/v2
config.username = "admin@pediment.com"
config.password = "pedb00ks"
config.retry = true
end
end
def self.spams
client.search(query: 'created>2018-06-26T23:55:00-07:00 created<2018-06-27T03:28:00-07:00 type:ticket status:new')
end
def self.cleanup
spams.page(1)
spams.clear_cache
## Get idsets
idsets = []
while spams.fetch!
ids = spams.map(&:id)
idsets << ids
spams.last_page? ? break : spams.next
end
spams.page(nil)
spams.clear_cache
## Handle idsets
jobs = []
idsets.each do |ids|
job = mark_many_as_spam(ids)
puts "Job [#{job.status}]: #{job.url}"
jobs << job
end
return jobs
end
def self.mark_many_as_spam(ids)
response = client.connection.put("tickets/mark_many_as_spam") do |req|
req.params = { ids: ids.join(',') }
req.body = {}
yield req if block_given?
end
ZendeskAPI::JobStatus.new_from_response(client, response)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment