Jakub Zak
Jakub Zak

Reputation: 1232

Ruby rest-client returning 401 while curl command works

I have a working curl command which returns exactly what I want, bunch of JSON:

curl -D- -u username:password -X GET -H "Content-Type: application/json" https://stash.address.net/rest/api/1.0/projects/FOOBAR/repos\?limit\=1000

And I need to transform it into RestClient::Request, but I am still getting 401 back:

RestClient::Request.execute(
    method: :get,
    headers: {
        content_type: 'application/json'
    },
    username: 'username',
    password: 'password',
    url: 'https://stash.address.net/rest/api/1.0/projects/FOOBAR/repos',
    params: {
        limit: '1000'
    },
    verify_ssl: false
)

Did I forget something? Is there something missing from my request? Isn't it exactly same as the curl command above?

Upvotes: 0

Views: 384

Answers (1)

Simone Carletti
Simone Carletti

Reputation: 176412

From the documentation I don't see any mention of the username and params options. They suggest to interpolate the value in the URL.

RestClient.get 'https://username:[email protected]/rest/api/1.0/projects/FOOBAR/repos', { accept: :json, params: { limit: 1000 }}

Upvotes: 1

Related Questions