Seona Bellamy


60 Experience
0 Lessons Completed
0 Questions Solved


Posted in Having trouble figuring out net/http and API calls.

It works on a straight curl request, so I'm figuring we have the right priviledges unless curl works differently - I'm not really that familiar with it.

Posted in Having trouble figuring out net/http and API calls.

Hi folks,

I need to make a number of calls to an API, some of which are GET requests and some of which are PUT requests. I've tried to make a common function since there's a bunch of security stuff that needs to happen, and I'm not sure if a) I'm actually doing it right in the first place, or b) there's a better/simpler/cleaner/more reliable way to do it instead.

I have the following function to handle the contact with the Smart API:

def callSmart(apipath,format)
pem ="#{Rails.root}/private/websummit.pem")
uri = URI.parse(apipath)
http =, uri.port)
http.use_ssl = true
http.cert =
http.key =, ENV['KEY_PASSWORD'])
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.start {
if format == 'get'
request =
elsif format == 'put'
request =
http.request(request) {|res|
respond_to do |format|
result = { :message => res.body }
format.json { render :json => result }

I can pass it an appropriate URL such as:


and get the result:


So far, so good. However I then tried calling one of the actions on the car, rather than passively requesting data:


This got me the following response:

{"message":"{\"message\":\"Service is not authenticated\"}"}

Given that it's running the same authentication code, do you have any idea why one is working and the other not?

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

© 2024 GoRails, LLC. All rights reserved.