What's the method to post comments via the API in Jira Data Center?

API Comment Posting in Jira

How do I programmatically insert comments into Jira Data Center issues using the API? See my revised code below.

import axios from 'axios';

const apiClient = axios.create({
  baseURL: 'https://jira-dc-demo.company.local/rest/api/2',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${accessKey}`
  }
});

function postComment(issueKey, text) {
  return apiClient.post(`/issue/${issueKey}/comment`, { body: text });
}

// Example usage
postComment('PROJ-456', 'This comment was added via a new API call');

hey, your code is fine. double-check your access token and perms. sometimes jira api hes issues if configuration’s off. might want to try basic auth if bearer keeps failing, idk.