Jira Cloud: Change an Issue Status
See more Jira Examples
List the workflow transitions currently available to an issue and execute the transition selected by name. A transition is an action, not merely a destination status: use the name returned by Jira, and do not assume the ID or name is the same in every project.
The expanded transition metadata identifies fields associated with transition screens. This basic example refuses a transition with required fields so it cannot silently omit them. Adapt the POST body with the required fields before using such a transition. Workflow conditions and validators can still reject a request, and the available transitions can change between GET and POST.
The code uses an Atlassian account email and an API token without scopes with the site URL. For a scoped API token, keep Basic authentication and change baseUrl to https://api.atlassian.com/ex/jira/YOUR_CLOUD_ID. For OAuth2, use that gateway URL, omit Login/Password/BasicAuth, and set http.AuthToken to the access token. See API token authentication and OAuth2 authorization. The account must have permission for the operation; OAuth scopes do not grant additional Jira permissions.
Targets Jira Cloud. Jira Data Center has a separate REST API and may require different paths, authentication, or payloads.
Atlassian REST API documentation
Chilkat PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Http
string ls_BaseUrl
oleobject loo_Url
oleobject loo_Resp
oleobject loo_Reply
string ls_IssueKey
string ls_TransitionName
string ls_TransitionId
long li_Matches
long li_NeedsFields
long i
long j
oleobject loo_Fields
oleobject loo_Field
oleobject loo_Request
li_Success = 0
// Assumes Chilkat is unlocked. See Global Unlock Sample.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Http.RequireSslCertVerify = 1
loo_Http.BasicAuth = 1
// Read these credentials from private application configuration.
loo_Http.Login = "YOUR_ATLASSIAN_EMAIL"
loo_Http.Password = "YOUR_API_TOKEN"
ls_BaseUrl = "https://your-domain.atlassian.net"
loo_Http.Accept = "application/json"
loo_Url = create oleobject
li_rc = loo_Url.ConnectToNewObject("Chilkat.StringBuilder")
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
loo_Reply = create oleobject
li_rc = loo_Reply.ConnectToNewObject("Chilkat.JsonObject")
ls_IssueKey = "PROJECT-123"
loo_Http.SetUrlVar("issueKey",ls_IssueKey)
ls_TransitionName = "Start Progress"
ls_TransitionId = ""
li_Matches = 0
li_NeedsFields = 0
loo_Url.SetString(ls_BaseUrl)
loo_Url.Append("/rest/api/3/issue/{$issueKey}/transitions?expand=transitions.fields")
li_Success = loo_Http.HttpNoBody("GET",loo_Url.GetAsString(),loo_Resp)
if loo_Resp.StatusCode = 0 then
Write-Debug "No HTTP response was received. Check connectivity and TLS settings."
destroy loo_Http
destroy loo_Url
destroy loo_Resp
destroy loo_Reply
return
end if
if (li_Success <> 1) OR (loo_Resp.StatusCode < 200) OR (loo_Resp.StatusCode >= 300) then
Write-Debug "Request failed. HTTP " + string(loo_Resp.StatusCode)
if loo_Resp.StatusCode = 429 then
Write-Debug "Rate limited. Retry-After: " + loo_Resp.GetHeaderField("Retry-After")
end if
// Inspect this response locally; it can contain private Jira data.
Write-Debug loo_Resp.BodyStr
destroy loo_Http
destroy loo_Url
destroy loo_Resp
destroy loo_Reply
return
end if
li_Success = loo_Reply.Load(loo_Resp.BodyStr)
if li_Success <> 1 then
Write-Debug "Expected a JSON object in the response."
destroy loo_Http
destroy loo_Url
destroy loo_Resp
destroy loo_Reply
return
end if
if loo_Reply.JsonTypeOf("transitions") <> 4 then
Write-Debug "Expected an array: transitions"
destroy loo_Http
destroy loo_Url
destroy loo_Resp
destroy loo_Reply
return
end if
i = 0
j = 0
loo_Fields = create oleobject
li_rc = loo_Fields.ConnectToNewObject("Chilkat.JsonObject")
loo_Field = create oleobject
li_rc = loo_Field.ConnectToNewObject("Chilkat.JsonObject")
do while (i < loo_Reply.SizeOfArray("transitions"))
loo_Reply.I = i
Write-Debug loo_Reply.StringOf("transitions[i].name") + " -> " + loo_Reply.StringOf("transitions[i].to.name")
if loo_Reply.StringOfEquals("transitions[i].name",ls_TransitionName,1) = 1 then
ls_TransitionId = loo_Reply.StringOf("transitions[i].id")
li_Matches = li_Matches + 1
loo_Fields = loo_Reply.ObjectOf("transitions[i].fields")
if loo_Reply.LastMethodSuccess <> 1 then
Write-Debug "Expected expanded transition field metadata."
destroy loo_Http
destroy loo_Url
destroy loo_Resp
destroy loo_Reply
destroy loo_Fields
destroy loo_Field
return
end if
j = 0
do while (j < loo_Fields.Size)
loo_Field = loo_Fields.ObjectAt(j)
if loo_Field.BoolOf("required") = 1 then
li_NeedsFields = 1
Write-Debug "Required transition field: " + loo_Fields.NameAt(j)
end if
destroy loo_Field
j = j + 1
loop
destroy loo_Fields
end if
i = i + 1
loop
if (li_Matches <> 1) OR (li_NeedsFields = 1) then
Write-Debug "Choose one available transition and supply any required transition fields before submitting."
destroy loo_Http
destroy loo_Url
destroy loo_Resp
destroy loo_Reply
destroy loo_Fields
destroy loo_Field
return
end if
loo_Request = create oleobject
li_rc = loo_Request.ConnectToNewObject("Chilkat.JsonObject")
loo_Request.UpdateString("transition.id",ls_TransitionId)
loo_Url.SetString(ls_BaseUrl)
loo_Url.Append("/rest/api/3/issue/{$issueKey}/transitions")
li_Success = loo_Http.HttpJson("POST",loo_Url.GetAsString(),loo_Request,"application/json",loo_Resp)
if loo_Resp.StatusCode = 0 then
Write-Debug "No HTTP response was received. Check connectivity and TLS settings."
destroy loo_Http
destroy loo_Url
destroy loo_Resp
destroy loo_Reply
destroy loo_Fields
destroy loo_Field
destroy loo_Request
return
end if
if (li_Success <> 1) OR (loo_Resp.StatusCode < 200) OR (loo_Resp.StatusCode >= 300) then
Write-Debug "Request failed. HTTP " + string(loo_Resp.StatusCode)
if loo_Resp.StatusCode = 429 then
Write-Debug "Rate limited. Retry-After: " + loo_Resp.GetHeaderField("Retry-After")
end if
// Inspect this response locally; it can contain private Jira data.
Write-Debug loo_Resp.BodyStr
destroy loo_Http
destroy loo_Url
destroy loo_Resp
destroy loo_Reply
destroy loo_Fields
destroy loo_Field
destroy loo_Request
return
end if
Write-Debug "Transition completed: " + ls_TransitionName
destroy loo_Http
destroy loo_Url
destroy loo_Resp
destroy loo_Reply
destroy loo_Fields
destroy loo_Field
destroy loo_Request