views:

80

answers:

1

the api I'm working with is here:

I'm able to log in fine and get back an auth token, but cant figure out how to do anything that requires a token. I get back a forbidden response when I try to get or post a private URL.

they give an example of the request that needs to be sent using curl:

curl \ --header 'Authorization: UserLogin token="kk5lvKJG1FohVbS3kcHllyTshdcBKX4FpFAKFnx_Eh0IYYpXN3Hg6HZLceXuYt7V52mCcdUk5i_GUMc~"' \ -X POST \ 'https://api.smarkets.com/v1/users/renew'

My question is: how would one send an equivalent request using the RestClient library in Ruby? I have a feeling that i'm messing up the header because the header in RestClient is all {:key => 'value'} pairs and I don't see how that would translate to the header given in the example.

A: 

In an HTTP request, headers are key/value pairs separated by a :, so the header pair that you need to send is:

:authorization => 'UserLogin token="kk5lvKJG1FohVbS3kcHllyTshdcBKX4FpFAKFnx_Eh0IYYpXN3Hg6HZLceXuYt7V52mCcdUk5i_GUMc~"'

So, to reproduce the request you give in your example:

RestClient.post 'https://api.smarkets.com/v1/users/renew', '', :authorization => 'UserLogin token="kk5lvKJG1FohVbS3kcHllyTshdcBKX4FpFAKFnx_Eh0IYYpXN3Hg6HZLceXuYt7V52mCcdUk5i_GUMc~"'
Hunter Morris
worked. Thanks.
Johnny Brown