Trying to add a comment using JIRA bulk edit endpoint rest/api/3/bulk/issues/fields

umits2009
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 1, 2024

I am trying to use bulk api edit endpoint to add comment. Here is my code:

 

import requests
from requests.auth import HTTPBasicAuth
import json

url = f"{DOMAIN}/rest/api/3/bulk/issues/fields"
auth = HTTPBasicAuth(USERNAME, API_TOKEN)

headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}

# Update this payload to include a valid ADF object for the comment
payload = json.dumps({
"editedFieldsInput": {
"richTextFields": [
{
"fieldId": "comment",
"richText": {
"version": 1,
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Hello "
},
{
"type": "text",
"text": "world",
"marks": [
{
"type": "strong"
}
]
}
]
}
]
}
}
]
},
"selectedIssueIdsOrKeys": [
"TLP-141103" # Add your issue key here
],
"selectedActions": [
"comment"
],
"sendBulkNotification": True # This will send a notification
})

response = requests.post(
url,
data=payload,
headers=headers,
auth=auth,
verify=False
)

# Check for success or errors
if response.status_code == 201:
print("Issues updated successfully!")
else:
print(f"Error: {response.status_code} - {response.text}")
I am able to do fixversion and priority using the same endpoint, the issue above seems to be with richText and i used the same code provided here  

https://developer.atlassian.com/cloud/jira/platform/apis/document/structure/ . The error i get is 

Error: 400 - {"errorMessages":["Invalid request payload. Refer to the REST API documentation and try again."]} which is very generic. 

 

 

Here is a working version of fix version and priority if anyone needs it: 

 

Any help is appreciated.

import requests
from requests.auth import HTTPBasicAuth
import json

# Replace with your Jira domain, project key, email, and API token
url = f"{DOMAIN}/rest/api/3/bulk/issues/fields"
auth = HTTPBasicAuth(USERNAME, API_TOKEN)

headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}

# Update this payload to your requirements
payload = json.dumps({
"editedFieldsInput": {
"multipleVersionPickerFields": [
{
"bulkEditMultiSelectFieldOption": "ADD", # Add the version
"fieldId": "fixVersions", # This is the field for Fix Versions
"versions": [
{
"versionId": "14594" # The ID of the Fix Version you're adding
}
]
}
],
"priority": {
"priorityId": "5"
},
},
"selectedIssueIdsOrKeys": [
"TLP-141103" # Add your issue key here
],
"selectedActions": [
"fixVersions",
"priority"
],
"sendBulkNotification": True # This will send a notification
})

response = requests.post(
url,
data=payload,
headers=headers,
auth=auth,
verify=False

)

# Check for success or errors
if response.status_code == 201:
print("Issues updated successfully!")
else:
print(f"Error: {response.status_code} - {response.text}")

1 answer

0 votes
Manoj Gangwar
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 2, 2024

@umits2009 welcome to the community! 

Could you please try below. 

import requests

from requests.auth import HTTPBasicAuth

import json

 

# Replace with your Jira domain, API token, and username

url = f"{DOMAIN}/rest/api/3/bulk/issues/fields"

auth = HTTPBasicAuth(USERNAME, API_TOKEN)

 

headers = {

    "Accept": "application/json",

    "Content-Type": "application/json"

}

 

# Correctly structured payload for the rich text comment

payload = json.dumps({

    "editedFieldsInput": {

        "richTextFields": [

            {

                "fieldId": "comment",

                "richText": {

                    "version": 1,

                    "type": "doc",

                    "content": [

                        {

                            "type": "paragraph",

                            "content": [

                                {

                                    "type": "text",

                                    "text": "Hello "

                                },

                                {

                                    "type": "text",

                                    "text": "world",

                                    "marks": [

                                        {

                                            "type": "strong"

                                        }

                                    ]

                                }

                            ]

                        }

                    ]

                }

            }

        ]

    },

    "selectedIssueIdsOrKeys": [

        "TLP-141103" # Replace with your issue key

    ],

    "selectedActions": [

        "comment"

    ],

    "sendBulkNotification": True # This will send a notification

})

 

response = requests.post(

    url,

    data=payload,

    headers=headers,

    auth=auth,

    verify=False

)

 

# Check for success or errors

if response.status_code == 201:

    print("Issues updated successfully!")

else:

    print(f"Error: {response.status_code} - {response.text}")

 

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