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
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()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.