0

I'm trying to use someone's API to retrieve data. Here's a plain curl GET that works fine:

$ curl -H 'Authorization: Bearer eyJhbGciOiJSUz...' 'https://app.theirsite.com/api/web/call/call-log?q=\{"pageSize":25,"pageIndex":1,"sortBy":"timeConnected","sortDirection":2,"userAccountId":0,"requestorId":0,"companyAccountId":99,"consumerId":null,"ticksSince":636959988000000000,"ticksUntil":636966899990000000,"callStatusId":1\}'

Note the escaped brackets.

I can't get this to work in rails with curb. I've tried various attempts at formatting the parameters following the '?' in the url, but no luck. Here's my last attempt:

params = {"pageSize": 25,
          "pageIndex": 1,
          "sortBy": "timeConnected",
          "sortDirection": 2,
          "userAccountId": 0,
          "requestorId": 0,
          "companyAccountId": 99,
          "consumerId": nil,
          "ticksSince": 636959988000000000,
          "ticksUntil": 636966899990000000,
          "callStatusId": 1}


params_str = JSON[params].to_s
params_str.insert( -2, '\\')

response = Curl.get("https://app.theirsite.com/api/web/call/call-log?q=\\" + params_str ) {|curl|
               curl.headers['Authorization'] = 'Bearer ' + @saved.token
               curl.verbose = true}

The authorization is fine, but their server is responding with a 500 error {"global":["Index was outside the bounds of the array."]}. This is what I was getting with a direct curl command before I figured out I needed the escaped brackets. I haven't figured out how to get curb to provide an output of the complete url before sending. That would be helpful.

Any thoughts.

mpipkorn
  • 153
  • 2
  • 9

1 Answers1

0

OK, not an answer, but I finally gave up on curb and switched to Ruby's net/http.

With the params above, it looks like:

uri = URI.parse("https://app.theirsite.com/api/web/call/call-log?q=" + JSON[params])
request = Net::HTTP::Get.new(uri)
request["Authorization"] = 'Bearer ' + @saved.token

req_options = {
  use_ssl: uri.scheme == "https",
}

response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
  http.request(request)
end

A bit longer, but no escaped characters and now everything works.

mpipkorn
  • 153
  • 2
  • 9