-1

I am posting to an API which accepts CURL as follows:

curl -v  -X POST "https://url.com" -d 'input=frustrated&user_key=3b9ccb48e734fce6b982a9c1c2cef301'

I have tried the following with an error:

    data = {'user_key' => "#{ENV['USER_KEY']}", 'input' => "#{text}", 'client_name'=>> "#{client_name}"}
    talkresponse = JSON.parse(RestClient.post url_talk_bot, {:params => data})

for some reason, the data is fine for all except for 'input' which always gets an error as an array which triggers an error since a string is expected. Note below how the input params is an array.

{"user_key"=>"3b9ccb48e734fce6b982a9c1c2cef301", "input"=>"[\"frustrated how do I post to params, worked fine before\"]", "client_name"=>"14155086888"}

 /mnt/task/__gems__/gems/rest_client-1.7.3/lib/restclient/abstract_response.rb:48:in `return!': 401 Unauthorized (RestClient::Unauthorized)
Satchel
  • 16,414
  • 23
  • 106
  • 192

1 Answers1

0

I have run into similar issues when using RestClient.post. So much so, that I stopped using .post and started using .execute

  • RestClient.post uri, {:params => data}

becomes

  • RestClient.execute({ :method => :post, :url => uri, :headers => {api_key: '123', authorization: Base64::encode("#{user}:#{password}"}, :payload: body})
oamike
  • 11
  • 1