I have two rails apps that are sending data to each other via HTTP requests.
My first app sends its client data to the other app via this code:
def sync_client_data
Rails.logger.debug("*** Sending client data to tech app.")
uri = URI(endpoint("clients")) # generates a URL e.g. my.api.com/clients
Rails.logger.debug("*** Sending to URI: #{uri}")
req = Net::HTTP::Post.new(uri, {
'Content-Type' => 'application/json',
'Authorization' => Rails.application.config.tech_app_api_key
})
req.body = Client.all.to_json(include: :locations)
res = Net::HTTP.start(uri.hostname, uri.port) do |http|
http.request(req)
end
Rails.logger.debug("*** Response: #{res}") # in production the response is: #<Net::HTTPBadRequest:0x000055b70cd18788>
return redirect_to service_orders_path
end
In development, there is no error. The other app receives the JSON data just fine, and is able to process it, do things with it, etc.
In production however, the app on the receiving end just responds with 400 bad request.
The receiving end looks like this:
class Api::ClientsController < ApiController
def create
Rails.logger.debug("Received request to sync client data.")
params["_json"].each do |client_json|
# do stuff...
end
end
end
I don’t even see the debug output in the logs that should say “Received request to sync client data.”
A bit stumped as to how I’m going to debug this.