Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Cannot update field Parent Link using RESTClient

zaharovvv_suek_ru
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.
Sep 30, 2019

I am trying to update Parent Link of issue and set its value from Epic link value. I've found a post where some person were managed to do this, however, I've always get the following error:

WARN [http.RESTClient]: Error parsing 'text/html;charset=UTF-8' response groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object The current character read is '<' with an int value of 60 Unable to determine the current character, it is not a string, number, array, or object line number 11 index number 10 <html>

However, if I insert the url into browser, I'll get the JSON response. My fullAddress variable has the following value:

https://onetwo.com/rest/api/2/issue/TS-74

 

Jira version is 8.4.1

 

The whole code looks like this:

import groovy.json.*
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import groovyx.net.http.RESTClient
import groovyx.net.http.HttpResponseException
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import org.apache.log4j.Logger

def log = Logger.getLogger("com.acme.CreateSubtask")

def issue = ComponentAccessor.getIssueManager().getIssueObject("TS-74")
log.info('Current issue is: ' + issue)
def customFieldManager = ComponentAccessor.getCustomFieldManager()

//def newParentLink = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(0000L) // <- here is ID custom field what u have to update.
def jsonObj = new JsonSlurper().parseText('{ "fields": { "customfield_10976": "GP-259"} }') //customfield_23280 is Parent Link ID
def parentLink = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10976L) // <- id parent link custom field

def userName = "user"
def password = "password"
def fullAddress = "https://onetwo.com/rest/api/2/issue/${issue.key}"
def authString = "${userName}:${password}".getBytes().encodeBase64().toString()

log.info(fullAddress);
log.info("parentLink ${parentLink}")

def client = new RESTClient(fullAddress)

try{
//necessary to overwrite the value of custom field, via rest only update if custom field have value null.
parentLink.updateValue(null, issue, new ModifiedValue(
issue.getCustomFieldValue(parentLink), null),
new DefaultIssueChangeHolder())
client.put(path: fullAddress,
contentType: groovyx.net.http.ContentType.JSON,
body: jsonObj,
headers: [Accept: 'application/json',
Authorization: "Basic ${authString}"]
)
} catch (final HttpResponseException e) {
log.warn e
}

What am I doing wrong?

1 answer

1 accepted

1 vote
Answer accepted
DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 30, 2019

One thing I can spot is, you are using `fullAddress` while initializing RESTClient and also as `path` parameter.

def client = new RESTClient(fullAddress) // LOOK HERE 

try{
//necessary to overwrite the value of custom field, via rest only update if custom field have value null.
parentLink.updateValue(null, issue, new ModifiedValue(
issue.getCustomFieldValue(parentLink), null),
new DefaultIssueChangeHolder())
client.put(path: fullAddress, // LOOK HERE
contentType: groovyx.net.http.ContentType.JSON,
body: jsonObj,
headers: [Accept: 'application/json',
Authorization: "Basic ${authString}"]
)
} catch (final HttpResponseException e) {
log.warn e
}

 

You can define `fullAddress` and `path` as follows,

def fullAddress = "https://onetwo.com/rest/api/2"
def issuePath = "/issue/${issue.key}"

def client = new RESTClient(fullAddress)

try{
//necessary to overwrite the value of custom field, via rest only update if custom field have value null.
parentLink.updateValue(null, issue, new ModifiedValue(
issue.getCustomFieldValue(parentLink), null),
new DefaultIssueChangeHolder())
client.put(path: issuePath, // LOOK CHANGE HERE
contentType: groovyx.net.http.ContentType.JSON,
body: jsonObj,
headers: [Accept: 'application/json',
Authorization: "Basic ${authString}"]
)
} catch (final HttpResponseException e) {
log.warn e
}
zaharovvv_suek_ru
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.
Sep 30, 2019 • edited
zaharovvv_suek_ru
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.
Sep 30, 2019
DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 30, 2019

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events