Sample code for 30+ languages & platforms
PowerBuilder Requires Chilkat v11.0.0+

Jira Cloud: Update Issue Fields

See more Jira Examples

Update an issue's summary and description, add a label, and remove another label. A field in fields replaces its value; operations in update can add or remove individual values. Do not put the same field in both objects.

Use GET /rest/api/3/issue/{issueIdOrKey}/editmeta to inspect editable fields and allowed operations for this issue. A commented custom-field assignment illustrates a single-line text field; replace its ID and use the value shape required by that field's schema. Updating fields does not perform a workflow transition.

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

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Http
string ls_BaseUrl
oleobject loo_Url
oleobject loo_Resp
oleobject loo_Reply
string ls_IssueKey
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)
loo_Request = create oleobject
li_rc = loo_Request.ConnectToNewObject("Chilkat.JsonObject")

loo_Request.UpdateString("fields.summary","Updated issue summary")
//  Jira v3 rich text is an Atlassian Document Format (ADF) document.
loo_Request.UpdateString("fields.description.type","doc")
loo_Request.UpdateInt("fields.description.version",1)
loo_Request.UpdateString("fields.description.content[0].type","paragraph")
loo_Request.UpdateString("fields.description.content[0].content[0].type","text")
loo_Request.UpdateString("fields.description.content[0].content[0].text","Updated description.")
loo_Request.UpdateString("update.labels[0].add","reviewed")
loo_Request.UpdateString("update.labels[1].remove","needs-review")
//  Optional: only after checking editmeta for your single-line text custom field.
//  ignore = request.UpdateString("fields.customfield_10042","Example value");
loo_Url.SetString(ls_BaseUrl)
loo_Url.Append("/rest/api/3/issue/{$issueKey}")
li_Success = loo_Http.HttpJson("PUT",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_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_Request
    return
end if

//  Jira normally returns HTTP 204 with no JSON body.
Write-Debug "Issue fields updated: " + ls_IssueKey


destroy loo_Http
destroy loo_Url
destroy loo_Resp
destroy loo_Reply
destroy loo_Request