Connor Leech
Connor Leech

Reputation: 18833

Authentication credentials were not provided

I am trying to request from the textit.in API and display the results of the request to the view using rails 4

I'm using the 'httparty' gem

In my controller I have:

  def show
    auth = 'b1363362f8777..etc'
    @sms =  HTTParty.get("https://api.textit.in/api/v1/sms.json", :headers => { "Authorization" => auth} )
  end

In the documentation for the site with the API it reads:

"You must authenticate all calls by including an Authorization header with your API token. For security reasons all calls must be made using HTTPS.

You Authorization header should look like this:

Authorization: Token YOUR_API_TOKEN_GOES_HERE"

Then in my view I have <%= @sms %>

But I get {"detail"=>"Authentication credentials were not provided."}

How can I include the Authorization header in my get request?

Upvotes: 1

Views: 1031

Answers (1)

mechanicalfish
mechanicalfish

Reputation: 12826

It should be:

@sms =  HTTParty.get("https://api.textit.in/api/v1/sms.json", :headers => { "Authorization" => "Token #{auth}" })

Upvotes: 2

Related Questions