# UPS quotes via shipping gem

**URL:** <https://www.ruby-forum.com/t/ups-quotes-via-shipping-gem/64423>\
**Category:** Rails\
**Created:** [June 25, 2006, 7:43pm UTC](https://www.ruby-forum.com/t/ups-quotes-via-shipping-gem/64423 "2006-06-25T19:43:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![minimal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@minimal](https://www.ruby-forum.com/u/minimal)\
**Post date:** [June 25, 2006, 7:43pm UTC](https://www.ruby-forum.com/t/ups-quotes-via-shipping-gem/64423/1 "2006-06-25T19:43:54Z")

</div>

greetings,

has anyone had luck with the UPS portion of the shipping gem?

i get nil’s returned for price, wondering what i’m missing. to avoid all  
confusion i included the account/login in the instantiation (sub with  
real values).

@ups = Shipping::UPS.new :ups\_account =\> ‘7B4F74E3075AEEFF’, :ups\_user  
=\> ‘username’, :ups\_password =\> ‘password’, :zip =\> 92064, :sender\_zip  
=\> 19122, :weight =\> 2

the fake UPS account number looks nuts, mine is only 6 character long.

any insight would be much appreciated. thanks.

---

<div class="post-metadata">

**Author:** ![minimal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@minimal](https://www.ruby-forum.com/u/minimal)\
**Post date:** [November 4, 2007, 8:39pm UTC](https://www.ruby-forum.com/t/ups-quotes-via-shipping-gem/64423/2 "2007-11-04T20:39:13Z")

</div>

minimal wrote:

> greetings,
> 
> has anyone had luck with the UPS portion of the shipping gem?
> 
> i get nil’s returned for price, wondering what i’m missing. to avoid all  
> confusion i included the account/login in the instantiation (sub with  
> real values).
> 
> @ups = Shipping::UPS.new :ups\_account =\> ‘7B4F74E3075AEEFF’, :ups\_user  
> =\> ‘username’, :ups\_password =\> ‘password’, :zip =\> 92064, :sender\_zip  
> =\> 19122, :weight =\> 2
> 
> the fake UPS account number looks nuts, mine is only 6 character long.
> 
> any insight would be much appreciated. thanks.

Hello,

I had this exact problem and found the solution somewhere on Google. I  
know how much this pissed me off so I want to help others.

OK first off make your life easier and create a file  
/config/shipping.yml and add your ups account information as shown  
below.

ups\_license\_number: ups\_xml\_access\_key  
ups\_user: ups\_username  
ups\_password: ups\_password

One important thing to notice is that I am using ups\_license\_number: as  
opposed to ups\_account: as shown in the Shipping gem docs ☹ . This is  
what is causing all the trouble. Also note that I am using the xml  
access key and not the account number.

Next you need a method to get your quote. Here is a quick one to get you  
started.

#in your controller  
def ups\_quote(to\_zip, sender\_zip, weight)  
#define the parameters for the quote  
params ={  
:zip =\> to\_zip,  
:sender\_zip =\> sender\_zip,  
:weight =\> weight,  
:prefs =\> “#{RAILS\_ROOT}/config/shipping.yml”  
}  
#build the shipping gem object  
@shipping = Shipping::UPS.new params  
end

#in your view

| Shipping Quote: | \<%= number\_to\_currency @shipping.price %\> |

That should solve your problem. I wish I could remember who was the  
author of that forum response so I could give credit where it is due.  
Also keep in mind that UPS tends to go offline from time to time and  
without a failsafe method in place of ups\_quote your application will  
break and output an error. You will need to add error trapping to the  
above method.

Best regards,

Tim M.
