Search code examples
ruby-on-railsrubywithings

Withings API: The callback URL is either unknown or invalid


I'm trying to set a notification in the withings API (with the withings-simplificator gem). I always get this error, no matter what URL I enter or if I encode it or not:

irb(main):013:0> user.subscribe_notification('http://foo.bar.com', 'test subscription')
Withings::ApiError: The callback URL 'http://foo.bar.com' is either unknown or invalid - Status code: 293
  from /app/vendor/bundle/ruby/2.2.0/gems/simplificator-withings-0.7.0/lib/withings/connection.rb:80:in `verify_response!'
  from /app/vendor/bundle/ruby/2.2.0/gems/simplificator-withings-0.7.0/lib/withings/connection.rb:22:in `get_request'
  from /app/vendor/bundle/ruby/2.2.0/gems/simplificator-withings-0.7.0/lib/withings/connection.rb:27:in `get_request'
  from /app/vendor/bundle/ruby/2.2.0/gems/simplificator-withings-0.7.0/lib/withings/user.rb:26:in `subscribe_notification'
  from (irb):13
  from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/console.rb:110:in `start'
  from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/console.rb:9:in `start'
  from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:68:in `console'
  from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
  from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
  from bin/rails:8:in `require'
  from bin/rails:8:in `<main>'

Has anyone encountered this and has a solution?

Update 1:

So I tried without the withings simplificator gem:

API_KEY       = '123'
API_SECRET    = '456'
USER_ID       = '789'
USER_KEY      = 'abc'
USER_SECRET   = 'def'
CONFIGURATION = {               site: 'https://oauth.withings.com',
                  request_token_path: '/account/request_token',
                   access_token_path: '/account/access_token',
                      authorize_path: '/account/authorize',
                         http_method: :get,
                              scheme: :query_string
                }

@consumer = OAuth::Consumer.new API_KEY, API_SECRET, CONFIGURATION

@access_token = OAuth::AccessToken.new @consumer, USER_KEY, USER_SECRET

url = ERB::Util.url_encode("www.foo.bar/trigger")
comment = ERB::Util.url_encode("Trigger")
response = @access_token.get("https://wbsapi.withings.net/notify?action=subscribe&userid=#{USER_ID}&callbackurl=#{url}&comment=#{comment}")
JSON.parse(response.body)

And same error:

irb(main):051:0>   JSON.parse(response.body)
=> {"status"=>293}

What am I doing wrong?


Solution

  • You have to make sure during setup

    • your "trigger url" exists
    • it responds with "ok" to a POST
    • it is fast ... I couldn't figure this out exactly how fast, but I think the response time should be < 1 second

    With an environment like this, my code above works.