Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Zendesk Ticket search based on search query like "" and with results including comments. Using the official Zendesk API v2 ruby gem:
require 'zendesk_api'
class Zendesk
attr_accessor :client
def initialize
@client = do |config|
# Mandatory:
config.url = "<- your-zendesk-url ->" # e.g.
# Basic / Token Authentication
config.username = ""
# Choose one of the following depending on your authentication choice
config.token = "your zendesk token"
config.password = "your zendesk password"
# OAuth Authentication
config.access_token = "your OAuth access token"
# Optional:
# Retry uses middleware to notify the user
# when hitting the rate limit, sleep automatically,
# then retry the request.
config.retry = true
# Logger prints to STDERR by default, to e.g. print to stdout:
require 'logger'
config.logger =
# Changes Faraday adapter
# config.adapter = :patron
# Merged with the default client options hash
# config.client_options = { :ssl => false }
# When getting the error 'hostname does not match the server certificate'
# use the API at
def find_tickets_including_comments(search_query) "type:ticket #{search_query}").map do |ticket|
ticket.to_h.slice(*%w[created_at subject]).merge(
'comments' => do |comment|
comment.to_h.slice(*%w[created_at via body])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment