I’m trying to modify the status of a Jira issue using the jira-ruby gem but running into problems. I found some examples online and wrote this code:
require 'jira'
require '../config/auth'
client_options = {
:username => $jira_username,
:password => $jira_password,
:site => "https://mycompany.atlassian.net",
:context_path => '',
:auth_type => :basic
}
jira_client = JIRA::Client.new(client_options)
ticket = jira_client.Issue.find("PROJ-2847")
possible_transitions = jira_client.Transition.all(:issue => ticket)
possible_transitions.each {|transition| puts "#{transition.name} (id #{transition.id})" }
But I get no output at all. I modified the transition.rb file in the gem to debug and added some print statements to see what’s happening. When I run it again, I see:
"https://mycompany.atlassian.net/rest/api/2/issue/18493/transitions"
"{\"expand\":\"transitions\",\"transitions\":[]}"
The weird thing is when I paste that URL directly into my browser, I can see all the valid transitions for the ticket in JSON format. So the URL works fine, but the script gets an empty response. Has anyone encountered this issue before?
This is definitely an auth issue between your API call and browser session. Your browser’s authenticated with cookies that jira-ruby can’t access. I’ve hit this exact problem before - Jira gets weird about transitions even when basic auth works fine for other endpoints. Switch to token auth instead. Generate an API token from your Atlassian account settings, then use your email as username and the token as password. Also check if you’ve got permission to view transitions for that project. Sometimes transitions are locked down by user roles or project settings.
Had the same headache a few months back. Your user account probably doesn’t have workflow permissions to see available transitions. Even if you can view the issue, Jira separates permissions for viewing workflow transitions. Run ticket.attrs first to see what permissions your API user actually has on that issue. Also check if you’re using the right issue key format. jira-ruby can be picky about using the actual issue ID versus the project key format. Your debug output shows it’s hitting issue ID 18493, but you’re passing PROJ-2847. The gem might be doing some internal conversion that’s screwing with the permissions context.
Weird, same thing happened to me last week. Add explicit headers to your client config - Jira sometimes needs ‘Content-Type’ => ‘application/json’ even for GET requests. Also check your ticket status. If it’s already done or closed, the transitions array will be empty. What’s PROJ-2847’s current status?