Reputation: 153
How to call an external api using rest-client gem with api token?
I am doing something like this
RestClient.get('api.openweathermap.org/data/2.5/weather?id=2172797', headers={appid: 'xxxxxxxxxxxxxxxxxxxxxxx'})
But this gives me an unauthorized response. What is the proper name for token header? Open weather api
I can't figure this out.
Upvotes: 0
Views: 699
Reputation: 153
I should put APPID in params hash. So the best solution I found was create ENV variable and use it in my file. Then I can just call.
RestClient.get 'http://api.openweathermap.org/data/2.5/weather?q=London', {params: {APPID: API_KEY}}
Upvotes: -1
Reputation: 2157
Try using string interpolation to put the API_TOKEN
into the url
so it looks like this.
http://api.openweathermap.org/data/2.5/forecast?id=524901&APPID=1111111111
So:
RestClient.get("api.openweathermap.org/data/2.5/weather?id=2172797&APPID=#{API_TOKEN}")
Upvotes: 2