jira-cli: jira init - 401 Unauthorized

Describe the bug

jira init failing with 401 Unauthorized response. but worked with curl requests using the same API token.

image

Please provide following details

  1. JiraCLI Version:
    (Version="v1.1.1-0.20220814163226-d993757c939c", GitCommit="", CommitDate="", GoVersion="go1.19", Compiler="gc", Platform="linux/amd64")
    
  2. Are you using Jira cloud or on-premise jira server? Also mention the version for on-premise installation.
    Cloud
    
  3. What operating system are you using? Also mention version.
    Void Linux
    
  4. What terminal are you using? Also mention version.
    foot
    

To Reproduce

Steps to reproduce the behavior:

  1. jira init

Expected behavior

should create config file. Screenshots

Additional context

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 23 (6 by maintainers)

Most upvoted comments

great. finally this worked for me. thanks @ankitpokhrel

JIRA_API_TOKEN=<token>  JIRA_AUTH_TYPE=basic jira init --debug

Ok, apparently it was my bad - by that point of trying to debug I’ve had export JIRA_AUTH_TYPE="bearer" in my .zshrc which made it not work

Here’s how to handle if anyone is facing it: inside your .zshrc include this: export JIRA_API_TOKEN=“<insert token here>” (to create a token go to: https://id.atlassian.com/manage-profile/security/api-tokens)

(make sure you don’t have export JIRA_AUTH_TYPE=“bearer” in your zshrc apparently, bearer token should not be used)

Edit: I still have the issue (it started happening again after a few minutes of working well) I turned on “–debug” and saw this is the issue: jira issue list is sending this request to JIRA: project=""+ORDER+BY+created+DESC&startAt=0&maxResults=100 as you can see the project is empty 🤔 I tried running jira issue list -p <my_project_key> and it worked this is what I have in my config:

project:
    key: <my_project_key>
    type: next-gen```
    
   edit #2: I think it happened because I've set an ENV variable called `JIRA_PROJECT`. perhaps it's used by jira-cli. 

I can confirm this issue on Ubuntu 20.04, supplying the api token inline works; but setting the token via export or bashrc does not.

Hey @akhiljalagam and @viditsi1 ! I had a similar problem but I found out that I made mistake while setting environmental variable. I tried first to add just JIRA_API_ROKEN="xxxxxxxxxxxxxxxxxxxxx" to my .bashrc. My --debug init gave similar result than yours. Then after 2 min Google I understood to add command export to the beginning of line. After that I ran command source .bashrc, and voilá, it’s working! So make sure that your .bashrc file has a line like export JIRA_API_ROKEN="xxxxxxxxxxxxxxxxxxxxx". and then run command source .bashrc . I hope it will work! 😃

Thanks. But I always use export in my env files. @jaervei

Hey @akhiljalagam and @viditsi1 ! I had a similar problem but I found out that I made mistake while setting environmental variable. I tried first to add just JIRA_API_ROKEN="xxxxxxxxxxxxxxxxxxxxx" to my .bashrc. My --debug init gave similar result than yours. Then after 2 min Google I understood to add command export to the beginning of line. After that I ran command source .bashrc, and voilá, it’s working! So make sure that your .bashrc file has a line like export JIRA_API_ROKEN="xxxxxxxxxxxxxxxxxxxxx". and then run command source .bashrc . I hope it will work! 😃