Free Support Forum - aspose.com

Getting a 400 Bad Request with Ruby API

I’m going through your REST API line by line after installing the appropriate gem…

Everything is copacetic until I get up to here :

responseStream = RestClient.get(signedURI, :accept => ‘application/json’)

Which returns :

RestClient::BadRequest: 400 Bad Request

The steps that preceded this and worked properly were :

begin
# require_relative 'saaspose_common'

productURI = 'http://api.saaspose.com/v1.0'
Common::Product.setBaseProductUri(productURI)

appSID = '4009d1 < i omitted this, but used what was on my app page > 795626b'
appKey = '19bf < i omitted this, but used what was on my app page > 9da3cc0b'

Common::SaasposeApp.new(appSID,appKey)

# filePath = 'C:/Sample.pdf'
# use carrierwave to transpose this url..
filePath = Rails.root.join('public/system/saaspose/Sample.pdf')
fileName = File.basename(filePath)

# Upload input Word document
urlFile = 'http://api.saaspose.com/v1.0/storage/file/' + fileName
signedURI = Common::Utils.sign(urlFile)
#RestClient.put( signedURI,File.new(filePath, 'rb'))

p 'Input PDF document uploaded successfully'
	
#build URI to convert to TIFF
strURI = 'http://api.saaspose.com/v1.0/pdf/' + fileName + '?format=html' 
		
#sign URI
signedURI = Common::Utils.sign(strURI)

Submitted from: http://saaspose.com/

Hi Daniel,

Sorry, I was unable to reproduce this issue at my end. I copied your code in a new .rb file and executed it and everything was successful. Only last line was added by me to save output file, please have a look at the following code:

require_relative 'saaspose_common'

appSID = '778'
appKey = '8'

Common::SaasposeApp.new(appSID,appKey)

productURI = 'http://api.saaspose.com/v1.0&#39;
Common::Product.setBaseProductUri(productURI)
Common::SaasposeApp.new(appSID,appKey)

filePath = 'C:/Sample.pdf'
fileName = File.basename(filePath)

# Upload input Word document
urlFile = 'http://api.saaspose.com/v1.0/storage/file/&#39; + fileName
signedURI = Common::Utils.sign(urlFile)
RestClient.put( signedURI,File.new(filePath, 'rb'))

p 'Input PDF document uploaded successfully'

#build URI to convert to TIFF
strURI = 'http://api.saaspose.com/v1.0/pdf/&#39; + fileName + '?format=html'

#sign URI
signedURI = Common::Utils.sign(strURI)
responseStream = RestClient.get(signedURI, :accept => 'application/json')
Common::Utils.saveFile(responseStream, "C:/Output.zip")

Can you please share your .rb file with App SID, App Key and complete code to reproduce the issue? Please also paste signed URI for further analysis.

Best Regards,
Imran Rafique
Support Developer, Saaspose Sialkot Team
http://www.saaspose.com

Thanks so much for responding!

I actually commented out this line :

require_relative 'saaspose_common'

As I was under the impression that this was loaded via my environment.
Without that line I can still call all the Libraries within the gem such as
Common, Words, etc.

Maybe though, that's what causing my problem?

My signed URI is :

signedURI =
http://api.saaspose.com/v1.0/pdf/Sample.pdf?format=html&appSID=4009d10e-c833-4210-8f61-f60ea795626b&signature=jl1OEZ8Lb2kB9rdEYLyAkdlOvGQ

This is essentially the offender. So that when I perform :

responseStream = RestClient.get(signedURI, :accept => 'application/json')

I get :

