I'm using the Faraday gem to request some data from the LibreNMS API. But when i display the response body I get some HTML code that looks like a redirect page to the libreNMS login.
I have the following code (BaseService class):
def libre_connection
Faraday.new(url: 'https://librenms.mydomain.nl') do |conn|
conn.path_prefix = "/api/v0"
conn.response :json, :content_type => /\bjson$/, :parser_options => { :symbolize_names => true }
conn.headers['X-Auth-Token'] = Rails.application.credentials[:libre][:key]
conn.headers["Content-Type"] = "application/json"
conn.adapter Faraday.default_adapter
end
And then this in a class that extends BaseService
def call()
response = libre_connection.get "/ports/25008.json"
end
For some reason this gives the following response:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <meta http-equiv="refresh" content="0;url=https://librenms.mydomain.nl/login" /> <title>Redirecting to https://librenms.mydomain.nl/login</title> </head> <body> Redirecting to <a href="https://librenms.mydomain.nl/login">https://librenms.mydomain.nl/login</a>. </body> </html>
I know the token works because when I do the following curl command I get the JSON response I expect
curl -H 'X-Auth-Token: MYAPITOKEN' https://librenms.mydomain.nl/api/v0/ports/25008
Anyone have any idea what I'm doing wrong?