I am having difficulty calling an external API from my Ruby on Rails Controller
The following code is my Destinations Controller
url = URI.parse("https://api.sygictravelapi.com/1.0/en/places/list?parents=#{@destination.destination_type.downcase}:#{@destination.sygia_id}&level=poi")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
req = Net::HTTP::Get.new(url.to_s)
req.add_field 'x-api-key', ENV["SYGIC_API_KEY"]
res = Net::HTTP.start(url.host, url.port) {
|http|
http.request(req)
}
The problem is that when I make this request, the response is "Bad Request", without any further information. Using the exact same request headers and URL through Postman, I get a 200-OK response from the endpoint, plus the data I expect.
When monitoring traffic using Wireshark, I see an HTTP request going to the API endpoint. But when using Postman, I see only TLS requests.
I've also tried different encoding of the Query String parameters to no avail. My assumption is that it is one of these two things that is causing the issue: 1) SSL not being used 2) QueryString Parameters not attached to the HTTP request. But would like additional eyes on my code to check I'm not missing something obvious.