Encountering 500 error while creating issues with the Jira REST API

I’m facing an issue with the Jira REST API. While I can smoothly retrieve existing issues using GET requests, every attempt to create a new issue via POST requests results in a 500 internal server error. The authentication must be functioning properly because I’m able to read data without problems.

Here’s the Node.js code I’m working with:

createIssue: function(req, res) {
  var Http = require('machinepack-http');
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
  Http.sendHttpRequest({
    url: '/rest/api/2/issue/',
    baseUrl: 'https://jira.example.com',
    method: 'post',
    data: {
      "fields": {
        "project": {
          "key": "TEST"
        },
        "summary": "Creating an issue via API",
        "description": "This issue is created using REST API calls",
        "issuetype": {
          "name": "Story"
        }
      }
    },
    headers: {
      "Authorization": "Basic dXNlcm5hbWU6cGFzc3dvcmQ="
    },
  }).exec({
    serverError: function(result) {
      res.send("Encountered an error: " + JSON.stringify(result))
    },
    success: function(result) {
      res.send("Issue created successfully");
    },
  });
}

The error message I receive is:

{
    "body": "{\"errorMessages\":[\"Internal server error\"],\"errors\":{}}",
    "headers": "{\"server\":\"nginx/1.8.0\",\"date\":\"Thu, 16 Sep 2021 10:00:00 GMT\",\"content-type\":\"application/json;charset=UTF-8\",\"connection\":\"close\"}",
    "status": 500
}

What might be causing this error?

You’re missing the Content-Type header completely. Jira’s REST API needs Content-Type: application/json for POST requests - without it, the API can’t parse your payload and you’ll get a 500 error. Had this exact issue last year during our migration. Also double-check that “TEST” project exists and you’ve got permission to create issues there. Those generic 500 errors love hiding permission problems. Add the Content-Type header first and see if that fixes it.

had a similar issue, adding the priority field really helped fix the 500 error for me! Give it a shot, it could be what you need. good luck!

Check your issue type config in the TEST project. I hit this exact same problem - the project had custom required fields that weren’t in my API call. That 500 error’s super misleading since it should just tell you which fields failed validation. Hit /rest/api/2/issue/createmeta?projectKeys=TEST&issuetypeNames=Story first to see what’s actually required for Story issues. You’ll probably find mandatory stuff like assignee, components, or custom fields missing from your payload. Saved me hours when I was debugging the same thing.