zendesk / zendesk_api_client_rb

Official Ruby Zendesk API Client
http://developer.zendesk.com/
Apache License 2.0
387 stars 183 forks source link

ZendeskAPI::Ticket appears to be using API v1? #340

Closed raquelxmoss closed 5 years ago

raquelxmoss commented 7 years ago

Hey there. I'm getting Zendesk set up in our Rails app, and, following the documentation I've set up the client with basic auth, and attempt to create a ticket as follows:

ZendeskAPI::Ticket.create!(client, subject: "Test", comment: { value: "test" }, priority: "urgent")

The response I get back seems to indicate that ZendeskAPI::Ticket.create is using API v1, and is unable to authenticate me.

post https://MYURL.zendesk.com/tickets
  Accept: "application/json"
  Accept-Encoding: "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
  User-Agent: "ZendeskAPI Ruby 1.14.4"
{:ticket=>#<ZendeskAPI::SilentMash comment=#<ZendeskAPI::SilentMash value="test"> priority="urgent" subject="Test">}
Status 400
  server: "nginx"
  date: "Wed, 28 Jun 2017 21:18:43 GMT"
  content-type: "text/html; charset=UTF-8"
  content-length: "36"
  connection: "close"
  x-zendesk-api-version: "v1"
  x-zendesk-application-version: "v29.33"
  x-rate-limit: "400"
  x-rate-limit-remaining: "399"
  x-api-deprecated: "Please use /api/v1/tickets"
  set-cookie: "_zendesk_shared_session=STUFF; path=/; secure; HttpOnly, _zendesk_authenticated=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT; secure; HttpOnly, _zendesk_cookie=STUFF; path=/; expires=Sun, 28-Jun-2037 20:26:37 GMT; secure; HttpOnly, _zendesk_session=STUFF"
  p3p: "CP=\"NOI DSP COR NID ADMa OPTa OUR NOR\""
  strict-transport-security: "max-age=31536000;"
  x-ua-compatible: "IE=Edge,chrome=1"
  cache-control: "no-cache"
  x-zendesk-origin-server: "app14.pod14.use1.zdsys.com"
  x-request-id: "a38eb0be-0d88-43a7-c3bb-12b5dccccec8"
  x-runtime: "0.179177"
  x-rack-cache: "invalidate, pass"
  x-zendesk-request-id: "c5617d6585fc16ad9521"
"api v1 basic auth access is disabled"

Making a request in Postman to /api/v2/users/me.json with the same basic auth credentials works just fine.

I'm using gem version 1.14.1, and I have an initializer set up for the client as follows:

require "zendesk_api"

module Zendesk
  def self.client
    @client ||= ZendeskAPI::Client.new do |config|
      config.url = "https://MYURLHERE.zendesk.com"

      # Basic / Token Authentication
      config.username = ENV.fetch("ZENDESK_USERNAME")
      config.token = ENV.fetch("ZENDESK_TOKEN")

      config.retry = true

      config.logger = Rails.logger
    end
  end
end
bekicot commented 7 years ago

I'm also having similar issue with version 1.14.4

bekicot commented 7 years ago

@raquelxmoss Well, answering to your and my own problem. Apparently, in the readme, it stated that we can manually specify it

bekicot.zendesk.com/api/v2

and then it will use API v2 as the endpoint

Probably Zendesk kept bekicot.zendesk.com/tickets endpoint for backward compatibility that returns that errors. The error also confused me.

rcscott commented 5 years ago

I think this can be closed. The documentation states that you must specify an API url ending with /api/v2: https://github.com/zendesk/zendesk_api_client_rb/wiki/Configuration#mandatory-options