How to update the value of a custom field in Jira cloud?

Jamshaid
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 3, 2024

I am trying to update the value of a custom field in Jira Cloud using ScriptRunner. Here is my code

static void updateCustomField(String apiUrl, String authString, String data) {

def url = new URL("$apiUrl")

def connection = url.openConnection() as HttpURLConnection

connection.requestMethod = "PUT"

connection.setRequestProperty("Authorization", "Basic $authString")

connection.setRequestProperty("Content-Type", "application/json")

connection.doOutput = true

def jsonBody = new JsonBuilder([

fields: [

"customfield_10389": "{"+data +"}" // Assuming this custom field accepts simple text

]

]).toString()

print(data)

connection.outputStream.with { os ->

os.write(jsonBody.bytes)

}

if (connection.responseCode == 200) {

println "Custom field updated successfully."

} else {

println "Failed to update issue: HTTP ${connection.responseCode} - ${connection.responseMessage}"

}

}

But, it always ends up with 400 error:

Failed to update issue: HTTP 400 - Bad Request

I have tried adding the variable as follows but it still did not work:

def jsonBody = new JsonBuilder([

fields: [

"customfield_10389": data

]

]).toString()

Here is what data is there in data variable:

---> (Failed Verification) Task : CT81 with title Perimeter Security Controls are up to date for all internet Facing Mobile and Web Applications. has failed verification with status = none
---> (Failed Verification) Task : CT59 with title Send formal notification email to the PM and STO has failed verification with status = none
---> (Failed Verification) Task : CT58 with title Cyber Security Advisor's Manager or delegate has reviewed the SPIR and evidence has failed verification with status = none
---> (Failed Verification) Task : CT91 with title Engage Network Security for review or assessment of network configurations and solution design has failed verification with status = none
---> (Failed Verification) Task : CT87 with title Security Issue finding record has been logged for any security control gaps/deficiencies in requirements and design has failed verification with status = none
---> (Failed Verification) Task : CT75 with title All personal privileged IDs have been removed and non personal privileged IDs are on-boarded onto the password vault (CyberArk) has failed verification with status = none
---> (Failed Verification) Task : CT72 with title All impacted applications have a record in the Application Catalogue (AppCat), which includes appropriate sensitivity information has failed verification with status = none
---> (Failed Verification) Task : CT65 with title Provide the final solution (SA) document as reviewed by Cyber Security for the appropriate APT forum(s) has failed verification with status = none
---> (Failed Verification) Task : CT64 with title The HLRD/LRD includes appropriate security requirements from the BMO Cyber Security Standards and Controls has failed verification with status = none

What might be going wrong? I am unable to get any reason for this. Where do i find the documentation for Jira Cloud Rest API?

Thanks 

 

1 answer

1 accepted

1 vote
Answer accepted
Jamshaid
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 5, 2024

I got it working using this as it was a multiline text field.

 


def connection = url.openConnection() as HttpURLConnection

connection.requestMethod = "PUT"

connection.setRequestProperty("Authorization", "Basic $authString")

connection.setRequestProperty("Content-Type", "application/json")

connection.doOutput = true

String jsonBody = new JsonBuilder([

fields: [

customfield_10389: [

version: 1,

type: "doc",

content: [[

type: "paragraph",

content: [[

type: "text",

text: logs

]]

]]

]

]

]).toString()

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events