bugsnag / bugsnag-api-ruby

BugSnag API toolkit for Ruby
Other
21 stars 15 forks source link

500 error fetching org projects endpoint #17

Closed wfleming closed 6 years ago

wfleming commented 6 years ago

I'm writing a script to interact with our org's bugsnag data and getting a surprising 500 fetching the related projects of an org. My code (anonymized a bit) is:

Bugsnag::Api.configure do |config|
  config.auth_token = "my-auth-token"
  config.auto_paginate = true
end

Bugsnag::Api.organization("my-org-name") # returns an object matching my expectations

Bugsnag::Api.organization("my-org-name").rels[:projects].get # errors with a  500

Exception/Stacktrace:

Bugsnag::Api::InternalServerError: GET https://api.bugsnag.com/organizations/my-org-id/projects: 500 - Error: Internal Server Error
        from /var/lib/gems/2.3.0/gems/bugsnag-api-2.0.2/lib/bugsnag/api/response/raise_error.rb:16:in `on_complete'
        from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/response.rb:9:in `block in call'
        from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/response.rb:61:in `on_complete'
        from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/response.rb:8:in `call'
        from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/rack_builder.rb:143:in `build_response'
        from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/connection.rb:387:in `run_request'
        from /var/lib/gems/2.3.0/gems/faraday-0.14.0/lib/faraday/connection.rb:138:in `get'
        from /var/lib/gems/2.3.0/gems/sawyer-0.8.1/lib/sawyer/agent.rb:94:in `call'
        from /var/lib/gems/2.3.0/gems/sawyer-0.8.1/lib/sawyer/relation.rb:264:in `call'
        from /var/lib/gems/2.3.0/gems/sawyer-0.8.1/lib/sawyer/relation.rb:163:in `get'
        from (irb):32
        from /usr/bin/irb:11:in `<main>'

Fetching other rels (e.g. contributors) in the same manner works successfully. Fetching the same URL via curl -H "Authorization: token my-auth-token" https://api.bugsnag.com/organizations/my-org-id/projects also works successfully, so I'm working on the belief right now that something about how the gem is constructing this request disagreed with an expectation of the API.

Other details:

If there are other details I can provide about environment or inspection of any of the objects involved that would be helpful in understanding what caused this, please let me know. Thanks for your help.

tobyhs commented 6 years ago

Hi @wfleming

It looks like you may have been using an organization API key (as opposed to a personal auth token) when you were making API requests with the gem. Using an organization API key is not supported for some endpoints such as GET /organizations/:id/projects. We plan on adding a more informative error message for this soon.

If you still have issues with the endpoint using a personal auth token, let us know.

wfleming commented 6 years ago

Well boy do I feel silly @tobyhs. Thanks for your patient reply, sorry for the noise. The one part I'm still confusedf about is why I thought curl -H "Authorization: token my-auth-token" https://api.bugsnag.com/organizations/my-org-id/projects worked for me when I filed this, but I'm sure I was also making some silly error in that case :man_shrugging:.