0

Am trying to access data from Exact Online API Using Faraday Gem and it is returning the status of "401" meaning am not authorized to access that link before I login, but I had already been authenticated and I logged in successfully in a different page.

If I try to access that link individually via the browser URL bar I can see the data.

Here is my controller

 def example1
    @exact_conn = Faraday.new(:url => 'https://start.exactonline.nl') do |data|
      data.request :url_encoded
      data.response :logger
      data.adapter Faraday.default_adapter
    end

   data = @exact_conn.get("/api/v1/{division}/salesinvoice/SalesInvoices"
   @received_data = data.status
  end

my View

<h1>Received Data</h1>
<%= @received_data %>

How can i solve this issue?
Or Is their any other option I can use in order to access that data directly without being authenticated for second time?.

Guido Leenders
  • 4,232
  • 1
  • 23
  • 43
Little Phild
  • 785
  • 1
  • 6
  • 17
  • By 'authorized on different page' - do you mean that you passed auth data to api and authorized there? – Vasfed Dec 09 '15 at 12:27
  • Basically I have a button in App if you click on it, it connects to exactonline authentication system and then after loggin it returns me back to the app. `It acts like facebook login button`: After wards if I try to access some data from Exactonline API it returns me 401 error – Little Phild Dec 09 '15 at 12:40
  • Please remember to include the division ID in the URL. {division} is just a signal that you must fill it in. You can find division in the URL when logged on or use 'select * from systemdivisions'. – Guido Leenders Jan 15 '17 at 09:54

1 Answers1

0

For APIs there is often authentication required on each request in the form of a token passed in your HTTP headers. If that is how this API works, you may try something like:

@exact_conn.get do |req|
  req.url('/api/v1/{division}/salesinvoice/SalesInvoices')
  req.headers['Authorization'] = "Token token=#{your_token_here}"
end
DannyRosenblatt
  • 895
  • 11
  • 15