2

I am using the rest-client gem to try and make a post to my API.

The RestClient.post helper requires three arguments to pass headers like that: .post(url, params, headers). Have you tried something more like this?

RestClient.post('http://api.example.com/', {key: 'value'}, authorization: 'a2m...')

https://github.com/rest-client/rest-client/issues/339#issuecomment-71787018

I have followed the advice above but receive RestClient::Unauthorized - 401 Unauthorized as the response.

My code:

RestClient.post "http://api.example-dev.com:7000/v1/resources", {key: 'value'}, :authorization => 'yyyyyyyy'

I have success with the below curl command but not the above RestClient.post. Successful curl:

curl -i -X POST -d 'test[key]=1234' -H "Authorization: Token token=yyyyyyyyyyyyyy" \ http://api.example-dev.com:7000/v1/resources
Marklar
  • 1,247
  • 4
  • 25
  • 48

1 Answers1

2

This should produce the same request as curl:

`RestClient.post "http://api.example-dev.com:7000/v1/resources", {:test => {key: '1234'}}, :authorization => 'Token token=yyyyyyyyyyyyyy'`
Pafjo
  • 4,979
  • 3
  • 23
  • 31
  • 1
    Thanks. I thought that rest-client would have automatically added "Token token=" when using `:authorization`. I was incorrect and your answer fixed the problem for me. – Marklar Apr 15 '15 at 06:15