What is the Process to Insert Comments in Jira Data Center via API?

I’m currently working with Jira Data Center and need to programmatically insert comments on issues using the API. While I have the right permissions and can initiate authenticated requests, I’m uncertain about the right endpoint and the format of the data payload for adding comments.

Here’s my existing setup:

API Method Used: POST Request
Using Axios:

this.jiraAPI = axios.create({
    baseURL: 'https://jira-dc-qa.YOUR-COMPANY-NAME.com/rest/api/2',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${yourToken}`
    }
});

return this.jiraAPI.request({
    method: 'POST',
    url: `/issue/${issueKey}/comments`,
    data: {
        message: "my comment"
    }
});

Could anyone share a comprehensive example of how to correctly structure the request for adding a comment? Also, are there specific headers or authentication elements that I need to include?

Correction Made: Ensured the Axios settings and request parameters were properly structured, including the essential data field for the comment message.

Desired Result: My goal is to ensure that after making these changes, the API request would successfully add a comment to the designated Jira issue, provided that the endpoint, authentication, and permissions are aptly configured.

To add comments to a Jira issue using the API, you need to ensure you’re hitting the correct endpoint and that your JSON payload is formatted correctly. Your usage of the Axios setup looks good so far but note a slight adjustment in the ‘data’ object. While the endpoint /issue/ISSUE-KEY/comments is correct, the JSON payload needs to have a body key, not message. So your data object should look like this:

data: {
    body: "my comment"
}

Additionally, ensure your baseURL is properly adjusted for your server environment. The authorization header with a Bearer token is correctly implemented for authentication purposes. Check for any atypical issues with your server setup or permissions if you encounter any problems.