RestClient::BadRequest: 400 Bad Request
from /Users/elephanttrip/.rvm/gems/ruby-1.9.2-p290@whisper/gems/rest-client-1.6.7/lib/restclient/abstract_response.rb:48:in
`return!'

Suggestions?

Perhaps this might be apart of the issue too.. If I don't use RestClient,
and I just try to navigate to your URL manually :

http://api.saaspose.com/v1.0/pdf/Sample.pdf?format=html&appSID=4009d10e-c833-4210-8f61-f60ea795626b&signature=jl1OEZ8Lb2kB9rdEYLyAkdlOvGQ

That URL is generated successfully by : signedURI =
Common::Utils.sign(strURI)

Upon reaching this site, I get an XML file that reads :

File 'Sample.pdf' is not found.

But alas! I promise you I do in fact have a sample.pdf file where I said it
was..

> Thanks so much for responding!
>
> I actually commented out this line :
>
> require_relative 'saaspose_common'
>
> As I was under the impression that this was loaded via my environment.
> Without that line I can still call all the Libraries within the gem such as
> Common, Words, etc.
>
> Maybe though, that's what causing my problem?
>
> My signed URI is :
>
> signedURI =
> http://api.saaspose.com/v1.0/pdf/Sample.pdf?format=html&appSID=4009d10e-c833-4210-8f61-f60ea795626b&signature=jl1OEZ8Lb2kB9rdEYLyAkdlOvGQ
>
> This is essentially the offender. So that when I perform :
>
> responseStream = RestClient.get(signedURI, :accept => 'application/json')
>
> I get :
>
> RestClient::BadRequest: 400 Bad Request
> from /Users/elephanttrip/.rvm/gems/ruby-1.9.2-p290@whisper/gems/rest-client-1.6.7/lib/restclient/abstract_response.rb:48:in
> `return!'
>
> Suggestions?
>
>
>
> On Thu, Jan 31, 2013 at 1:04 PM, Support <
> notifications-support@saaspose.zendesk.com> wrote:
>
>> **
>>

Annnnnnd I figured it out. I had to uncomment your line to upload it ;)

Thanks so much guys!

> Perhaps this might be apart of the issue too.. If I don't use RestClient,
> and I just try to navigate to your URL manually :
>
>
> http://api.saaspose.com/v1.0/pdf/Sample.pdf?format=html&appSID=4009d10e-c833-4210-8f61-f60ea795626b&signature=jl1OEZ8Lb2kB9rdEYLyAkdlOvGQ
>
> That URL is generated successfully by : signedURI =
> Common::Utils.sign(strURI)
>
> Upon reaching this site, I get an XML file that reads :
>
> File 'Sample.pdf' is not found.
>
> But alas! I promise you I do in fact have a sample.pdf file where I said
> it was..
>
>
> On Thu, Jan 31, 2013 at 1:38 PM, Trip Levine <daniel.levine4@gmail.com>wrote:
>
>> Thanks so much for responding!
>>
>> I actually commented out this line :
>>
>> require_relative 'saaspose_common'
>>
>> As I was under the impression that this was loaded via my environment.
>> Without that line I can still call all the Libraries within the gem such as
>> Common, Words, etc.
>>
>> Maybe though, that's what causing my problem?
>>
>> My signed URI is :
>>
>> signedURI =
>> http://api.saaspose.com/v1.0/pdf/Sample.pdf?format=html&appSID=4009d10e-c833-4210-8f61-f60ea795626b&signature=jl1OEZ8Lb2kB9rdEYLyAkdlOvGQ
>>
>> This is essentially the offender. So that when I perform :
>>
>> responseStream = RestClient.get(signedURI, :accept =>
>> 'application/json')
>>
>> I get :
>>
>> RestClient::BadRequest: 400 Bad Request
>> from /Users/elephanttrip/.rvm/gems/ruby-1.9.2-p290@whisper/gems/rest-client-1.6.7/lib/restclient/abstract_response.rb:48:in
>> `return!'
>>
>> Suggestions?
>>
>>
>>
>> On Thu, Jan 31, 2013 at 1:04 PM, Support <
>> notifications-support@saaspose.zendesk.com> wrote:
>>
>>> **
>>>

Hi Daniel,

We're glad to know that this issue is resolved at your end. If you still find any further questions or need assistance from our side, please do let us know. We'll be happy to help you.

Thanks & Regards
Shahzad Latif
Saaspose Support Team.