zendesk / sunshine-conversations-ruby

Smooch API Library for Ruby

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception` when calling AppApi->create_app: Unauthorized

iamcaleberic opened this issue · comments

      payload = {:scope => 'account'}
      jwtHeader = {:kid => ENV['SMOOCH_KEY_ID']}

      token = JWT.encode payload, ENV['SMOOCH_SECRET'], 'HS256', jwtHeader

      # Setup authorization
      SmoochApi.configure do |config|
        # Configure API key authorization: jwt
        config.api_key['Authorization'] = token
        config.api_key_prefix['Authorization'] = 'Bearer'
        config.host = 'api.eu-1.smooch.io'
      end

      api_instance = SmoochApi::AppApi.new
      app_create_body = SmoochApi::AppCreate.new # AppCreate | Body for a createApp request.

      begin
        result = api_instance.create_app(app_create_body)
        p result
      rescue SmoochApi::ApiError => e
        puts "Exception when calling AppApi->create_app: #{e}"
      end

Exception` when calling AppApi->create_app: Unauthorized

#10 - Issue references same issue but the workaround does not work

Here are a few things to verify to make sure that the authorization you are supplying is correct:

  1. When using scope of account, make sure that the key ID you supply is an account-level key, i.e. it should begin with act_
  2. You are setting the host to api.eu-1.smooch.io, please make sure that your account has been provisioned with access to the EU platform
  3. If yes for (2), make sure the key ID/secret you are using is one that you got from the EU dashboard and not the public dashboard

Thanks @mspensieri for the clarifications as to the use of EU platform. I think that should be included in the docs as a note.After changing to the default region everything works.