error: API request failed Invalid token (401 status) but sentry-cli works

See original GitHub issue

Hello I have added @sentry/webpack-plugin to my webpack configuration:

    new SentryWebpackPlugin({
      authToken: dotEnv.definitions['process.env.APP_SENTRY_AUTH_TOKEN'],
      org: 'my-org-slug',
      project: package.name,
      release: gitRevisionWebpackPlugin.commithash(),
      include: './dist/',
      ignore: [ 'node_modules', 'webpack.common.js', 'webpack.dev.js', 'webpack.prod.js' ],
    }),

When running compilation with SENTRY_LOG_LEVEL=debug I get following output

ERROR in Sentry CLI Plugin: Command failed: /Users/username/Projects/myproject/node_modules/@sentry/cli/sentry-cli releases new mygitsha1
  DEBUG   2020-10-26 22:02:48.609905 +01:00 sentry-cli version: 1.58.0, platform: "darwin", architecture: "x86_64"
  INFO    2020-10-26 22:02:48.612301 +01:00 sentry-cli was invoked with the following command line: "/Users/username/Projects/myproject/node_modules/@sentry/cli/sentry-cli" "releases" "new" "mygitsha1"
  DEBUG   2020-10-26 22:02:48.613544 +01:00 request POST https://sentry.io/api/0/projects/mileus-f3/analytics-api-debugger/releases/
  DEBUG   2020-10-26 22:02:48.613938 +01:00 using token authentication
  DEBUG   2020-10-26 22:02:48.613965 +01:00 json body: {"version":"mygitsha1","projects":["myproject"],"dateStarted":"2020-10-26T21:02:48.613512Z"}
  DEBUG   2020-10-26 22:02:48.613979 +01:00 retry number 0, max retries: 0
  DEBUG   2020-10-26 22:02:49.580256 +01:00 > POST /api/0/projects/my-org-slug/myproject/releases/ HTTP/1.1
  DEBUG   2020-10-26 22:02:49.580363 +01:00 > Host: sentry.io
  DEBUG   2020-10-26 22:02:49.580385 +01:00 > Accept: */*
  DEBUG   2020-10-26 22:02:49.580400 +01:00 > Connection: TE
  DEBUG   2020-10-26 22:02:49.580414 +01:00 > TE: gzip
  DEBUG   2020-10-26 22:02:49.580428 +01:00 > User-Agent: sentry-cli/1.58.0
  DEBUG   2020-10-26 22:02:49.581397 +01:00 > Authorization: Bearer "token***
  DEBUG   2020-10-26 22:02:49.581423 +01:00 > Content-Type: application/json
  DEBUG   2020-10-26 22:02:49.581440 +01:00 > Content-Length: 136
  DEBUG   2020-10-26 22:02:50.083904 +01:00 < HTTP/1.1 401 Unauthorized
  DEBUG   2020-10-26 22:02:50.083965 +01:00 < Server: nginx
  DEBUG   2020-10-26 22:02:50.083989 +01:00 < Date: Mon, 26 Oct 2020 21:02:50 GMT
  DEBUG   2020-10-26 22:02:50.084013 +01:00 < Content-Type: application/json
  DEBUG   2020-10-26 22:02:50.084056 +01:00 < Content-Length: 26
  DEBUG   2020-10-26 22:02:50.084077 +01:00 < Connection: keep-alive
  DEBUG   2020-10-26 22:02:50.084103 +01:00 < Access-Control-Allow-Headers: X-Sentry-Auth, X-Requested-With, Origin, Accept, Content-Type, Authentication, Authorization, Content-Encoding
  DEBUG   2020-10-26 22:02:50.084124 +01:00 < X-Content-Type-Options: nosniff
  DEBUG   2020-10-26 22:02:50.084143 +01:00 < Content-Language: en
  DEBUG   2020-10-26 22:02:50.084160 +01:00 < Access-Control-Expose-Headers: X-Sentry-Error, Retry-After
  DEBUG   2020-10-26 22:02:50.084179 +01:00 < Vary: Accept-Language, Cookie
  DEBUG   2020-10-26 22:02:50.084197 +01:00 < X-XSS-Protection: 1; mode=block
  DEBUG   2020-10-26 22:02:50.084215 +01:00 < Allow: GET, POST, HEAD, OPTIONS
  DEBUG   2020-10-26 22:02:50.084233 +01:00 < X-Frame-Options: deny
  DEBUG   2020-10-26 22:02:50.084250 +01:00 < Access-Control-Allow-Origin: *
  DEBUG   2020-10-26 22:02:50.084267 +01:00 < Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS
  DEBUG   2020-10-26 22:02:50.084289 +01:00 < WWW-Authenticate: xBasic realm="api"
  DEBUG   2020-10-26 22:02:50.084309 +01:00 < X-Served-By: web-ee8f0660
  DEBUG   2020-10-26 22:02:50.084329 +01:00 < Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
  DEBUG   2020-10-26 22:02:50.084408 +01:00 response status: 401
  DEBUG   2020-10-26 22:02:50.084441 +01:00 body: {"detail":"Invalid token"}
error: API request failed
  caused by: sentry reported an error: Invalid token (http status: 401)
  DEBUG   2020-10-26 22:02:50.088188 +01:00 client close; no transport to shut down  (from sentry)
  DEBUG   2020-10-26 22:02:50.088999 +01:00 skipping update nagger because session is not attended


webpack 5.2.0 compiled with 1 error in 18690 ms
ℹ 「wdm」: Failed to compile.

(NOTE: I have replaced project, org name, token value with dummy values).

I’m using dotenv to load token value into my webpack config so dotEnv.definitions['process.env.APP_SENTRY_AUTH_TOKEN'] actually contains a token I created under my organization’s settings -> developer setttings -> internal integration:

Screenshot 2020-10-27 at 08 27 18

For package.name I’m using my NPM’s package name which is identical to project name set up in Sentry. For release I’m using git-revision-webpack-plugin to load latest Git SHA1 hash. I also have different webpack config files: webpack.prod.js, webpack.common.js and webpack.dev.js. In this instance I’m launching build using webpack.dev.js (which then uses webpack-merge package to merge webpack.common.js configuration). I also checked my organization settings that my-org-slug is the same as in Sentry.

When I log the values used for the plugin, they all are present and correct.

I tried running sentry-clilike this:

SENTRY_AUTH_TOKEN=[token] ./node_modules/.bin/sentry-cli releases --org=[my-org-slug] --project=[myproject] new [mygitsha1].

This succesfully created release in my Sentry dashboard. However I still need to upload source maps which is why I wanted to use this plugin so it’s more automated. The usage of sentry-cli proves that my auth credentials are correct so I don’t know why this is failing.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:18 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
xgqfrmscommented, Jan 11, 2021

@comatory I’m confused, too.

It works on Sentry.io, but not work in my company’s private Sentry service, maybe version problem, who knows?

authToken in sentry.io ✅

authToken in private sentry ❌, but token is right ✅

5reactions
comatorycommented, Mar 8, 2021

Bumping this up.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sentry reported an error: Invalid token (http status: 401)
After integration sentry in my project the dev environment works fine but when I try to build the project with yarn ...
Read more >
API request failed Invalid token (401 status) but sentry-cli works
Hello I have added @sentry/webpack-plugin to my webpack configuration: new SentryWebpackPlugin({ authToken: dotEnv.definitions['process.env.
Read more >
"Invalid token: API request failed" with sentry-cli login
I can't seem to log in with sentry-cli login. I have created a new token in Settings > Account > API > Auth...
Read more >
Configuration and Authentication - Docs - Sentry Documentation
Learn how to use Sentry, configure Sentry clients, and contribute to the open source project on GitHub.
Read more >
Deployment failing in github actions, unable to pass env to ...
#16 8.299 Sentry CLI Plugin: Command failed: ... new xxxxxxxxxxxxxxxxxx #16 8.299 error: API request failed #16 8.299 ... (http status: 401).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found