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

Updating description field using REST API and Atlassian Document Formatting (ADF)

Isaac Powell October 3, 2024

Using an API call

Referencing ADF:  Document builder (atlassian.com) 

I have successfully set the description field as:

 

{
  "update": {
    "description": [
      {
        "set": {
          "version": 1,
          "type": "doc",
          "content": [
            {
              "type": "paragraph",
              "content": [
                {
                  "type": "text",
                  "text": "Hi"
                }
              ]
            }
          ]
        }
      }
    ]
  }
}

 

I would like then update the field, adding another line that says "hello again" (not really, this is just test data). I believe swappting "set" for "add" should achieve this:  Advanced field editing using JSON | Cloud automation Cloud | Atlassian Support

My attempts are failing:

{
  "update": {
    "description": [
      {
        "add": {
          "version": 1,
          "type": "doc",
          "content": [
            {
              "type": "paragraph",
              "content": [
                {
                  "type": "text",
                  "text": "Hello again"
                }
              ]
            }
          ]
        }
      }
    ]
  }
}

 

 

1 answer

1 accepted

5 votes
Answer accepted
Marcelo Ulloa
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.
October 3, 2024

Hello 

To resolve this issue when updating the description field using the Jira REST API and ADF (Atlassian Document Format), you should avoid using "add" as it doesn't concatenate text. Instead, you should use "set" and reconstruct the entire document with the new content added. Here's an example:

{
  "update": {
    "description": [
      {
        "set": {
          "version": 1,
          "type": "doc",
          "content": [
            {
              "type": "paragraph",
              "content": [
                { "type": "text", "text": "Existing text" }
              ]
            },
            {
              "type": "paragraph",
              "content": [
                { "type": "text", "text": "Newly added text" }
              ]
            }
          ]
        }
      }
    ]
  }
}
Isaac Powell October 3, 2024

Will it fail on "add" all the time then?

The end goal was to generate a table, then each update would just add another table below the first.

Marcelo Ulloa
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.
October 3, 2024

Using "add" doesn't work as expected for appending content like tables. The "add" operation in the ADF format is used to append content within the same node, but it won't concatenate new structures like entire tables. If your goal is to add multiple tables below each other, you'll need to retrieve the existing content first, append the new table, and then use "set" to update the description with the combined content.

Marcelo Ulloa
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.
October 3, 2024

I'll give you an example that might help you.

{
  "update": {
    "description": [
      {
        "set": {
          "version": 1,
          "type": "doc",
          "content": [
            {
              "type": "table",
              "content": [
                {
                  "type": "tableRow",
                  "content": [
                    { "type": "tableHeader", "content": [{ "type": "text", "text": "Header 1" }] },
                    { "type": "tableHeader", "content": [{ "type": "text", "text": "Header 2" }] }
                  ]
                },
                {
                  "type": "tableRow",
                  "content": [
                    { "type": "tableCell", "content": [{ "type": "text", "text": "Cell 1" }] },
                    { "type": "tableCell", "content": [{ "type": "text", "text": "Cell 2" }] }
                  ]
                }
              ]
            },
            {
              "type": "table",
              "content": [
                {
                  "type": "tableRow",
                  "content": [
                    { "type": "tableHeader", "content": [{ "type": "text", "text": "New Header 1" }] },
                    { "type": "tableHeader", "content": [{ "type": "text", "text": "New Header 2" }] }
                  ]
                },
                {
                  "type": "tableRow",
                  "content": [
                    { "type": "tableCell", "content": [{ "type": "text", "text": "New Cell 1" }] },
                    { "type": "tableCell", "content": [{ "type": "text", "text": "New Cell 2" }] }
                  ]
                }
              ]
            }
          ]
        }
      }
    ]
  }
}
Isaac Powell October 3, 2024

Ok that makes sense.

In that case I could just bring the looping of the data to completion first then do the final 'set' once I have it all complete.

Then *if* I need to append anything I can do that read of the old data, then set the old+new.

Thanks! 🙏

Suggest an answer

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

Atlassian Community Events