How to edit description field through REST api

faisalamdani July 12, 2021

We want to edit jira issue description field through rest api but we are not able to do that can you help us with that

 

4 answers

1 vote
Daniel Ebers
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.
July 16, 2021

Hi @faisalamdani

is there a specific error you are getting back?

It should really be no harder than passing the following to REST API - which method did you use? I seem to recognize from documentation the request should be of type 'PUT'.

It should work that way:

{"fields":{"description":"my new description"}}

For the URL I'd say it is:
PUT /rest/api/2/issue/issuekey

Let us know if it proceeded well, please.

Cheers,
Daniel

faisalamdani July 16, 2021

Hello @Daniel Ebers 

I am using V3 api in which we can not directly send description in fields object like this {"fields":{"description":"my new description"}}

though in V2 its working but I want the solution for V3

 

Thank You!

Daniel Ebers
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.
July 18, 2021

There still might be deviances between v2 and v3 API - why I am not confident it definitely works in v3 API.

You probably could also check with Developer Community (https://community.developer.atlassian.com/tag/rest-api) - guessing there are more users specialicing in integration questions with API and coding.
You also could wait here for more input but an older thread normally does not get that much attention after a few days.

0 votes
YANNAM SHRAVAN January 14, 2022

Hello everyone below java code helps to update jira issue name and description in Jira.

 

I think this will help you.

 

It is working for me.

 

JsonNodeFactory jnf = JsonNodeFactory.instance;
ObjectNode payload = jnf.objectNode();
{
ObjectNode update = payload.putObject("update");
{
ArrayNode summary = update.putArray("summary");
ObjectNode summary0 = summary.addObject();
{
summary0.put("set", Name);
}
}

ObjectNode fields = payload.putObject("fields");
ObjectNode description = fields.putObject("description");
{
description.put("type", "doc");
description.put("version", 1);
ArrayNode content = description.putArray("content");
ObjectNode content0 = content.addObject();
{
content0.put("type", "paragraph");
content = content0.putArray("content");
content0 = content.addObject();
{
content0.put("text", Description);
content0.put("type", "text");
}

}
}
}


// Connect Jackson ObjectMapper to Unirest
Unirest.setObjectMapper(new ObjectMapper() {
private com.fasterxml.jackson.databind.ObjectMapper jacksonObjectMapper
= new com.fasterxml.jackson.databind.ObjectMapper();

public <T> T readValue(String value, Class<T> valueType) {
try {
return jacksonObjectMapper.readValue(value, valueType);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public String writeValue(Object value) {
try {
return jacksonObjectMapper.writeValueAsString(value);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
});

// This code sample uses the 'Unirest' library:
// http://unirest.io/java.html
HttpResponse<JsonNode> response = Unirest.put("https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}")
.basicAuth("email@example.com", "<api_token>")
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.body(payload)
.asJson();

System.out.println(response.getBody());

0 votes
YANNAM SHRAVAN January 14, 2022

Hello Everyone below is the java code for updating issue name and description in Jira.

I think this will help you.

It is working for me.


JsonNodeFactory jnf = JsonNodeFactory.instance;
ObjectNode payload = jnf.objectNode();
{
   ObjectNode update = payload.putObject("update");
   {
        ArrayNode summary = update.putArray("summary");
        ObjectNode summary0 = summary.addObject();
        {
            summary0.put("set", Name);
         }
    }

    ObjectNode fields = payload.putObject("fields");
    ObjectNode description = fields.putObject("description");
    {
         description.put("type", "doc");
         description.put("version", 1);
         ArrayNode content = description.putArray("content");
         ObjectNode content0 = content.addObject();
         {
              content0.put("type", "paragraph");
              content = content0.putArray("content");
              content0 = content.addObject();
              {
                   content0.put("text", Description);
                   content0.put("type", "text");
              }

         }
     }
}


// Connect Jackson ObjectMapper to Unirest
Unirest.setObjectMapper(new ObjectMapper() {
private com.fasterxml.jackson.databind.ObjectMapper jacksonObjectMapper
= new com.fasterxml.jackson.databind.ObjectMapper();

     public <T> T readValue(String value, Class<T> valueType) {
     try {
     return jacksonObjectMapper.readValue(value, valueType);
     } catch (IOException e) {
    throw new RuntimeException(e);
    }
}

public String writeValue(Object value) {
  try {
     return jacksonObjectMapper.writeValueAsString(value);
  } catch (JsonProcessingException e) {
  throw new RuntimeException(e);
  }
 }
});

// This code sample uses the 'Unirest' library:
// http://unirest.io/java.html
HttpResponse<JsonNode> response = Unirest.put("https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}")
.basicAuth("email@example.com", "<api_token>")
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.body(payload)
.asJson();

System.out.println(response.getBody());

0 votes
Fazila Ashraf
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 12, 2021

Hi @faisalamdani 

The JIRA cloud rest api documentation on edit issue should help you with this ->  https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issues/#api-rest-api-2-issue-issueidorkey-put

faisalamdani July 12, 2021

Hello @Fazila Ashraf 

I am using V3 version in which they dint have field for description in edit issue api. can you help me that?

Thank you !

Fazila Ashraf
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 12, 2021
faisalamdani July 12, 2021

Hello @Fazila Ashraf 

 

I am referring the same documentation.

The description field in this api is in the historyMetadata object which doesn't update the description field in jira.

We can't pass description field in 'update' or 'fields' objects in this api which actually updates the jira filelds.

 

Thank you !

Alex Garcia November 1, 2021

I also found myself on this struggle, I'm trying to udpate the description but I'm also getting error 400 BAD REQUEST, based on how the description is actually being shown in the API I wouldn't be surprised if the documentation for such field was erroneous

Bruno Pacheco November 10, 2021

Same problem here. When I try to update description I'm getting a 400 error code too.

My code in laravel:
$response = Http::withBasicAuth(env('JIRA_USER'), env('JIRA_API_TOKEN'))->put('https://company.atlassian.net/rest/api/3/issue/issue-key,
    array(
        'fields' => array(
            'summary' => 'Issue Updated',
            'description' => array(
                'type' => 'doc',
                'version' => '1',
                'content' => array(
                    'type' => 'paragraph',
                    'content' => array(
                        'text' => 'Test Description',
                        'type' => 'text'
                    )
                )
            )
        )
    )
);
Summary is updating well but description does not and I'm getting this response:
{
    "errorMessages": [],
    "errors": {
        "xpto": "Field 'xpto' cannot be set. It is not on the appropriate screen, or unknown."
    }
}
Can someone help?
Like # people like this

Suggest an answer

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

Atlassian Community Events