ynab / ynab-sdk-ruby

YNAB API Client for Ruby
https://api.ynab.com
Apache License 2.0
65 stars 12 forks source link

Base usage + examples not working? #42

Closed skeud closed 5 years ago

skeud commented 5 years ago

Hi,

I installed the YNAB gem. I'm using Ruby version "ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-darwin18]". Then I created a ynab.rb script, in which I copied your usage script into. Then I ran from the command line "ruby ynab.rb" and I always get the following:

Traceback (most recent call last): 3: from ynab.rb:6:in <main>' 2: from /Users/thomas/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/ynab-1.10.0/lib/ynab/api/budgets_api.rb:134:inget_budgets' 1: from /Users/thomas/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/ynab-1.10.0/lib/ynab/api/budgets_api.rb:163:in get_budgets_with_http_info' /Users/thomas/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/ynab-1.10.0/lib/ynab/api_client.rb:68:incall_api': Unauthorized (YNAB::ApiError)

I checked my Personal Access Token twice, and even generated a new one, and each time I get: "`call_api': Unauthorized (YNAB::ApiError)".

From the command line, with CURL, my token works.

Can you please help?

bradymholt commented 5 years ago

Hi @skeud -

How are you passing in the Personal Access Token?

When you instantiate YNAB::API.new, it should be passed into the constructor like this:

ynab_api = YNAB::API.new(access_token)

You might try hardcoding it ynab_api = YNAB::API.new('663c733f-665c-4bcd-a4cb-f7c4e91b4762') to see if you can getting it working that way initially.

The examples show access_token = ENV['YNAB_ACCESS_TOKEN'] which means it is expected the access token is available as an environment variable. To pass that in when running the script you can run it like this:

YNAB_ACCESS_TOKEN=663c733f-665c-4bcd-a4cb-f7c4e91b4762 ruby ynab.rb
skeud commented 5 years ago

My bad, starting with Ruby and indeed I wasn't using the ENV variable properly... Thanks a lot and sorry for disturbing with a newbie question :)