/http/import question

Archived from the Transloadit support forum. Originally posted on February 18, 2011; details may be outdated, see our docs for current behavior. Original thread

I’m having a little trouble getting the /http/import robot to work using the REST API. Can anybody spot the problem below?

require 'rubygems'
require 'openssl'
require 'json'
require 'net/http'

auth_key = 'XXXX'
auth_secret = 'XXXX'

image_url = 'http://transloadit.com/img/robots/http-import.jpg'

params = JSON.generate({:auth => {
  :expires => Time.now.utc.strftime('%Y/%m/%d %H:%M:%S+00:00'),
  :key => auth_key,
  :robot => "/http/import",
  :url => image_url
}})

digest = OpenSSL::Digest::Digest.new('sha1')
signature = OpenSSL::HMAC.hexdigest(digest, auth_secret, params)

http = Net::HTTP.new("api2.transloadit.com")
request = Net::HTTP::Post.new("/?signature=#{ signature }")
request.set_form_data( { :params => params })
response = http.request( request )

The request goes through, but all I get back is an ‘OK’. I doubt I’m posting to the right place or with the right params.

Hey Adam,

At first glance I can’t spot a problem, but since your language is
Ruby have you considered testdriving our gem?
http://rubygems.org/gems/transloadit/

Should make working with our API even easier : )

Let me know if that doesn’t work out, so we can go in-depth and solve your problem.

Just discovered the github repo. I’m on it.

Hi Adam, sorry but the gem is not quite ready yet. Anyway, are you sure you are getting “OK” back? Can you paste the full output?

Your JSON has multiple problems. Most importantly your http import step needs to be wrapped in a “steps” key, and your “expires” / “key” properties need to be wrapped in an “auth” key. I’m surprised if you wouldn’t get a more meaningful error message on this.

--fg

I reorganized my code and am getting a lot further…

{"error":"ASSEMBLY_STEP_INVALID","message":"One of your {steps: ...} parameters is a non-object value.","reason":"{\"url\":\"http://transloadit.com/img/robots/http-import.jpg\"}"}

…can you spot the problem in “steps” ?

params = JSON.generate({
    :auth => {
      :expires => ( Time.now + 10.minutes ).utc.strftime('%Y/%m/%d %H:%M:%S+00:00'),
      :key => auth_key,
    },
    :steps => {
      :robot => "/http/import",
      :url => url
    }
})

I think I’m good:

params = JSON.generate({
    :auth => {
      :expires => ( Time.now + 10.minutes ).utc.strftime('%Y/%m/%d %H:%M:%S+00:00'),
      :key => auth_key,
    },
    :steps => {
      :import_existing => {
        :robot => "/http/import",
        :url => url
      }
    }
})

Thanks.

Glad you figured it out. Closing this for now.

Kind regards,
Tim