API Requests not being sent in Production w/Excon Rails 6.0.0

183 views Asked by At

I'm having an issue where my POST request with Excon gem is not being sent out in production, but works perfectly in development. In my logs, it shows Processing ServiceFormsControlller#run_background_check as HTML. I don't know exactly why this is happening...It was working perfectly last week. Now all of a sudden, no requests are being sent out from the production server...It shows the action taking place, but the API endpoint never receives the POST. I added the website to my CORS configuration as a whitelisted domain. That didn't do anything to improve the results.

service_forms_controller.rb

class ServiceFormsController < ApplicationController
 @service_form = ServiceForm.find(params[:id])
 @service_info = @service_form.info

 if @service_info.first_name.present? && @service_info.last_name.present? && @service_info.ssn.present? && @service_info.address.present? && @service_info.email.present?

@report_builder = GoodHire.new
if Rails.env.production?
 @report_builder.create_report_for_candidate(@service_info.first_name, @service_info.last_name, @service_info.ssn, @service_info.address, @service_info.email)
# other mandatory fields added to this call
end
  redirect_to service_forms_path, notice: "You've submitted the candidate for a background check"
  else
redirect_to service_forms_path, notice: "The candidate doesn't have all fields completed"
end

good_hire.rb

class GoodHire
  API_KEY_PROD = 'ZZzazzee'

include RestClient
include Excon

def create_report_for_candidate(first_name, last_name, email, ssn, address, city, state, zip, work_histories =[].....,api_key = API_KEY_PROD)

begin
 Excon.post("https://api.goodhire.com/v1/Report", body: {
  "Candidate": {
  "FirstName": "#{first_name}"
  ....
  ...  
},
"Offer": {
  "Products": [
  "....ID"  
 ]
},
 "RequestOptions": {
  "SendPurchaseReceipt": true 
  }
}.to_json, headers: {"Content-Type" => "application/json", "Authorization" => "ApiKey #{api_key}"})
 rescue Excon::Errors => e
 puts "RESPONSE ERROR #{e.response}"
  end
end

Server Development Log

Started POST "/service_forms/7/run_candidate_bckground_check?id=7" for 127.0.0.1
Processing by ServiceFormsController#run_candidate_background_check as HTML
Parameters: {"authenticity_token" => "zregegegergergergegegege", "id" => "7", "service_form_id"=> "7"}

app/controllers/service_forms_controller.rb: in `run_candidate_background_check'
Redirected to https://127.0.0.1:3000/service_forms 
Completed 302 Found in 4359ms

Started GET "/service_forms" for 127.0.0.1

initate_background_check.html.erb

<body>
 <%= button_to service_form_run_candidate_background_check(service_form_id: @service_form.id, id: @service_form.id), method: :post, class: 'bttn-simple bttn-sm bttn-primary'do %>
  Start Background Check
<% end %>
</body>
1

There are 1 answers

0
valcod3r On

API Validations caused API requests to fail