site logo

Example: Ticket list (Ruby)


Example: ticket listing (Ruby)  

This code produces a list of tickets selected based on some criteria such as ticket status and creation date.

#!/usr/bin/ruby
# This script demonstrates the Mojo Helpdesk Ticket API ( SOAP access)
# Demonstrates search and ticket listing capability

# You will need to adjust the URL and MYID values:
#
# URL - Base URL to your helpdesk.
#
# MYID - Your access key, as displayed on your "profile" page
#

require 'soap/wsdlDriver'

#
# Configuration settings.
#

URL = "http://mycompany.mojohelpdesk.com"
MYID = "ec91417dddfd7jhgkjhgkjhgjkhg53dce59058932"

#
# Create the SOAP client
#
drv = SOAP::WSDLDriverFactory.new("#{URL}/backend/service.wsdl").create_rpc_driver


#
# Construct the search query.
# ( search for open tickets older than 3 days )

mysrch = {
"status" => "open",
"created_days" => "3",
"created_days_before_or_after" => "before",
"results_per_page" => 10, "page" => 2}

#
# Execute the query.
#

result = drv.FindTickets("#{MYID}", mysrch)

#
# Process the results.
#

result.tickets.each do |r|

print "Ticket:\t", r['id'], "\r\n"
print "Title:\t", r['title'], "\r\n"
print "Status:\t", r['status'], "\r\n"
print "Created by: ", r['created_by']['full_name'], "\r\n"
print "Company name: ", r['company']['name'], "\r\n"
print "Company id: ", r['company']['id'], "\r\n"
print "URL:\t", r['url'], "\r\n"
print "\n"

end