Developing using RoR

I am trying to integrate PostalMethods API and one of my app using RoR. But when I am run the code samples in my app just got an error for my account details. Error is " PostalMethods::NoCredentialsException (You have failed to provide any credentials (api key))",

I am using Rails 3.0.4.

I tested following code sample:

class PostalmethodsController < ApplicationController
 
  def index
    @postmethod = 'Test postal methods app'
 
    options = {:username => 'username', :password => 'password'}
    client = PostalMethods::Client.new(options)
    client.prepare!
  end
 
end

How can I solve this issue?

Thanks.

Comments

Dear Mr. N S

Dear Mr. N S Hettiarachchi,

The problem is that your code is trying to provide the service your user name and password, while our API expects to receive an API key.

To solve this, you can go in one of the following two options:

Option #1 (recommended):
Replace
options = {:username => 'username', :password => 'password'}
with
options = {:APIkey => 'APIkey'}
In order to obtain your API key, please:
- Log in to the Control Panel at https://cp.postalmethods.com
- In the top menu, click "USER SETTINGS". Select the "Security" tab, and click on "ADVANCED SETTINGS".
- Click the "Generate Key" link in the "API Key" section.
- Copy your API key, and paste it in the appropriate place in your code (make sure there are no spaces ("blanks") in the API key when you paste it.

Option #2 (easier to implement, but not recommended and will be removed from the system soon):
Replace the URL your application connect to to
http://api.postalmethods.com/2009-02-26/PostalWS.asmx
to use the older version of the API.

Please note, option #2 will be removed in the future, and will no longer be supported.
We strongly recommend using the 1st option.

Thank you,
A. Honig,
PostalMethods Support Team

Hi A. Honig, First one(#1)

Hi A. Honig,

First one(#1) which you recommended is working for me. So now I started integration with our app.

Thanks you very much for your replay.

Cheers!
Nuwansh.