0

Just get a HTTP error 500 when I try to execute this uniquest Ruby script. The goal is to make an HTTP POST request on an API which use oauth to authenticate.

So I made 2 arrays, one for the request header and a second for the request body, but it doesn't seems to work.

# Import unirest & yaml (for debugging)
require 'unirest'
require 'yaml'

# Generate Timestamp for oauth authenticate
@timestamp = Time.now.to_i

# Head array
@toHead = {
  "Cache-Control" => "no-cache",
  "Accept" => "*/*",
  "Accept-Encoding" => "gzip, deflate",
  "Content-Type" => "application/x-www-form-urlencoded",
  "User-Agent" => "runscope/0.1",
  "Content-Length" => "94",
  "Authorization" => {
    "oauth_nonce" => '12345678',
    "oauth_timestamp" => "#{@timestamp}",
    "oauth_version" => '1.0',
    "oauth_signature_method" => 'PLAINTEXT',
    "oauth_consumer_key" => 'CONSUMER_KEY',
    "oauth_token" => 'TOKEN_KEY',
    "oauth_signature" => "CONSUMER_SECRET&TOKEN_SECRET"
  }
}

# Body array
@toSend = {
  :io_mode => "json",
  :request => 1,
  :do_in => {
    :method => 'Client.getList',
    :params => []
  }
}

# Launch the request
response = Unirest.post "https://apifeed.sellsy.com/0/",
                        headers:@toHead,
                        parameters:@toSend

# Get the response
response.code
response.headers
response.body
response.raw_body

That returns an error code 500, the answer headers and an empty body :

code: 500
headers:
  :server: nginx
  :date: Wed, 21 Jun 2017 07:43:03 GMT
  :content_type: application/json; encoding=utf-8
  :content_length: '0'
  :connection: keep-alive
  :keep_alive: timeout=10
raw_body: ''
body: ''

EDIT : I tried with hurl.it, for a simple post request, and It works great : Hurl.it request

Bastien Robert
  • 809
  • 1
  • 10
  • 31

1 Answers1

-1

Finally find the solution, script’s disponible here : https://github.com/bastienrobert/Sellsy-API

Bastien Robert
  • 809
  • 1
  • 10
  • 31
  • A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](//stackoverflow.com/help/deleted-answers) – Mogsdad Feb 09 '18 at 01:58