locoboy
locoboy

Reputation: 38940

Sending a POST request with RestClient and Authentication headers

I have the following curl request that I would like to translate into a RestClient API request.

curl -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Token user_token="tokenhere", email="[email protected]"' -X POST "https://api.myapi.io/reports?start_date=2016-05-10&end_date=2016-05-12" -v

I tried the following as a RestClient POST but I keep getting a 401. When I do the curl request I get a response.

url = "https://api.myapi.io/reports?start_date=2016-05-10&end_date=2016-05-12"

RestClient.post(url, :authorization => 'Token email="[email protected]" user_token="tokenhere"', :content_type => 'application/json', :accept => 'application/json')

Any ideas?

Upvotes: 2

Views: 1810

Answers (1)

Josh Abrams
Josh Abrams

Reputation: 76

The string you're expecting is:

'Token user_token="tokenhere", email="[email protected]"'

The line you're sending is:

'Token email="[email protected]" user_token="tokenhere"'

The parameters are flipped around. :) If that doesn't work, I'd check and make sure that the curl request is expecting escaped characters. You could be effectively sending this:

"Token email=\"[email protected]\" user_token=\"tokenhere\""

Upvotes: 1

Related Questions