Я работаю над Ruby в приложении Rails, которому требуется доступ к внешнему API через запросы GET. В запросе необходимо отправить несколько параметров с запросом. Я использовал Activeresource Gem для доступа к API. Запрос API хорошо работает в Postman и выдает ожидаемые записи, но выдает ошибку 400 из приложения Rails.
Ниже приведен код
class PayRunEmploymentHeroBase < ActiveResource::Base
self.site = "https://api.yourpayroll.com.au"
self.user = ENV['EMPLOYMENT_HERO_USERNAME']
self.element_name = ""
self.include_format_in_path = false
self.prefix = "/api/v2/business/:business_id/payrun?$filter=DateFinalised gt datetime':finalised_date'"
end
Я вставляю здесь детали ошибки 400 при доступе по ссылке из приложения Rails.
Reloading...
=> true
2.3.0 :006 > PayRunEmploymentHeroBase.find(:all, params: {:business_id => business_id, :finalised_date => finalised_date})
##############################################INFO##############################################
{
"method": "get",
"request_uri": "https://api.yourpayroll.com.au:443/api/v2/business/48058/payrun?$filter=DateFinalised gt datetime'2017-11-16'",
"http_status": "400",
"http_message": "Bad Request"
}
##############################################INFO##############################################
ActiveResource::BadRequest: Failed. Response code = 400. Response message = Bad Request.
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activeresource-5.1.0/lib/active_resource/connection.rb:141:in `handle_response'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activeresource-5.1.0/lib/active_resource/connection.rb:126:in `request'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activeresource-5.1.0/lib/active_resource/connection.rb:85:in `block in get'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activeresource-5.1.0/lib/active_resource/connection.rb:220:in `with_auth'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activeresource-5.1.0/lib/active_resource/connection.rb:85:in `get'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activeresource-5.1.0/lib/active_resource/base.rb:1073:in `find_every'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activeresource-5.1.0/lib/active_resource/base.rb:974:in `find'
from (irb):6
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/railties-5.0.3/lib/rails/commands/console.rb:65:in `start'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/railties-5.0.3/lib/rails/commands/console_helper.rb:9:in `start'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:78:in `console'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/railties-5.0.3/lib/rails/commands.rb:18:in `<main>'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/bootsnap-1.0.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17:in `require'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/bootsnap-1.0.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17:in `require'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:293:in `block in require'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:259:in `load_dependency'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:293:in `require'
from /Users/bebble1/work/awe/bin/rails:9:in `<main>'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/bootsnap-1.0.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `load'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/bootsnap-1.0.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `load'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:287:in `block in load'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:259:in `load_dependency'
from /Users/bebble1/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:287:in `load'
from /Users/bebble1/.rvm/rubies/ruby-2.3.0/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/bebble1/.rvm/rubies/ruby-2.3.0/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:54:in `require'
Я также приложил сюда картинку с результатами приложения Rails