在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:zendesk/zendesk_api_client_rb开源软件地址:https://github.com/zendesk/zendesk_api_client_rb开源编程语言:Ruby 100.0%开源软件介绍:Zendesk API ClientDocumentationThis Ruby gem is a generic wrapper around Zendesk's REST API. Follow this README and the wiki for how to use it. You can interact with all the resources defined in Please refer to our API documentation for the specific endpoints and once you understand the mapping between Ruby and the HTTP endpoints you should be able to call any endpoint. The Yard generated documentation is available in at RubyDoc. Please report any bug in the Github issues page. You might want to try out this gem in a REPL for exploring your options, if so, check out this project. Product SupportThis Ruby gem supports the REST API's for Zendesk Support, Zendesk Guide, and Zendesk Talk. It does not yet support other Zendesk products such as Zendesk Chat, Zendesk Explore, and Zendesk Sell. InstallationThe Zendesk API client can be installed using Rubygems or Bundler. Rubygemsgem install zendesk_api BundlerAdd it to your Gemfile
Then ConfigurationConfiguration is done through a block returning an instance of require 'zendesk_api'
client = ZendeskAPI::Client.new do |config|
# Mandatory:
config.url = "<- your-zendesk-url ->" # e.g. https://yoursubdomain.zendesk.com/api/v2
# Basic / Token Authentication
config.username = "[email protected]"
# 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
# Raise error when hitting the rate limit.
# This is ignored and always set to false when `retry` is enabled.
# Disabled by default.
config.raise_error_when_rate_limited = false
# Logger prints to STDERR by default, to e.g. print to stdout:
require 'logger'
config.logger = Logger.new(STDOUT)
# Disable resource cache (this is enabled by default)
config.use_resource_cache = false
# Changes Faraday adapter
# config.adapter = :patron
# Merged with the default client options hash
# config.client_options = {:ssl => {:verify => false}, :request => {:timeout => 30}}
# When getting the error 'hostname does not match the server certificate'
# use the API at https://yoursubdomain.zendesk.com/api/v2
# Change retry configuration (this is disabled by default)
config.retry_on_exception = true
# Error codes when the request will be automatically retried. Defaults to 429, 503
config.retry_codes = [ 429 ]
end UsageThe result of configuration is an instance of One way to use the client is to pass it in as an argument to individual classes. Note: all method calls ending in ZendeskAPI::Ticket.new(client, :id => 1, :priority => "urgent") # doesn't actually send a request, must explicitly call #save!
ZendeskAPI::Ticket.create!(client, :subject => "Test Ticket", :comment => { :value => "This is a test" }, :submitter_id => client.current_user.id, :priority => "urgent")
ZendeskAPI::Ticket.find!(client, :id => 1)
ZendeskAPI::Ticket.destroy!(client, :id => 1) You can also update ticket objects. ticket = ZendeskAPI::Ticket.find!(client, :id => 1)
ticket.update(:comment => { :value => "This is a test reply." })
ticket.save! Another way is to use the instance methods under client. client.tickets.first
client.tickets.find!(:id => 1)
client.tickets.build(:subject => "Test Ticket")
client.tickets.create!(:subject => "Test Ticket", :comment => { :value => "This is a test" }, :submitter_id => client.current_user.id, :priority => "urgent")
client.tickets.destroy!(:id => 1) The methods under CaveatsResource updating is implemented by sending only the
Pagination
tickets = client.tickets.page(2).per_page(3)
next_page = tickets.next # => 3
tickets.fetch! # GET /api/v2/tickets?page=3&per_page=3
previous_page = tickets.prev # => 2
tickets.fetch! # GET /api/v2/tickets?page=2&per_page=3 Iteration over all resources and pages is handled by client.tickets.all! do |resource|
# every resource, from all pages, will be yielded to this block
end If given a block with two arguments, the page number is also passed in. client.tickets.all! do |resource, page_number|
# all resources will be yielded along with the page number
end CallbacksCallbacks can be added to the client.insert_callback do |env|
puts env[:response_headers]
end Resource managementIndividual resources can be created, modified, saved, and destroyed. ticket = client.tickets[0] # ZendeskAPI::Ticket.find(client, :id => 1)
ticket.priority = "urgent"
ticket.attributes # => { "priority" => "urgent" }
ticket.save! # Will PUT => true
ticket.destroy! # => true
ZendeskAPI::Ticket.new(client, { :priority => "urgent" })
ticket.new_record? # => true
ticket.save! # Will POST Side-loadingTo facilitate a smaller number of requests and easier manipulation of associated data we allow "side-loading," or inclusion, of selected resources. For example:
A "ticket": {
"id": 1,
"url": "http.....",
"requester_id": 7,
...
} Calling tickets = client.tickets.include(:users)
# Or client.tickets(:include => :users)
# Does *NOT* make a request to the server since it is already loaded
tickets.first.requester # => #<ZendeskAPI::User id=...>
# OR
ticket = client.tickets.find!(:id => 1, :include => :users)
ticket.requester # => #<ZendeskAPI::User id=...> Currently, this feature is limited to only a few resources and their associations. They are documented on developer.zendesk.com. SearchSearching is done through the client. Returned is an instance of client.search(:query => "my search query") # /api/v2/search.json?query=...
client.users.search(:query => "my new query") # /api/v2/users/search.json?query=... Special case: Custom resources pathsAPI endpoints such as client.tickets.recent
client.topics.show_many(:verb => :post, :ids => [1, 2, 3]) Special Case: Current userUse either of the following to obtain the current user instance: client.users.find!(:id => 'me')
client.current_user Special Case: Importing a ticketBulk importing tickets allows you to move large amounts of data into Zendesk. ticket = ZendeskAPI::Ticket.import(client, :subject => "Help", :comments => [{ :author_id => 19, :value => "This is a comment" }]) Further documentation can be found on developer.zendesk.com Attaching filesFiles can be attached to ticket comments using either a path or the File class and will be automatically uploaded and attached. ticket = ZendeskAPI::Ticket.new(client, :comment => { :value => "attachments" })
ticket.comment.uploads << "img.jpg"
ticket.comment.uploads << File.new("img.jpg")
ticket.save! Apps APIv1.1.0 introduces support for the Zendesk Apps API Creating Appsupload = client.apps.uploads.create!(:file => "path/to/app.zip")
client.apps.create!(:name => "test", :upload_id => upload.id)
# Or
app = ZendeskAPI::App.new(client, :name => "test")
app.upload = "path/to/app.zip"
app.save!
# Or
upload = ZendeskAPI::App::Upload.new(client, :file => "path/to/app.zip")
upload.save!
app = ZendeskAPI::App.new(client, :name => "test")
app.upload_id = upload.id
app.save!
# Or
client.apps.create!(:name => "test", :upload => "app.zip") Note: job statuses are currently not supported, so you must manually poll the job status API for app creation. body = {}
until %w{failed completed}.include?(body["status"])
response = client.connection.get(app.response.headers["Location"])
body = response.body
sleep(body["retry_in"])
end Updating Appsupload = client.apps.uploads.create!(:file => "NewApp.zip")
# Then
client.apps.update!(:id => 123, :upload_id => upload.id)
# Or
app = ZendeskAPI::App.new(client, :id => 123)
app.upload_id = upload.id
app.save!
# Or
ZendeskAPI::App.update!(client, :id => 123, :upload_id => upload.id) Deleting Appsclient.apps.destroy!(:id => 123)
app = ZendeskAPI::App.new(client, :id => 123)
app.destroy!
ZendeskAPI::App.destroy!(client, :id => 123) Installing an AppInstallation name is required installation = ZendeskAPI::AppInstallation.new(client, :app_id => 123, :settings => { :name => 'Name' })
installation.save!
# or
client.apps.installations.create!(:app_id => 123, :settings => { :name => 'Name' })
# or
ZendeskAPI::AppInstallation.create!(client, :app_id => 123, :settings => { :name => 'Name' }) List Installationsapps = client.app.installations
apps.fetch! Update Installationclient.app.installations.update!(:id => 123, :settings => { :title => "My New Name" })
installation = ZendeskAPI::AppInstallation.new(client, :id => 123)
inst |
2022-08-15
2022-08-17
2022-09-23
2022-08-18
2023-10-27
请发表评论