Question

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?

Was it helpful?

Solution

It should be:

@sms =  HTTParty.get("https://api.textit.in/api/v1/sms.json", :headers => { "Authorization" => "Token #{auth}" })
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top